You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.5 KiB
62 lines
2.5 KiB
import ether from '../helpers/ether';
|
|
import { advanceBlock } from '../helpers/advanceToBlock';
|
|
import { increaseTimeTo, duration } from '../helpers/increaseTime';
|
|
import latestTime from '../helpers/latestTime';
|
|
import EVMRevert from '../helpers/EVMRevert';
|
|
|
|
const BigNumber = web3.BigNumber;
|
|
|
|
require('chai')
|
|
.use(require('chai-as-promised'))
|
|
.use(require('chai-bignumber')(BigNumber))
|
|
.should();
|
|
|
|
const TimedCrowdsale = artifacts.require('TimedCrowdsaleImpl');
|
|
const SimpleToken = artifacts.require('SimpleToken');
|
|
|
|
contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
|
|
const rate = new BigNumber(1);
|
|
const value = ether(42);
|
|
const tokenSupply = new BigNumber('1e22');
|
|
|
|
before(async function () {
|
|
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
|
|
await advanceBlock();
|
|
});
|
|
|
|
beforeEach(async function () {
|
|
this.openingTime = latestTime() + duration.weeks(1);
|
|
this.closingTime = this.openingTime + duration.weeks(1);
|
|
this.afterClosingTime = this.closingTime + duration.seconds(1);
|
|
this.token = await SimpleToken.new();
|
|
this.crowdsale = await TimedCrowdsale.new(this.openingTime, this.closingTime, rate, wallet, this.token.address);
|
|
await this.token.transfer(this.crowdsale.address, tokenSupply);
|
|
});
|
|
|
|
it('should be ended only after end', async function () {
|
|
let ended = await this.crowdsale.hasClosed();
|
|
ended.should.equal(false);
|
|
await increaseTimeTo(this.afterClosingTime);
|
|
ended = await this.crowdsale.hasClosed();
|
|
ended.should.equal(true);
|
|
});
|
|
|
|
describe('accepting payments', function () {
|
|
it('should reject payments before start', async function () {
|
|
await this.crowdsale.send(value).should.be.rejectedWith(EVMRevert);
|
|
await this.crowdsale.buyTokens(investor, { from: purchaser, value: value }).should.be.rejectedWith(EVMRevert);
|
|
});
|
|
|
|
it('should accept payments after start', async function () {
|
|
await increaseTimeTo(this.openingTime);
|
|
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 increaseTimeTo(this.afterClosingTime);
|
|
await this.crowdsale.send(value).should.be.rejectedWith(EVMRevert);
|
|
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.rejectedWith(EVMRevert);
|
|
});
|
|
});
|
|
});
|
|
|