balanceDifference tests and application (#1514)
* Added balanceDifference tests. * Added balanceDifference tests. * Now using balanceDifference in all (most) tests. * Fixed typo.
This commit is contained in:
@ -2,7 +2,7 @@ const { ether } = require('../helpers/ether');
|
||||
const { advanceBlock } = require('../helpers/advanceToBlock');
|
||||
const shouldFail = require('../helpers/shouldFail');
|
||||
const time = require('../helpers/time');
|
||||
const { ethGetBalance } = require('../helpers/web3');
|
||||
const { balanceDifference } = require('../helpers/balanceDifference');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -82,26 +82,21 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
|
||||
await time.increaseTo(this.openingTime);
|
||||
await this.crowdsale.send(GOAL);
|
||||
|
||||
const beforeFinalization = await ethGetBalance(wallet);
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
const afterFinalization = await ethGetBalance(wallet);
|
||||
|
||||
afterFinalization.minus(beforeFinalization).should.be.bignumber.equal(GOAL);
|
||||
(await balanceDifference(wallet, async () => {
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
})).should.be.bignumber.equal(GOAL);
|
||||
});
|
||||
|
||||
it('should allow refunds if the goal is not reached', async function () {
|
||||
const balanceBeforeInvestment = await ethGetBalance(investor);
|
||||
(await balanceDifference(investor, async () => {
|
||||
await time.increaseTo(this.openingTime);
|
||||
await this.crowdsale.sendTransaction({ value: ether(1), from: investor, gasPrice: 0 });
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
|
||||
await time.increaseTo(this.openingTime);
|
||||
await this.crowdsale.sendTransaction({ value: ether(1), from: investor, gasPrice: 0 });
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
await this.crowdsale.claimRefund(investor, { gasPrice: 0 });
|
||||
|
||||
const balanceAfterRefund = await ethGetBalance(investor);
|
||||
balanceBeforeInvestment.should.be.bignumber.equal(balanceAfterRefund);
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
await this.crowdsale.claimRefund(investor, { gasPrice: 0 });
|
||||
})).should.be.bignumber.equal(0);
|
||||
});
|
||||
|
||||
describe('when goal > cap', function () {
|
||||
|
||||
Reference in New Issue
Block a user