Introduce increaseTimeTo helper method.

This commit is contained in:
Jakub Wojciechowski
2017-08-10 16:23:52 +02:00
parent 7c883b6368
commit 46c5759b88
6 changed files with 63 additions and 69 deletions

View File

@ -1,7 +1,6 @@
import ether from './helpers/ether'
import {advanceBlock} from './helpers/advanceToBlock'
import increaseTime from './helpers/increaseTime'
import {duration, increaseTimeHandicap} from './helpers/increaseTime'
import {increaseTimeTo, duration} from './helpers/increaseTime'
import latestTime from './helpers/latestTime'
import EVMThrow from './helpers/EVMThrow'
@ -27,13 +26,9 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
})
beforeEach(async function () {
this.timeToStart = duration.weeks(1);
this.crowdsalePeriod = duration.weeks(1);
this.timeToEnd = this.timeToStart + this.crowdsalePeriod + increaseTimeHandicap;
this.startTime = latestTime().unix() + this.timeToStart;
this.endTime = this.startTime + this.crowdsalePeriod;
this.startTime = latestTime().unix() + duration.weeks(1);
this.endTime = this.startTime + duration.weeks(1);
this.afterEndTime = this.endTime + duration.seconds(1);
this.crowdsale = await SampleCrowdsale.new(this.startTime, this.endTime, RATE, GOAL, CAP, wallet);
this.token = SampleCrowdsaleToken.at(await this.crowdsale.token());
@ -61,7 +56,7 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
const investmentAmount = ether(1);
const expectedTokenAmount = RATE.mul(investmentAmount);
await increaseTime(this.timeToStart);
await increaseTimeTo(this.startTime);
await this.crowdsale.buyTokens(investor, {value: investmentAmount, from: investor}).should.be.fulfilled;
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
@ -69,23 +64,23 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
});
it('should reject payments after end', async function () {
await increaseTime(this.timeToEnd);
await increaseTimeTo(this.afterEnd);
await this.crowdsale.send(ether(1)).should.be.rejectedWith(EVMThrow);
await this.crowdsale.buyTokens(investor, {value: ether(1), from: investor}).should.be.rejectedWith(EVMThrow);
});
it('should reject payments over cap', async function () {
await increaseTime(this.timeToStart);
await increaseTimeTo(this.startTime);
await this.crowdsale.send(CAP);
await this.crowdsale.send(1).should.be.rejectedWith(EVMThrow);
});
it('should allow finalization and transfer funds to wallet if the goal is reached', async function () {
await increaseTime(this.timeToStart);
await increaseTimeTo(this.startTime);
await this.crowdsale.send(GOAL);
const beforeFinalization = web3.eth.getBalance(wallet);
await increaseTime(this.crowdsalePeriod + increaseTimeHandicap);
await increaseTimeTo(this.afterEndTime);
await this.crowdsale.finalize({from: owner});
const afterFinalization = web3.eth.getBalance(wallet);
@ -95,9 +90,9 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
it('should allow refunds if the goal is not reached', async function () {
const balanceBeforeInvestment = web3.eth.getBalance(investor);
await increaseTime(this.timeToStart);
await increaseTimeTo(this.startTime);
await this.crowdsale.sendTransaction({value: ether(1), from: investor, gasPrice: 0});
await increaseTime(this.crowdsalePeriod + increaseTimeHandicap);
await increaseTimeTo(this.afterEndTime);
await this.crowdsale.finalize({from: owner});
await this.crowdsale.claimRefund({from: investor, gasPrice: 0}).should.be.fulfilled;