Files
openzeppelin-contracts/test/crowdsale/CappedCrowdsale.test.js
Yohann Pereira 489d2e85f1 Replace chai.should with chai.expect (#1780)
* changed exxpect to expect wherever applicable

* Merged with latest branch

* Updated merkleTree helper to latest master branch

* Made linting fixes

* Fix for test build

* updated for Coverage

* Updated Address.test.js

* Undo package-lock changes.
2019-06-24 17:40:05 -03:00

64 lines
2.1 KiB
JavaScript

const { BN, ether, expectRevert } = require('openzeppelin-test-helpers');
const { expect } = require('chai');
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 expectRevert(CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0),
'CappedCrowdsale: cap is 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 expectRevert(this.crowdsale.send(1), 'CappedCrowdsale: cap exceeded');
});
it('should reject payments that exceed cap', async function () {
await expectRevert(this.crowdsale.send(cap.addn(1)), 'CappedCrowdsale: cap exceeded');
});
});
describe('ending', function () {
it('should not reach cap if sent under cap', async function () {
await this.crowdsale.send(lessThanCap);
expect(await this.crowdsale.capReached()).to.equal(false);
});
it('should not reach cap if sent just under cap', async function () {
await this.crowdsale.send(cap.subn(1));
expect(await this.crowdsale.capReached()).to.equal(false);
});
it('should reach cap if cap sent', async function () {
await this.crowdsale.send(cap);
expect(await this.crowdsale.capReached()).to.equal(true);
});
});
});
});