|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
import moment from 'moment' |
|
|
|
|
import ether from './helpers/ether' |
|
|
|
|
import {advanceBlock} from './helpers/advanceToBlock' |
|
|
|
|
import increaseTime from './helpers/increaseTime' |
|
|
|
|
import {duration, increaseTimeHandicap} from './helpers/increaseTime' |
|
|
|
|
import latestTime from './helpers/latestTime' |
|
|
|
|
import EVMThrow from './helpers/EVMThrow' |
|
|
|
|
|
|
|
|
@ -28,8 +28,12 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
beforeEach(async function () { |
|
|
|
|
this.startTime = latestTime().unix() + moment.duration(1, 'week').asSeconds(); |
|
|
|
|
this.endTime = latestTime().unix() + moment.duration(2, 'week').asSeconds(); |
|
|
|
|
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.crowdsale = await Crowdsale.new(this.startTime, this.endTime, rate, wallet) |
|
|
|
|
|
|
|
|
@ -44,7 +48,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { |
|
|
|
|
it('should be ended only after end', async function () { |
|
|
|
|
let ended = await this.crowdsale.hasEnded() |
|
|
|
|
ended.should.equal(false) |
|
|
|
|
await increaseTime(moment.duration(2.1, 'week')) |
|
|
|
|
await increaseTime(this.timeToEnd) |
|
|
|
|
ended = await this.crowdsale.hasEnded() |
|
|
|
|
ended.should.equal(true) |
|
|
|
|
}) |
|
|
|
@ -57,13 +61,13 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('should accept payments after start', async function () { |
|
|
|
|
await increaseTime(moment.duration(1, 'week')) |
|
|
|
|
await increaseTime(this.timeToStart) |
|
|
|
|
await this.crowdsale.send(value).should.be.fulfilled |
|
|
|
|
await this.crowdsale.buyTokens(investor, {value: value, from: purchaser}).should.be.fulfilled |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('should reject payments after end', async function () { |
|
|
|
|
await increaseTime(moment.duration(2.1, 'week')) |
|
|
|
|
await increaseTime(this.timeToEnd) |
|
|
|
|
await this.crowdsale.send(value).should.be.rejectedWith(EVMThrow) |
|
|
|
|
await this.crowdsale.buyTokens(investor, {value: value, from: purchaser}).should.be.rejectedWith(EVMThrow) |
|
|
|
|
}) |
|
|
|
@ -73,7 +77,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { |
|
|
|
|
describe('high-level purchase', function () { |
|
|
|
|
|
|
|
|
|
beforeEach(async function() { |
|
|
|
|
await increaseTime(moment.duration(1, 'week')) |
|
|
|
|
await increaseTime(this.timeToStart) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('should log purchase', async function () { |
|
|
|
@ -112,33 +116,33 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { |
|
|
|
|
describe('low-level purchase', function () { |
|
|
|
|
|
|
|
|
|
beforeEach(async function() { |
|
|
|
|
await increaseTime(moment.duration(1, 'week')) |
|
|
|
|
await increaseTime(this.timeToStart) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should log purchase', async function () { |
|
|
|
|
const {logs} = await this.crowdsale.buyTokens(investor, {value: value, from: purchaser}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const event = logs.find(e => e.event === 'TokenPurchase') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
should.exist(event) |
|
|
|
|
event.args.purchaser.should.equal(purchaser) |
|
|
|
|
event.args.beneficiary.should.equal(investor) |
|
|
|
|
event.args.value.should.be.bignumber.equal(value) |
|
|
|
|
event.args.amount.should.be.bignumber.equal(expectedTokenAmount) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should increase totalSupply', async function () { |
|
|
|
|
await this.crowdsale.buyTokens(investor, {value, from: purchaser}) |
|
|
|
|
const totalSupply = await this.token.totalSupply() |
|
|
|
|
totalSupply.should.be.bignumber.equal(expectedTokenAmount) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should assign tokens to beneficiary', async function () { |
|
|
|
|
await this.crowdsale.buyTokens(investor, {value, from: purchaser}) |
|
|
|
|
const balance = await this.token.balanceOf(investor) |
|
|
|
|
balance.should.be.bignumber.equal(expectedTokenAmount) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should forward funds to wallet', async function () { |
|
|
|
|
const pre = web3.eth.getBalance(wallet) |
|
|
|
|
await this.crowdsale.buyTokens(investor, {value, from: purchaser}) |
|
|
|
|