Files
openzeppelin-contracts/test/crowdsale/TimedCrowdsale.test.js
Nicolás Venturo 3e82db2f6f Migration to truffle 5 (and web3 1.0 (and BN)) (#1601)
* Now compiling using truffle 5.

* Migrated some test files, missing BN scientific notation usage.

* Now using BN time values.

* Migrate ERC20 tests.

* Migrate all ERC20 tests.

* Migrate utils, payment and ownership tests.

* All tests save ERC721 migrated.

* Migrated ERC721 tests.

* Fix lint errors.

* Delete old test helpers.

* Fix remaining crowdsale tests.

* Fix signature bouncer tests.

* Update how constants is used.

* Compile script pre-removes the build dir.

* Fix SafeMath tests.

* Revert "Compile script pre-removes the build dir."

This reverts commit 247e745113.

* Fix linter errors.

* Upgrade openzeppelin-test-helpers dependency.

* Update openzeppelin-test-helpers dependency.

* Define math constants globally.

* Remove unnecessary ether unit.

* Roll back reduced ether amounts in tests.

* Remove unnecessary toNumber conversions.

* Delete compile script.

* Fixed failing test.
2019-01-14 19:11:55 -03:00

78 lines
3.1 KiB
JavaScript

const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers');
const TimedCrowdsaleImpl = artifacts.require('TimedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
await time.advanceBlock();
});
beforeEach(async function () {
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await SimpleToken.new();
});
it('reverts if the opening time is in the past', async function () {
await shouldFail.reverting(TimedCrowdsaleImpl.new(
(await time.latest()).sub(time.duration.days(1)), this.closingTime, rate, wallet, this.token.address
));
});
it('reverts if the closing time is before the opening time', async function () {
await shouldFail.reverting(TimedCrowdsaleImpl.new(
this.openingTime, this.openingTime.sub(time.duration.seconds(1)), rate, wallet, this.token.address
));
});
it('reverts if the closing time equals the opening time', async function () {
await shouldFail.reverting(TimedCrowdsaleImpl.new(
this.openingTime, this.openingTime, rate, wallet, this.token.address
));
});
context('with crowdsale', function () {
beforeEach(async function () {
this.crowdsale = await TimedCrowdsaleImpl.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.equal(false);
await time.increaseTo(this.afterClosingTime);
(await this.crowdsale.isOpen()).should.equal(false);
(await this.crowdsale.hasClosed()).should.equal(true);
});
describe('accepting payments', function () {
it('should reject payments before start', async function () {
(await this.crowdsale.isOpen()).should.equal(false);
await shouldFail.reverting(this.crowdsale.send(value));
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { from: purchaser, value: value }));
});
it('should accept payments after start', async function () {
await time.increaseTo(this.openingTime);
(await this.crowdsale.isOpen()).should.equal(true);
await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
});
it('should reject payments after end', async function () {
await time.increaseTo(this.afterClosingTime);
await shouldFail.reverting(this.crowdsale.send(value));
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
});
});
});
});