Files
openzeppelin-contracts/test/crowdsale/FinalizableCrowdsale.test.js
Jakub Bogacz 39db4b4b05 Feature/use expect event in test logs assertions #1232 (#1343)
* Add BigNumber support to expectEvent/inLogs (#1026)

* switched direct logs array check to expectEvent method in AllowanceCrowdsale.test.js

* Refactor expectEvent.inLogs function to use simple value number check

* Introduced should.be.bignumber method to compare BigNumber values

* Use expectEvent to test logs (#1232)

* Removed trailing space

(cherry picked from commit 536262f2ec)
2018-10-20 21:22:54 +00:00

57 lines
2.0 KiB
JavaScript

const expectEvent = require('../helpers/expectEvent');
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 FinalizableCrowdsaleImpl = artifacts.require('FinalizableCrowdsaleImpl');
const ERC20 = artifacts.require('ERC20');
contract('FinalizableCrowdsale', function ([_, wallet, anyone]) {
const rate = new BigNumber(1000);
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 ERC20.new();
this.crowdsale = await FinalizableCrowdsaleImpl.new(
this.openingTime, this.closingTime, rate, wallet, this.token.address
);
});
it('cannot be finalized before ending', async function () {
await expectThrow(this.crowdsale.finalize({ from: anyone }), EVMRevert);
});
it('can be finalized by anyone after ending', async function () {
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: anyone });
});
it('cannot be finalized twice', async function () {
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: anyone });
await expectThrow(this.crowdsale.finalize({ from: anyone }), EVMRevert);
});
it('logs finalized', async function () {
await increaseTimeTo(this.afterClosingTime);
const { logs } = await this.crowdsale.finalize({ from: anyone });
expectEvent.inLogs(logs, 'CrowdsaleFinalized');
});
});