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