Promisify web3 sync requests in tests (#1009)
This commit is contained in:
@ -4,6 +4,7 @@ import { increaseTimeTo, duration } from '../helpers/increaseTime';
|
||||
import latestTime from '../helpers/latestTime';
|
||||
import EVMRevert from '../helpers/EVMRevert';
|
||||
import assertRevert from '../helpers/assertRevert';
|
||||
import { ethGetBalance } from '../helpers/web3';
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -26,7 +27,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
|
||||
});
|
||||
|
||||
beforeEach(async function () {
|
||||
this.openingTime = latestTime() + duration.weeks(1);
|
||||
this.openingTime = (await latestTime()) + duration.weeks(1);
|
||||
this.closingTime = this.openingTime + duration.weeks(1);
|
||||
this.afterClosingTime = this.closingTime + duration.seconds(1);
|
||||
|
||||
@ -88,16 +89,16 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
|
||||
await increaseTimeTo(this.openingTime);
|
||||
await this.crowdsale.send(GOAL);
|
||||
|
||||
const beforeFinalization = web3.eth.getBalance(wallet);
|
||||
const beforeFinalization = await ethGetBalance(wallet);
|
||||
await increaseTimeTo(this.afterClosingTime);
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
const afterFinalization = web3.eth.getBalance(wallet);
|
||||
const afterFinalization = await ethGetBalance(wallet);
|
||||
|
||||
afterFinalization.minus(beforeFinalization).should.be.bignumber.equal(GOAL);
|
||||
});
|
||||
|
||||
it('should allow refunds if the goal is not reached', async function () {
|
||||
const balanceBeforeInvestment = web3.eth.getBalance(investor);
|
||||
const balanceBeforeInvestment = await ethGetBalance(investor);
|
||||
|
||||
await increaseTimeTo(this.openingTime);
|
||||
await this.crowdsale.sendTransaction({ value: ether(1), from: investor, gasPrice: 0 });
|
||||
@ -106,7 +107,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
|
||||
await this.crowdsale.finalize({ from: owner });
|
||||
await this.crowdsale.claimRefund({ from: investor, gasPrice: 0 }).should.be.fulfilled;
|
||||
|
||||
const balanceAfterRefund = web3.eth.getBalance(investor);
|
||||
const balanceAfterRefund = await ethGetBalance(investor);
|
||||
balanceBeforeInvestment.should.be.bignumber.equal(balanceAfterRefund);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user