Skip to content

Commit

Permalink
Test: Remove chai-as-promised calls
Browse files Browse the repository at this point in the history
  • Loading branch information
justuswilhelm committed Jul 26, 2018
1 parent 92b83b5 commit 2e952d2
Show file tree
Hide file tree
Showing 35 changed files with 156 additions and 162 deletions.
1 change: 0 additions & 1 deletion test/access/SignatureBouncer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { getBouncerSigner } = require('../helpers/sign');
const Bouncer = artifacts.require('SignatureBouncerMock');

require('chai')
.use(require('chai-as-promised'))
.should();

const UINT_VALUE = 23;
Expand Down
5 changes: 2 additions & 3 deletions test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber;

const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand All @@ -27,11 +26,11 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW

describe('accepting payments', function () {
it('should accept sends', async function () {
await this.crowdsale.send(value).should.be.fulfilled;
await this.crowdsale.send(value);
});

it('should accept payments', async function () {
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled;
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
});
});

Expand Down
21 changes: 15 additions & 6 deletions test/crowdsale/CappedCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');

const BigNumber = web3.BigNumber;

require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand All @@ -25,23 +25,32 @@ contract('CappedCrowdsale', function ([_, wallet]) {

describe('creating a valid crowdsale', function () {
it('should fail with zero cap', async function () {
await CappedCrowdsale.new(rate, wallet, 0, this.token.address).should.be.rejectedWith(EVMRevert);
await expectThrow(
CappedCrowdsale.new(rate, wallet, 0, this.token.address),
EVMRevert,
);
});
});

describe('accepting payments', function () {
it('should accept payments within cap', async function () {
await this.crowdsale.send(cap.minus(lessThanCap)).should.be.fulfilled;
await this.crowdsale.send(lessThanCap).should.be.fulfilled;
await this.crowdsale.send(cap.minus(lessThanCap));
await this.crowdsale.send(lessThanCap);
});

it('should reject payments outside cap', async function () {
await this.crowdsale.send(cap);
await this.crowdsale.send(1).should.be.rejectedWith(EVMRevert);
await expectThrow(
this.crowdsale.send(1),
EVMRevert,
);
});

it('should reject payments that exceed cap', async function () {
await this.crowdsale.send(cap.plus(1)).should.be.rejectedWith(EVMRevert);
await expectThrow(
this.crowdsale.send(cap.plus(1)),
EVMRevert,
);
});
});

Expand Down
5 changes: 2 additions & 3 deletions test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber;

const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand All @@ -25,8 +24,8 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {

describe('accepting payments', function () {
it('should accept payments', async function () {
await this.crowdsale.send(value).should.be.fulfilled;
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled;
await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
});
});

Expand Down
10 changes: 5 additions & 5 deletions test/crowdsale/FinalizableCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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;

const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand Down Expand Up @@ -34,23 +34,23 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
});

it('cannot be finalized before ending', async function () {
await this.crowdsale.finalize({ from: owner }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.finalize({ from: owner }), EVMRevert);
});

it('cannot be finalized by third party after ending', async function () {
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: thirdparty }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.finalize({ from: thirdparty }), EVMRevert);
});

it('can be finalized by owner after ending', async function () {
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner }).should.be.fulfilled;
await this.crowdsale.finalize({ from: owner });
});

it('cannot be finalized twice', async function () {
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner });
await this.crowdsale.finalize({ from: owner }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.finalize({ from: owner }), EVMRevert);
});

it('logs finalized', async function () {
Expand Down
1 change: 0 additions & 1 deletion test/crowdsale/IncreasingPriceCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { latestTime } = require('../helpers/latestTime');
const BigNumber = web3.BigNumber;

require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand Down
30 changes: 15 additions & 15 deletions test/crowdsale/IndividuallyCappedCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');

const BigNumber = web3.BigNumber;

require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand All @@ -30,27 +30,27 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli

describe('accepting payments', function () {
it('should accept payments within cap', async function () {
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice }).should.be.fulfilled;
await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth }).should.be.fulfilled;
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth });
});

it('should reject payments outside cap', async function () {
await this.crowdsale.buyTokens(alice, { value: capAlice });
await this.crowdsale.buyTokens(alice, { value: 1 }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.buyTokens(alice, { value: 1 }), EVMRevert);
});

it('should reject payments that exceed cap', async function () {
await this.crowdsale.buyTokens(alice, { value: capAlice.plus(1) }).should.be.rejectedWith(EVMRevert);
await this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.buyTokens(alice, { value: capAlice.plus(1) }), EVMRevert);
await expectThrow(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }), EVMRevert);
});

it('should manage independent caps', async function () {
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice }).should.be.fulfilled;
await this.crowdsale.buyTokens(bob, { value: lessThanCapAlice }).should.be.rejectedWith(EVMRevert);
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
await expectThrow(this.crowdsale.buyTokens(bob, { value: lessThanCapAlice }), EVMRevert);
});

it('should default to a cap of zero', async function () {
await this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth }), EVMRevert);
});
});

Expand Down Expand Up @@ -78,20 +78,20 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli

describe('accepting payments', function () {
it('should accept payments within cap', async function () {
await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth }).should.be.fulfilled;
await this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth }).should.be.fulfilled;
await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth });
await this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth });
});

it('should reject payments outside cap', async function () {
await this.crowdsale.buyTokens(bob, { value: capBob });
await this.crowdsale.buyTokens(bob, { value: 1 }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.buyTokens(bob, { value: 1 }), EVMRevert);
await this.crowdsale.buyTokens(charlie, { value: capBob });
await this.crowdsale.buyTokens(charlie, { value: 1 }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.buyTokens(charlie, { value: 1 }), EVMRevert);
});

it('should reject payments that exceed cap', async function () {
await this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }).should.be.rejectedWith(EVMRevert);
await this.crowdsale.buyTokens(charlie, { value: capBob.plus(1) }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }), EVMRevert);
await expectThrow(this.crowdsale.buyTokens(charlie, { value: capBob.plus(1) }), EVMRevert);
});
});

Expand Down
5 changes: 2 additions & 3 deletions test/crowdsale/MintedCrowdsale.behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber;

const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand All @@ -13,8 +12,8 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
describe('as a minted crowdsale', function () {
describe('accepting payments', function () {
it('should accept payments', async function () {
await this.crowdsale.send(value).should.be.fulfilled;
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled;
await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/crowdsale/PostDeliveryCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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 { ether } = require('../helpers/ether');

const BigNumber = web3.BigNumber;

require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand Down Expand Up @@ -46,14 +46,14 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
it('should not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
await increaseTimeTo(this.beforeEndTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
await this.crowdsale.withdrawTokens({ from: investor }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.withdrawTokens({ from: investor }), EVMRevert);
});

it('should allow beneficiaries to withdraw tokens after crowdsale ends', async function () {
await increaseTimeTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.withdrawTokens({ from: investor }).should.be.fulfilled;
await this.crowdsale.withdrawTokens({ from: investor });
});

it('should return the amount of tokens bought', async function () {
Expand Down
20 changes: 11 additions & 9 deletions test/crowdsale/RefundableCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ 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 { ethGetBalance } = require('../helpers/web3');

const BigNumber = web3.BigNumber;

require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand Down Expand Up @@ -40,23 +40,26 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser

describe('creating a valid crowdsale', function () {
it('should fail with zero goal', async function () {
await RefundableCrowdsale.new(
this.openingTime, this.closingTime, rate, wallet, this.token.address, 0, { from: owner }
).should.be.rejectedWith(EVMRevert);
await expectThrow(
RefundableCrowdsale.new(
this.openingTime, this.closingTime, rate, wallet, this.token.address, 0, { from: owner }
),
EVMRevert,
);
});
});

it('should deny refunds before end', async function () {
await this.crowdsale.claimRefund({ from: investor }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.claimRefund({ from: investor }), EVMRevert);
await increaseTimeTo(this.openingTime);
await this.crowdsale.claimRefund({ from: investor }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.claimRefund({ from: investor }), EVMRevert);
});

it('should deny refunds after end if goal was reached', async function () {
await increaseTimeTo(this.openingTime);
await this.crowdsale.sendTransaction({ value: goal, from: investor });
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.claimRefund({ from: investor }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.claimRefund({ from: investor }), EVMRevert);
});

it('should allow refunds after end if goal was not reached', async function () {
Expand All @@ -65,8 +68,7 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner });
const pre = await ethGetBalance(investor);
await this.crowdsale.claimRefund({ from: investor, gasPrice: 0 })
.should.be.fulfilled;
await this.crowdsale.claimRefund({ from: investor, gasPrice: 0 });
const post = await ethGetBalance(investor);
post.minus(pre).should.be.bignumber.equal(lessThanGoal);
});
Expand Down
14 changes: 7 additions & 7 deletions test/crowdsale/TimedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ 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-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();

Expand Down Expand Up @@ -43,20 +43,20 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {

describe('accepting payments', function () {
it('should reject payments before start', async function () {
await this.crowdsale.send(value).should.be.rejectedWith(EVMRevert);
await this.crowdsale.buyTokens(investor, { from: purchaser, value: value }).should.be.rejectedWith(EVMRevert);
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).should.be.fulfilled;
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled;
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 this.crowdsale.send(value).should.be.rejectedWith(EVMRevert);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.send(value), EVMRevert);
await expectThrow(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }), EVMRevert);
});
});
});
Loading

0 comments on commit 2e952d2

Please sign in to comment.