Files
openzeppelin-contracts/test/crowdsale/CappedCrowdsale.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

60 lines
2.0 KiB
JavaScript

const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
const CappedCrowdsaleImpl = artifacts.require('CappedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('CappedCrowdsale', function ([_, wallet]) {
const rate = new BN('1');
const cap = ether('100');
const lessThanCap = ether('60');
const tokenSupply = new BN('10').pow(new BN('22'));
beforeEach(async function () {
this.token = await SimpleToken.new();
});
it('rejects a cap of zero', async function () {
await shouldFail.reverting(CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0));
});
context('with crowdsale', function () {
beforeEach(async function () {
this.crowdsale = await CappedCrowdsaleImpl.new(rate, wallet, this.token.address, cap);
await this.token.transfer(this.crowdsale.address, tokenSupply);
});
describe('accepting payments', function () {
it('should accept payments within cap', async function () {
await this.crowdsale.send(cap.sub(lessThanCap));
await this.crowdsale.send(lessThanCap);
});
it('should reject payments outside cap', async function () {
await this.crowdsale.send(cap);
await shouldFail.reverting(this.crowdsale.send(1));
});
it('should reject payments that exceed cap', async function () {
await shouldFail.reverting(this.crowdsale.send(cap.addn(1)));
});
});
describe('ending', function () {
it('should not reach cap if sent under cap', async function () {
await this.crowdsale.send(lessThanCap);
(await this.crowdsale.capReached()).should.equal(false);
});
it('should not reach cap if sent just under cap', async function () {
await this.crowdsale.send(cap.subn(1));
(await this.crowdsale.capReached()).should.equal(false);
});
it('should reach cap if cap sent', async function () {
await this.crowdsale.send(cap);
(await this.crowdsale.capReached()).should.equal(true);
});
});
});
});