123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- const { ether } = require('../helpers/ether');
- const { advanceBlock } = require('../helpers/advanceToBlock');
- const { increaseTimeTo, duration } = require('../helpers/increaseTime');
- const { latestTime } = require('../helpers/latestTime');
- const { expectThrow } = require('../helpers/expectThrow');
- const { EVMRevert } = require('../helpers/EVMRevert');
- const BigNumber = web3.BigNumber;
- require('chai')
- .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 = (await 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 () {
- (await this.crowdsale.hasClosed()).should.be.false;
- await increaseTimeTo(this.afterClosingTime);
- (await this.crowdsale.hasClosed()).should.be.true;
- });
- describe('accepting payments', function () {
- it('should reject payments before start', async function () {
- await expectThrow(this.crowdsale.send(value), EVMRevert);
- await expectThrow(this.crowdsale.buyTokens(investor, { from: purchaser, value: value }), EVMRevert);
- });
- it('should accept payments after start', async function () {
- await increaseTimeTo(this.openingTime);
- await this.crowdsale.send(value);
- await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
- });
- it('should reject payments after end', async function () {
- await increaseTimeTo(this.afterClosingTime);
- await expectThrow(this.crowdsale.send(value), EVMRevert);
- await expectThrow(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }), EVMRevert);
- });
- });
- });
|