Skip to content

Commit

Permalink
checking fee
Browse files Browse the repository at this point in the history
  • Loading branch information
vittominacori committed Oct 25, 2018
1 parent 494332c commit 7b9eeda
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
6 changes: 5 additions & 1 deletion contracts/CharityProject.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ contract CharityProject is RBACManager {

function totalRaised() public view returns (uint256) {
uint256 raised = _token.balanceOf(this);
return raised.add(_withdrawnTokens);
return raised.add(_withdrawnTokens).add(_withdrawnFees);
}

function totalFee() public view returns (uint256) {
return totalRaised().mul(_feeInMillis).div(1000);
}

function hasStarted() public view returns (bool) {
Expand Down
60 changes: 60 additions & 0 deletions test/CharityProject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,66 @@ contract('CharityProject', function (accounts) {
raised.should.be.bignumber.equal(tokenAmount);
});
});

describe('after withdraw of tokens and fee', function () {
it('should be equal to donation', async function () {
const tokenAmount = new BigNumber(20000);
await this.token.transfer(this.mock.address, tokenAmount, { from: userWallet });

const withdrawAmount = new BigNumber(200);
await this.mock.withdrawTokens(onlusWallet, withdrawAmount, { from: owner });
await this.mock.withdrawFees(anyone, withdrawAmount, { from: owner });

const raised = await this.mock.totalRaised();
raised.should.be.bignumber.equal(tokenAmount);
});
});
});

context('checking total fee', function () {
describe('after creation', function () {
it('should be zero', async function () {
const totalFee = await this.mock.totalFee();
totalFee.should.be.bignumber.equal(0);
});
});

describe('after donation', function () {
it('should be equal to a percent of donation', async function () {
const tokenAmount = new BigNumber(20000);
await this.token.transfer(this.mock.address, tokenAmount, { from: userWallet });

const totalFee = await this.mock.totalFee();
totalFee.should.be.bignumber.equal(tokenAmount.mul(this.feeInMillis).div(1000));
});
});

describe('after withdraw', function () {
it('should be equal to a percent of donation', async function () {
const tokenAmount = new BigNumber(20000);
await this.token.transfer(this.mock.address, tokenAmount, { from: userWallet });

const withdrawAmount = new BigNumber(200);
await this.mock.withdrawFees(anyone, withdrawAmount, { from: owner });

const totalFee = await this.mock.totalFee();
totalFee.should.be.bignumber.equal(tokenAmount.mul(this.feeInMillis).div(1000));
});
});

describe('after withdraw of fee and tokens', function () {
it('should be equal to a percent of donation', async function () {
const tokenAmount = new BigNumber(20000);
await this.token.transfer(this.mock.address, tokenAmount, { from: userWallet });

const withdrawAmount = new BigNumber(200);
await this.mock.withdrawFees(anyone, withdrawAmount, { from: owner });
await this.mock.withdrawTokens(onlusWallet, withdrawAmount, { from: owner });

const totalFee = await this.mock.totalFee();
totalFee.should.be.bignumber.equal(tokenAmount.mul(this.feeInMillis).div(1000));
});
});
});

context('recover tokens from contract', function () {
Expand Down

0 comments on commit 7b9eeda

Please sign in to comment.