Merged latestTime, increaseTime and duration into a time helper. (#1364)

This commit is contained in:
Nicolás Venturo
2018-10-02 07:07:11 -03:00
committed by GitHub
parent 6ae041bca6
commit 34bc709bc2
10 changed files with 84 additions and 95 deletions

View File

@ -1,7 +1,6 @@
const { ether } = require('../helpers/ether');
const { advanceBlock } = require('../helpers/advanceToBlock');
const { increaseTimeTo, duration } = require('../helpers/increaseTime');
const { latestTime } = require('../helpers/latestTime');
const time = require('../helpers/time');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const { assertRevert } = require('../helpers/assertRevert');
@ -27,9 +26,9 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
});
beforeEach(async function () {
this.openingTime = (await latestTime()) + duration.weeks(1);
this.closingTime = this.openingTime + duration.weeks(1);
this.afterClosingTime = this.closingTime + duration.seconds(1);
this.openingTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.openingTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.token = await SampleCrowdsaleToken.new({ from: deployer });
this.crowdsale = await SampleCrowdsale.new(
@ -68,7 +67,7 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
const investmentAmount = ether(1);
const expectedTokenAmount = RATE.mul(investmentAmount);
await increaseTimeTo(this.openingTime);
await time.increaseTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: investmentAmount, from: investor });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
@ -76,23 +75,23 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
});
it('should reject payments after end', async function () {
await increaseTimeTo(this.afterClosingTime);
await time.increaseTo(this.afterClosingTime);
await expectThrow(this.crowdsale.send(ether(1)), EVMRevert);
await expectThrow(this.crowdsale.buyTokens(investor, { value: ether(1), from: investor }), EVMRevert);
});
it('should reject payments over cap', async function () {
await increaseTimeTo(this.openingTime);
await time.increaseTo(this.openingTime);
await this.crowdsale.send(CAP);
await expectThrow(this.crowdsale.send(1), EVMRevert);
});
it('should allow finalization and transfer funds to wallet if the goal is reached', async function () {
await increaseTimeTo(this.openingTime);
await time.increaseTo(this.openingTime);
await this.crowdsale.send(GOAL);
const beforeFinalization = await ethGetBalance(wallet);
await increaseTimeTo(this.afterClosingTime);
await time.increaseTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner });
const afterFinalization = await ethGetBalance(wallet);
@ -102,9 +101,9 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
it('should allow refunds if the goal is not reached', async function () {
const balanceBeforeInvestment = await ethGetBalance(investor);
await increaseTimeTo(this.openingTime);
await time.increaseTo(this.openingTime);
await this.crowdsale.sendTransaction({ value: ether(1), from: investor, gasPrice: 0 });
await increaseTimeTo(this.afterClosingTime);
await time.increaseTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner });
await this.crowdsale.claimRefund(investor, { gasPrice: 0 });