Commit e6c15b34 by Justus Perlwitz Committed by Nicolás Venturo

Remove chai-as-promised (#1116)

* Test: Remove chai-as-promised calls

* Test/Helpers: expectThrow accepts optional message

* NPM: Remove chai-as-promised

* Contracts/DestructibleMock: Fix lint
parent afe9113b
...@@ -2,6 +2,7 @@ pragma solidity ^0.4.24; ...@@ -2,6 +2,7 @@ pragma solidity ^0.4.24;
import "../lifecycle/Destructible.sol"; import "../lifecycle/Destructible.sol";
contract DestructibleMock is Destructible { contract DestructibleMock is Destructible {
function() payable public {} function() payable public {}
} }
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
"homepage": "https://github.com/OpenZeppelin/zeppelin-solidity", "homepage": "https://github.com/OpenZeppelin/zeppelin-solidity",
"devDependencies": { "devDependencies": {
"chai": "^4.1.2", "chai": "^4.1.2",
"chai-as-promised": "^7.0.0",
"chai-bignumber": "^2.0.2", "chai-bignumber": "^2.0.2",
"coveralls": "^3.0.1", "coveralls": "^3.0.1",
"dotenv": "^4.0.0", "dotenv": "^4.0.0",
......
...@@ -4,7 +4,6 @@ const { getBouncerSigner } = require('../helpers/sign'); ...@@ -4,7 +4,6 @@ const { getBouncerSigner } = require('../helpers/sign');
const Bouncer = artifacts.require('SignatureBouncerMock'); const Bouncer = artifacts.require('SignatureBouncerMock');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
const UINT_VALUE = 23; const UINT_VALUE = 23;
......
...@@ -5,7 +5,6 @@ const { ethGetBalance } = require('../helpers/web3'); ...@@ -5,7 +5,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
const should = require('chai') const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -27,11 +26,11 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW ...@@ -27,11 +26,11 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
describe('accepting payments', function () { describe('accepting payments', function () {
it('should accept sends', async 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 () { 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 });
}); });
}); });
......
const { ether } = require('../helpers/ether'); const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -25,23 +25,32 @@ contract('CappedCrowdsale', function ([_, wallet]) { ...@@ -25,23 +25,32 @@ contract('CappedCrowdsale', function ([_, wallet]) {
describe('creating a valid crowdsale', function () { describe('creating a valid crowdsale', function () {
it('should fail with zero cap', async 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 () { describe('accepting payments', function () {
it('should accept payments within cap', async function () { it('should accept payments within cap', async function () {
await this.crowdsale.send(cap.minus(lessThanCap)).should.be.fulfilled; await this.crowdsale.send(cap.minus(lessThanCap));
await this.crowdsale.send(lessThanCap).should.be.fulfilled; await this.crowdsale.send(lessThanCap);
}); });
it('should reject payments outside cap', async function () { it('should reject payments outside cap', async function () {
await this.crowdsale.send(cap); 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 () { 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,
);
}); });
}); });
......
...@@ -4,7 +4,6 @@ const { ethGetBalance } = require('../helpers/web3'); ...@@ -4,7 +4,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
const should = require('chai') const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -25,8 +24,8 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { ...@@ -25,8 +24,8 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe('accepting payments', function () { describe('accepting payments', function () {
it('should accept payments', async function () { it('should accept payments', async function () {
await this.crowdsale.send(value).should.be.fulfilled; await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled; await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
}); });
}); });
......
const { advanceBlock } = require('../helpers/advanceToBlock'); const { advanceBlock } = require('../helpers/advanceToBlock');
const { increaseTimeTo, duration } = require('../helpers/increaseTime'); const { increaseTimeTo, duration } = require('../helpers/increaseTime');
const { latestTime } = require('../helpers/latestTime'); const { latestTime } = require('../helpers/latestTime');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
const should = require('chai') const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -34,23 +34,23 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) { ...@@ -34,23 +34,23 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
}); });
it('cannot be finalized before ending', async function () { 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 () { it('cannot be finalized by third party after ending', async function () {
await increaseTimeTo(this.afterClosingTime); 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 () { it('can be finalized by owner after ending', async function () {
await increaseTimeTo(this.afterClosingTime); 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 () { it('cannot be finalized twice', async function () {
await increaseTimeTo(this.afterClosingTime); await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner }); 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 () { it('logs finalized', async function () {
......
...@@ -6,7 +6,6 @@ const { latestTime } = require('../helpers/latestTime'); ...@@ -6,7 +6,6 @@ const { latestTime } = require('../helpers/latestTime');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
const { ether } = require('../helpers/ether'); const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -30,27 +30,27 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli ...@@ -30,27 +30,27 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli
describe('accepting payments', function () { describe('accepting payments', function () {
it('should accept payments within cap', async function () { it('should accept payments within cap', async function () {
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice }).should.be.fulfilled; await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth }).should.be.fulfilled; await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth });
}); });
it('should reject payments outside cap', async function () { it('should reject payments outside cap', async function () {
await this.crowdsale.buyTokens(alice, { value: capAlice }); 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 () { it('should reject payments that exceed cap', async function () {
await this.crowdsale.buyTokens(alice, { value: capAlice.plus(1) }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(alice, { value: capAlice.plus(1) }), EVMRevert);
await this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }), EVMRevert);
}); });
it('should manage independent caps', async function () { it('should manage independent caps', async function () {
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice }).should.be.fulfilled; await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
await this.crowdsale.buyTokens(bob, { value: lessThanCapAlice }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(bob, { value: lessThanCapAlice }), EVMRevert);
}); });
it('should default to a cap of zero', async function () { 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);
}); });
}); });
...@@ -78,20 +78,20 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli ...@@ -78,20 +78,20 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli
describe('accepting payments', function () { describe('accepting payments', function () {
it('should accept payments within cap', async function () { it('should accept payments within cap', async function () {
await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth }).should.be.fulfilled; await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth });
await this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth }).should.be.fulfilled; await this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth });
}); });
it('should reject payments outside cap', async function () { it('should reject payments outside cap', async function () {
await this.crowdsale.buyTokens(bob, { value: capBob }); 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: 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 () { it('should reject payments that exceed cap', async function () {
await this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }), EVMRevert);
await this.crowdsale.buyTokens(charlie, { value: capBob.plus(1) }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(charlie, { value: capBob.plus(1) }), EVMRevert);
}); });
}); });
......
...@@ -3,7 +3,6 @@ const { ethGetBalance } = require('../helpers/web3'); ...@@ -3,7 +3,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
const should = require('chai') const should = require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -13,8 +12,8 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate ...@@ -13,8 +12,8 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
describe('as a minted crowdsale', function () { describe('as a minted crowdsale', function () {
describe('accepting payments', function () { describe('accepting payments', function () {
it('should accept payments', async function () { it('should accept payments', async function () {
await this.crowdsale.send(value).should.be.fulfilled; await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled; await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
}); });
}); });
......
const { advanceBlock } = require('../helpers/advanceToBlock'); const { advanceBlock } = require('../helpers/advanceToBlock');
const { increaseTimeTo, duration } = require('../helpers/increaseTime'); const { increaseTimeTo, duration } = require('../helpers/increaseTime');
const { latestTime } = require('../helpers/latestTime'); const { latestTime } = require('../helpers/latestTime');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const { ether } = require('../helpers/ether'); const { ether } = require('../helpers/ether');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -46,14 +46,14 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) { ...@@ -46,14 +46,14 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
it('should not allow beneficiaries to withdraw tokens before crowdsale ends', async function () { it('should not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
await increaseTimeTo(this.beforeEndTime); await increaseTimeTo(this.beforeEndTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); 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 () { it('should allow beneficiaries to withdraw tokens after crowdsale ends', async function () {
await increaseTimeTo(this.openingTime); await increaseTimeTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
await increaseTimeTo(this.afterClosingTime); 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 () { it('should return the amount of tokens bought', async function () {
......
...@@ -2,13 +2,13 @@ const { ether } = require('../helpers/ether'); ...@@ -2,13 +2,13 @@ const { ether } = require('../helpers/ether');
const { advanceBlock } = require('../helpers/advanceToBlock'); const { advanceBlock } = require('../helpers/advanceToBlock');
const { increaseTimeTo, duration } = require('../helpers/increaseTime'); const { increaseTimeTo, duration } = require('../helpers/increaseTime');
const { latestTime } = require('../helpers/latestTime'); const { latestTime } = require('../helpers/latestTime');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const { ethGetBalance } = require('../helpers/web3'); const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -40,23 +40,26 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser ...@@ -40,23 +40,26 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser
describe('creating a valid crowdsale', function () { describe('creating a valid crowdsale', function () {
it('should fail with zero goal', async function () { it('should fail with zero goal', async function () {
await RefundableCrowdsale.new( await expectThrow(
this.openingTime, this.closingTime, rate, wallet, this.token.address, 0, { from: owner } RefundableCrowdsale.new(
).should.be.rejectedWith(EVMRevert); this.openingTime, this.closingTime, rate, wallet, this.token.address, 0, { from: owner }
),
EVMRevert,
);
}); });
}); });
it('should deny refunds before end', async function () { 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 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 () { it('should deny refunds after end if goal was reached', async function () {
await increaseTimeTo(this.openingTime); await increaseTimeTo(this.openingTime);
await this.crowdsale.sendTransaction({ value: goal, from: investor }); await this.crowdsale.sendTransaction({ value: goal, from: investor });
await increaseTimeTo(this.afterClosingTime); 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 () { it('should allow refunds after end if goal was not reached', async function () {
...@@ -65,8 +68,7 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser ...@@ -65,8 +68,7 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor, purchaser
await increaseTimeTo(this.afterClosingTime); await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner }); await this.crowdsale.finalize({ from: owner });
const pre = await ethGetBalance(investor); const pre = await ethGetBalance(investor);
await this.crowdsale.claimRefund({ from: investor, gasPrice: 0 }) await this.crowdsale.claimRefund({ from: investor, gasPrice: 0 });
.should.be.fulfilled;
const post = await ethGetBalance(investor); const post = await ethGetBalance(investor);
post.minus(pre).should.be.bignumber.equal(lessThanGoal); post.minus(pre).should.be.bignumber.equal(lessThanGoal);
}); });
......
...@@ -2,12 +2,12 @@ const { ether } = require('../helpers/ether'); ...@@ -2,12 +2,12 @@ const { ether } = require('../helpers/ether');
const { advanceBlock } = require('../helpers/advanceToBlock'); const { advanceBlock } = require('../helpers/advanceToBlock');
const { increaseTimeTo, duration } = require('../helpers/increaseTime'); const { increaseTimeTo, duration } = require('../helpers/increaseTime');
const { latestTime } = require('../helpers/latestTime'); const { latestTime } = require('../helpers/latestTime');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -43,20 +43,20 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { ...@@ -43,20 +43,20 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
describe('accepting payments', function () { describe('accepting payments', function () {
it('should reject payments before start', async function () { it('should reject payments before start', async function () {
await this.crowdsale.send(value).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.send(value), EVMRevert);
await this.crowdsale.buyTokens(investor, { from: purchaser, value: value }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(investor, { from: purchaser, value: value }), EVMRevert);
}); });
it('should accept payments after start', async function () { it('should accept payments after start', async function () {
await increaseTimeTo(this.openingTime); await increaseTimeTo(this.openingTime);
await this.crowdsale.send(value).should.be.fulfilled; await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled; await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
}); });
it('should reject payments after end', async function () { it('should reject payments after end', async function () {
await increaseTimeTo(this.afterClosingTime); await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.send(value).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.send(value), EVMRevert);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }), EVMRevert);
}); });
}); });
}); });
const { ether } = require('../helpers/ether'); const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
const WhitelistedCrowdsale = artifacts.require('WhitelistedCrowdsaleImpl'); const WhitelistedCrowdsale = artifacts.require('WhitelistedCrowdsaleImpl');
...@@ -24,20 +24,20 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, ...@@ -24,20 +24,20 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,
describe('accepting payments', function () { describe('accepting payments', function () {
it('should accept payments to whitelisted (from whichever buyers)', async function () { it('should accept payments to whitelisted (from whichever buyers)', async function () {
await this.crowdsale.sendTransaction({ value, from: authorized }).should.be.fulfilled; await this.crowdsale.sendTransaction({ value, from: authorized });
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled; await this.crowdsale.buyTokens(authorized, { value: value, from: authorized });
await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized }).should.be.fulfilled; await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized });
}); });
it('should reject payments to not whitelisted (from whichever buyers)', async function () { it('should reject payments to not whitelisted (from whichever buyers)', async function () {
await this.crowdsale.sendTransaction({ value, from: unauthorized }).should.be.rejected; await expectThrow(this.crowdsale.sendTransaction({ value, from: unauthorized }));
await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected; await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }));
await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected; await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }));
}); });
it('should reject payments to addresses removed from whitelist', async function () { it('should reject payments to addresses removed from whitelist', async function () {
await this.crowdsale.removeAddressFromWhitelist(authorized); await this.crowdsale.removeAddressFromWhitelist(authorized);
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.rejected; await expectThrow(this.crowdsale.buyTokens(authorized, { value: value, from: authorized }));
}); });
}); });
...@@ -61,22 +61,22 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, ...@@ -61,22 +61,22 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,
describe('accepting payments', function () { describe('accepting payments', function () {
it('should accept payments to whitelisted (from whichever buyers)', async function () { it('should accept payments to whitelisted (from whichever buyers)', async function () {
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled; await this.crowdsale.buyTokens(authorized, { value: value, from: authorized });
await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized }).should.be.fulfilled; await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized });
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.fulfilled; await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized });
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: unauthorized }).should.be.fulfilled; await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: unauthorized });
}); });
it('should reject payments to not whitelisted (with whichever buyers)', async function () { it('should reject payments to not whitelisted (with whichever buyers)', async function () {
await this.crowdsale.send(value).should.be.rejected; await expectThrow(this.crowdsale.send(value));
await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected; await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }));
await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected; await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }));
}); });
it('should reject payments to addresses removed from whitelist', async function () { it('should reject payments to addresses removed from whitelist', async function () {
await this.crowdsale.removeAddressFromWhitelist(anotherAuthorized); await this.crowdsale.removeAddressFromWhitelist(anotherAuthorized);
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled; await this.crowdsale.buyTokens(authorized, { value: value, from: authorized });
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.rejected; await expectThrow(this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }));
}); });
}); });
......
...@@ -2,6 +2,7 @@ const { ether } = require('../helpers/ether'); ...@@ -2,6 +2,7 @@ const { ether } = require('../helpers/ether');
const { advanceBlock } = require('../helpers/advanceToBlock'); const { advanceBlock } = require('../helpers/advanceToBlock');
const { increaseTimeTo, duration } = require('../helpers/increaseTime'); const { increaseTimeTo, duration } = require('../helpers/increaseTime');
const { latestTime } = require('../helpers/latestTime'); const { latestTime } = require('../helpers/latestTime');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const { assertRevert } = require('../helpers/assertRevert'); const { assertRevert } = require('../helpers/assertRevert');
const { ethGetBalance } = require('../helpers/web3'); const { ethGetBalance } = require('../helpers/web3');
...@@ -9,7 +10,6 @@ const { ethGetBalance } = require('../helpers/web3'); ...@@ -9,7 +10,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -58,8 +58,14 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) { ...@@ -58,8 +58,14 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
}); });
it('should not accept payments before start', async function () { it('should not accept payments before start', async function () {
await this.crowdsale.send(ether(1)).should.be.rejectedWith(EVMRevert); await expectThrow(
await this.crowdsale.buyTokens(investor, { from: investor, value: ether(1) }).should.be.rejectedWith(EVMRevert); this.crowdsale.send(ether(1)),
EVMRevert,
);
await expectThrow(
this.crowdsale.buyTokens(investor, { from: investor, value: ether(1) }),
EVMRevert,
);
}); });
it('should accept payments during the sale', async function () { it('should accept payments during the sale', async function () {
...@@ -67,7 +73,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) { ...@@ -67,7 +73,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
const expectedTokenAmount = RATE.mul(investmentAmount); const expectedTokenAmount = RATE.mul(investmentAmount);
await increaseTimeTo(this.openingTime); await increaseTimeTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: investmentAmount, from: investor }).should.be.fulfilled; await this.crowdsale.buyTokens(investor, { value: investmentAmount, from: investor });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount); (await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
(await this.token.totalSupply()).should.be.bignumber.equal(expectedTokenAmount); (await this.token.totalSupply()).should.be.bignumber.equal(expectedTokenAmount);
...@@ -75,14 +81,14 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) { ...@@ -75,14 +81,14 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
it('should reject payments after end', async function () { it('should reject payments after end', async function () {
await increaseTimeTo(this.afterClosingTime); await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.send(ether(1)).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.send(ether(1)), EVMRevert);
await this.crowdsale.buyTokens(investor, { value: ether(1), from: investor }).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.buyTokens(investor, { value: ether(1), from: investor }), EVMRevert);
}); });
it('should reject payments over cap', async function () { it('should reject payments over cap', async function () {
await increaseTimeTo(this.openingTime); await increaseTimeTo(this.openingTime);
await this.crowdsale.send(CAP); await this.crowdsale.send(CAP);
await this.crowdsale.send(1).should.be.rejectedWith(EVMRevert); await expectThrow(this.crowdsale.send(1), EVMRevert);
}); });
it('should allow finalization and transfer funds to wallet if the goal is reached', async function () { it('should allow finalization and transfer funds to wallet if the goal is reached', async function () {
...@@ -105,7 +111,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) { ...@@ -105,7 +111,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
await increaseTimeTo(this.afterClosingTime); await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner }); await this.crowdsale.finalize({ from: owner });
await this.crowdsale.claimRefund({ from: investor, gasPrice: 0 }).should.be.fulfilled; await this.crowdsale.claimRefund({ from: investor, gasPrice: 0 });
const balanceAfterRefund = await ethGetBalance(investor); const balanceAfterRefund = await ethGetBalance(investor);
balanceBeforeInvestment.should.be.bignumber.equal(balanceAfterRefund); balanceBeforeInvestment.should.be.bignumber.equal(balanceAfterRefund);
......
async function expectThrow (promise) { async function expectThrow (promise, message) {
try { try {
await promise; await promise;
} catch (error) { } catch (error) {
// TODO: Check jump destination to destinguish between a throw // Message is an optional parameter here
// and an actual invalid jump. if (message) {
const invalidOpcode = error.message.search('invalid opcode') >= 0; assert(
// TODO: When we contract A calls contract B, and B throws, instead error.message.search(message) >= 0,
// of an 'invalid jump', we get an 'out of gas' error. How do 'Expected \'' + message + '\', got \'' + error + '\' instead',
// we distinguish this from an actual out of gas event? (The );
// ganache log actually show an 'invalid jump' event.) return;
const outOfGas = error.message.search('out of gas') >= 0; } else {
const revert = error.message.search('revert') >= 0; // TODO: Check jump destination to destinguish between a throw
assert( // and an actual invalid jump.
invalidOpcode || outOfGas || revert, const invalidOpcode = error.message.search('invalid opcode') >= 0;
'Expected throw, got \'' + error + '\' instead', // TODO: When we contract A calls contract B, and B throws, instead
); // of an 'invalid jump', we get an 'out of gas' error. How do
return; // we distinguish this from an actual out of gas event? (The
// ganache log actually show an 'invalid jump' event.)
const outOfGas = error.message.search('out of gas') >= 0;
const revert = error.message.search('revert') >= 0;
assert(
invalidOpcode || outOfGas || revert,
'Expected throw, got \'' + error + '\' instead',
);
return;
}
} }
assert.fail('Expected throw not received'); assert.fail('Expected throw not received');
} }
......
...@@ -4,7 +4,6 @@ const { assertRevert } = require('../helpers/assertRevert'); ...@@ -4,7 +4,6 @@ const { assertRevert } = require('../helpers/assertRevert');
const SupportsInterfaceWithLookup = artifacts.require('SupportsInterfaceWithLookupMock'); const SupportsInterfaceWithLookup = artifacts.require('SupportsInterfaceWithLookupMock');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
contract('SupportsInterfaceWithLookup', function (accounts) { contract('SupportsInterfaceWithLookup', function (accounts) {
......
...@@ -4,7 +4,6 @@ const { expectThrow } = require('../helpers/expectThrow'); ...@@ -4,7 +4,6 @@ const { expectThrow } = require('../helpers/expectThrow');
const ECRecoveryMock = artifacts.require('ECRecoveryMock'); const ECRecoveryMock = artifacts.require('ECRecoveryMock');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
contract('ECRecovery', function (accounts) { contract('ECRecovery', function (accounts) {
......
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
function shouldBehaveLikeOwnable (accounts) { function shouldBehaveLikeOwnable (accounts) {
...@@ -25,12 +25,12 @@ function shouldBehaveLikeOwnable (accounts) { ...@@ -25,12 +25,12 @@ function shouldBehaveLikeOwnable (accounts) {
const other = accounts[2]; const other = accounts[2];
const owner = await this.ownable.owner.call(); const owner = await this.ownable.owner.call();
owner.should.not.eq(other); owner.should.not.eq(other);
await this.ownable.transferOwnership(other, { from: other }).should.be.rejectedWith(EVMRevert); await expectThrow(this.ownable.transferOwnership(other, { from: other }), EVMRevert);
}); });
it('should guard ownership against stuck state', async function () { it('should guard ownership against stuck state', async function () {
let originalOwner = await this.ownable.owner(); let originalOwner = await this.ownable.owner();
await this.ownable.transferOwnership(null, { from: originalOwner }).should.be.rejectedWith(EVMRevert); await expectThrow(this.ownable.transferOwnership(null, { from: originalOwner }), EVMRevert);
}); });
it('loses owner after renouncement', async function () { it('loses owner after renouncement', async function () {
...@@ -44,7 +44,7 @@ function shouldBehaveLikeOwnable (accounts) { ...@@ -44,7 +44,7 @@ function shouldBehaveLikeOwnable (accounts) {
const other = accounts[2]; const other = accounts[2];
const owner = await this.ownable.owner.call(); const owner = await this.ownable.owner.call();
owner.should.not.eq(other); owner.should.not.eq(other);
await this.ownable.renounceOwnership({ from: other }).should.be.rejectedWith(EVMRevert); await expectThrow(this.ownable.renounceOwnership({ from: other }), EVMRevert);
}); });
}); });
} }
......
...@@ -4,7 +4,6 @@ const expectEvent = require('../helpers/expectEvent'); ...@@ -4,7 +4,6 @@ const expectEvent = require('../helpers/expectEvent');
const Superuser = artifacts.require('Superuser'); const Superuser = artifacts.require('Superuser');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
contract('Superuser', function (accounts) { contract('Superuser', function (accounts) {
......
...@@ -4,7 +4,6 @@ const expectEvent = require('../helpers/expectEvent'); ...@@ -4,7 +4,6 @@ const expectEvent = require('../helpers/expectEvent');
const WhitelistMock = artifacts.require('WhitelistMock'); const WhitelistMock = artifacts.require('WhitelistMock');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
contract('Whitelist', function (accounts) { contract('Whitelist', function (accounts) {
...@@ -69,8 +68,7 @@ contract('Whitelist', function (accounts) { ...@@ -69,8 +68,7 @@ contract('Whitelist', function (accounts) {
it('should allow whitelisted address to call #onlyWhitelistedCanDoThis', async function () { it('should allow whitelisted address to call #onlyWhitelistedCanDoThis', async function () {
await this.mock.addAddressToWhitelist(whitelistedAddress1, { from: owner }); await this.mock.addAddressToWhitelist(whitelistedAddress1, { from: owner });
await this.mock.onlyWhitelistedCanDoThis({ from: whitelistedAddress1 }) await this.mock.onlyWhitelistedCanDoThis({ from: whitelistedAddress1 });
.should.be.fulfilled;
}); });
}); });
......
...@@ -4,7 +4,6 @@ const expectEvent = require('../../helpers/expectEvent'); ...@@ -4,7 +4,6 @@ const expectEvent = require('../../helpers/expectEvent');
const RBACMock = artifacts.require('RBACMock'); const RBACMock = artifacts.require('RBACMock');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
const ROLE_ADVISOR = 'advisor'; const ROLE_ADVISOR = 'advisor';
...@@ -25,47 +24,36 @@ contract('RBAC', function (accounts) { ...@@ -25,47 +24,36 @@ contract('RBAC', function (accounts) {
context('in normal conditions', () => { context('in normal conditions', () => {
it('allows admin to call #onlyAdminsCanDoThis', async () => { it('allows admin to call #onlyAdminsCanDoThis', async () => {
await mock.onlyAdminsCanDoThis({ from: admin }) await mock.onlyAdminsCanDoThis({ from: admin });
.should.be.fulfilled;
}); });
it('allows admin to call #onlyAdvisorsCanDoThis', async () => { it('allows admin to call #onlyAdvisorsCanDoThis', async () => {
await mock.onlyAdvisorsCanDoThis({ from: admin }) await mock.onlyAdvisorsCanDoThis({ from: admin });
.should.be.fulfilled;
}); });
it('allows advisors to call #onlyAdvisorsCanDoThis', async () => { it('allows advisors to call #onlyAdvisorsCanDoThis', async () => {
await mock.onlyAdvisorsCanDoThis({ from: advisors[0] }) await mock.onlyAdvisorsCanDoThis({ from: advisors[0] });
.should.be.fulfilled;
}); });
it('allows admin to call #eitherAdminOrAdvisorCanDoThis', async () => { it('allows admin to call #eitherAdminOrAdvisorCanDoThis', async () => {
await mock.eitherAdminOrAdvisorCanDoThis({ from: admin }) await mock.eitherAdminOrAdvisorCanDoThis({ from: admin });
.should.be.fulfilled;
}); });
it('allows advisors to call #eitherAdminOrAdvisorCanDoThis', async () => { it('allows advisors to call #eitherAdminOrAdvisorCanDoThis', async () => {
await mock.eitherAdminOrAdvisorCanDoThis({ from: advisors[0] }) await mock.eitherAdminOrAdvisorCanDoThis({ from: advisors[0] });
.should.be.fulfilled;
}); });
it('does not allow admins to call #nobodyCanDoThis', async () => { it('does not allow admins to call #nobodyCanDoThis', async () => {
await expectThrow( await expectThrow(mock.nobodyCanDoThis({ from: admin }));
mock.nobodyCanDoThis({ from: admin })
);
}); });
it('does not allow advisors to call #nobodyCanDoThis', async () => { it('does not allow advisors to call #nobodyCanDoThis', async () => {
await expectThrow( await expectThrow(mock.nobodyCanDoThis({ from: advisors[0] }));
mock.nobodyCanDoThis({ from: advisors[0] })
);
}); });
it('does not allow anyone to call #nobodyCanDoThis', async () => { it('does not allow anyone to call #nobodyCanDoThis', async () => {
await expectThrow( await expectThrow(mock.nobodyCanDoThis({ from: anyone }));
mock.nobodyCanDoThis({ from: anyone })
);
}); });
it('allows an admin to remove an advisor\'s role', async () => { it('allows an admin to remove an advisor\'s role', async () => {
await mock.removeAdvisor(advisors[0], { from: admin }) await mock.removeAdvisor(advisors[0], { from: admin })
.should.be.fulfilled; ;
}); });
it('allows admins to #adminRemoveRole', async () => { it('allows admins to #adminRemoveRole', async () => {
await mock.adminRemoveRole(advisors[3], ROLE_ADVISOR, { from: admin }) await mock.adminRemoveRole(advisors[3], ROLE_ADVISOR, { from: admin })
.should.be.fulfilled; ;
}); });
it('announces a RoleAdded event on addRole', async () => { it('announces a RoleAdded event on addRole', async () => {
...@@ -85,14 +73,10 @@ contract('RBAC', function (accounts) { ...@@ -85,14 +73,10 @@ contract('RBAC', function (accounts) {
context('in adversarial conditions', () => { context('in adversarial conditions', () => {
it('does not allow an advisor to remove another advisor', async () => { it('does not allow an advisor to remove another advisor', async () => {
await expectThrow( await expectThrow(mock.removeAdvisor(advisors[1], { from: advisors[0] }));
mock.removeAdvisor(advisors[1], { from: advisors[0] })
);
}); });
it('does not allow "anyone" to remove an advisor', async () => { it('does not allow "anyone" to remove an advisor', async () => {
await expectThrow( await expectThrow(mock.removeAdvisor(advisors[0], { from: anyone }));
mock.removeAdvisor(advisors[0], { from: anyone })
);
}); });
}); });
}); });
const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour'); const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
...@@ -35,7 +36,7 @@ contract('ConditionalEscrow', function (accounts) { ...@@ -35,7 +36,7 @@ contract('ConditionalEscrow', function (accounts) {
it('reverts on withdrawals', async function () { it('reverts on withdrawals', async function () {
await this.escrow.deposit(payee, { from: owner, value: amount }); await this.escrow.deposit(payee, { from: owner, value: amount });
await this.escrow.withdraw(payee, { from: owner }).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.withdraw(payee, { from: owner }), EVMRevert);
}); });
}); });
}); });
const expectEvent = require('../helpers/expectEvent'); const expectEvent = require('../helpers/expectEvent');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const { ethGetBalance } = require('../helpers/web3'); const { ethGetBalance } = require('../helpers/web3');
...@@ -28,7 +29,7 @@ function shouldBehaveLikeEscrow (owner, [payee1, payee2]) { ...@@ -28,7 +29,7 @@ function shouldBehaveLikeEscrow (owner, [payee1, payee2]) {
}); });
it('only the owner can deposit', async function () { it('only the owner can deposit', async function () {
await this.escrow.deposit(payee1, { from: payee2 }).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.deposit(payee1, { from: payee2 }), EVMRevert);
}); });
it('emits a deposited event', async function () { it('emits a deposited event', async function () {
...@@ -84,7 +85,7 @@ function shouldBehaveLikeEscrow (owner, [payee1, payee2]) { ...@@ -84,7 +85,7 @@ function shouldBehaveLikeEscrow (owner, [payee1, payee2]) {
}); });
it('only the owner can withdraw', async function () { it('only the owner can withdraw', async function () {
await this.escrow.withdraw(payee1, { from: payee1 }).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.withdraw(payee1, { from: payee1 }), EVMRevert);
}); });
it('emits a withdrawn event', async function () { it('emits a withdrawn event', async function () {
......
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert'); const { EVMRevert } = require('../helpers/EVMRevert');
const expectEvent = require('../helpers/expectEvent'); const expectEvent = require('../helpers/expectEvent');
const { ethGetBalance } = require('../helpers/web3'); const { ethGetBalance } = require('../helpers/web3');
...@@ -28,17 +29,17 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) { ...@@ -28,17 +29,17 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
it('does not refund refundees', async function () { it('does not refund refundees', async function () {
await this.escrow.deposit(refundee1, { from: owner, value: amount }); await this.escrow.deposit(refundee1, { from: owner, value: amount });
await this.escrow.withdraw(refundee1).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
}); });
it('does not allow beneficiary withdrawal', async function () { it('does not allow beneficiary withdrawal', async function () {
await this.escrow.deposit(refundee1, { from: owner, value: amount }); await this.escrow.deposit(refundee1, { from: owner, value: amount });
await this.escrow.beneficiaryWithdraw().should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
}); });
}); });
it('only owner can enter closed state', async function () { it('only owner can enter closed state', async function () {
await this.escrow.close({ from: beneficiary }).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.close({ from: beneficiary }), EVMRevert);
const receipt = await this.escrow.close({ from: owner }); const receipt = await this.escrow.close({ from: owner });
...@@ -53,11 +54,11 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) { ...@@ -53,11 +54,11 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
}); });
it('rejects deposits', async function () { it('rejects deposits', async function () {
await this.escrow.deposit(refundee1, { from: owner, value: amount }).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.deposit(refundee1, { from: owner, value: amount }), EVMRevert);
}); });
it('does not refund refundees', async function () { it('does not refund refundees', async function () {
await this.escrow.withdraw(refundee1).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
}); });
it('allows beneficiary withdrawal', async function () { it('allows beneficiary withdrawal', async function () {
...@@ -70,7 +71,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) { ...@@ -70,7 +71,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
}); });
it('only owner can enter refund state', async function () { it('only owner can enter refund state', async function () {
await this.escrow.enableRefunds({ from: beneficiary }).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.enableRefunds({ from: beneficiary }), EVMRevert);
const receipt = await this.escrow.enableRefunds({ from: owner }); const receipt = await this.escrow.enableRefunds({ from: owner });
...@@ -85,7 +86,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) { ...@@ -85,7 +86,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
}); });
it('rejects deposits', async function () { it('rejects deposits', async function () {
await this.escrow.deposit(refundee1, { from: owner, value: amount }).should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.deposit(refundee1, { from: owner, value: amount }), EVMRevert);
}); });
it('refunds refundees', async function () { it('refunds refundees', async function () {
...@@ -99,7 +100,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) { ...@@ -99,7 +100,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
}); });
it('does not allow beneficiary withdrawal', async function () { it('does not allow beneficiary withdrawal', async function () {
await this.escrow.beneficiaryWithdraw().should.be.rejectedWith(EVMRevert); await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
}); });
}); });
}); });
...@@ -3,10 +3,10 @@ const { ethGetBalance, ethSendTransaction } = require('../helpers/web3'); ...@@ -3,10 +3,10 @@ const { ethGetBalance, ethSendTransaction } = require('../helpers/web3');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
const { expectThrow } = require('../helpers/expectThrow');
const EVMThrow = require('../helpers/EVMThrow.js'); const EVMThrow = require('../helpers/EVMThrow.js');
const SplitPayment = artifacts.require('SplitPayment'); const SplitPayment = artifacts.require('SplitPayment');
...@@ -38,12 +38,12 @@ contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, pa ...@@ -38,12 +38,12 @@ contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, pa
}); });
it('should throw if no funds to claim', async function () { it('should throw if no funds to claim', async function () {
await this.contract.claim({ from: payee1 }).should.be.rejectedWith(EVMThrow); await expectThrow(this.contract.claim({ from: payee1 }), EVMThrow);
}); });
it('should throw if non-payee want to claim', async function () { it('should throw if non-payee want to claim', async function () {
await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount }); await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount });
await this.contract.claim({ from: nonpayee1 }).should.be.rejectedWith(EVMThrow); await expectThrow(this.contract.claim({ from: nonpayee1 }), EVMThrow);
}); });
it('should distribute funds to payees', async function () { it('should distribute funds to payees', async function () {
......
const ERC20WithMetadata = artifacts.require('ERC20WithMetadataMock'); const ERC20WithMetadata = artifacts.require('ERC20WithMetadataMock');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
const metadataURI = 'https://example.com'; const metadataURI = 'https://example.com';
......
...@@ -5,7 +5,6 @@ const BigNumber = web3.BigNumber; ...@@ -5,7 +5,6 @@ const BigNumber = web3.BigNumber;
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
...@@ -3,7 +3,6 @@ const { assertRevert } = require('../../helpers/assertRevert'); ...@@ -3,7 +3,6 @@ const { assertRevert } = require('../../helpers/assertRevert');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
const { expectThrow } = require('../../helpers/expectThrow');
const { EVMRevert } = require('../../helpers/EVMRevert'); const { EVMRevert } = require('../../helpers/EVMRevert');
require('chai') require('chai')
.use(require('chai-as-promised'))
.should(); .should();
const SafeERC20Helper = artifacts.require('SafeERC20Helper'); const SafeERC20Helper = artifacts.require('SafeERC20Helper');
...@@ -12,26 +12,26 @@ contract('SafeERC20', function () { ...@@ -12,26 +12,26 @@ contract('SafeERC20', function () {
}); });
it('should throw on failed transfer', async function () { it('should throw on failed transfer', async function () {
await this.helper.doFailingTransfer().should.be.rejectedWith(EVMRevert); await expectThrow(this.helper.doFailingTransfer(), EVMRevert);
}); });
it('should throw on failed transferFrom', async function () { it('should throw on failed transferFrom', async function () {
await this.helper.doFailingTransferFrom().should.be.rejectedWith(EVMRevert); await expectThrow(this.helper.doFailingTransferFrom(), EVMRevert);
}); });
it('should throw on failed approve', async function () { it('should throw on failed approve', async function () {
await this.helper.doFailingApprove().should.be.rejectedWith(EVMRevert); await expectThrow(this.helper.doFailingApprove(), EVMRevert);
}); });
it('should not throw on succeeding transfer', async function () { it('should not throw on succeeding transfer', async function () {
await this.helper.doSucceedingTransfer().should.be.fulfilled; await this.helper.doSucceedingTransfer();
}); });
it('should not throw on succeeding transferFrom', async function () { it('should not throw on succeeding transferFrom', async function () {
await this.helper.doSucceedingTransferFrom().should.be.fulfilled; await this.helper.doSucceedingTransferFrom();
}); });
it('should not throw on succeeding approve', async function () { it('should not throw on succeeding approve', async function () {
await this.helper.doSucceedingApprove().should.be.fulfilled; await this.helper.doSucceedingApprove();
}); });
}); });
...@@ -7,7 +7,6 @@ const BigNumber = web3.BigNumber; ...@@ -7,7 +7,6 @@ const BigNumber = web3.BigNumber;
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
const { latestTime } = require('../../helpers/latestTime'); const { latestTime } = require('../../helpers/latestTime');
const { increaseTimeTo, duration } = require('../../helpers/increaseTime'); const { increaseTimeTo, duration } = require('../../helpers/increaseTime');
const { expectThrow } = require('../../helpers/expectThrow');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -22,32 +22,32 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) { ...@@ -22,32 +22,32 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
}); });
it('cannot be released before time limit', async function () { it('cannot be released before time limit', async function () {
await this.timelock.release().should.be.rejected; await expectThrow(this.timelock.release());
}); });
it('cannot be released just before time limit', async function () { it('cannot be released just before time limit', async function () {
await increaseTimeTo(this.releaseTime - duration.seconds(3)); await increaseTimeTo(this.releaseTime - duration.seconds(3));
await this.timelock.release().should.be.rejected; await expectThrow(this.timelock.release());
}); });
it('can be released just after limit', async function () { it('can be released just after limit', async function () {
await increaseTimeTo(this.releaseTime + duration.seconds(1)); await increaseTimeTo(this.releaseTime + duration.seconds(1));
await this.timelock.release().should.be.fulfilled; await this.timelock.release();
const balance = await this.token.balanceOf(beneficiary); const balance = await this.token.balanceOf(beneficiary);
balance.should.be.bignumber.equal(amount); balance.should.be.bignumber.equal(amount);
}); });
it('can be released after time limit', async function () { it('can be released after time limit', async function () {
await increaseTimeTo(this.releaseTime + duration.years(1)); await increaseTimeTo(this.releaseTime + duration.years(1));
await this.timelock.release().should.be.fulfilled; await this.timelock.release();
const balance = await this.token.balanceOf(beneficiary); const balance = await this.token.balanceOf(beneficiary);
balance.should.be.bignumber.equal(amount); balance.should.be.bignumber.equal(amount);
}); });
it('cannot be released twice', async function () { it('cannot be released twice', async function () {
await increaseTimeTo(this.releaseTime + duration.years(1)); await increaseTimeTo(this.releaseTime + duration.years(1));
await this.timelock.release().should.be.fulfilled; await this.timelock.release();
await this.timelock.release().should.be.rejected; await expectThrow(this.timelock.release());
const balance = await this.token.balanceOf(beneficiary); const balance = await this.token.balanceOf(beneficiary);
balance.should.be.bignumber.equal(amount); balance.should.be.bignumber.equal(amount);
}); });
......
const { expectThrow } = require('../../helpers/expectThrow');
const { EVMRevert } = require('../../helpers/EVMRevert'); const { EVMRevert } = require('../../helpers/EVMRevert');
const { latestTime } = require('../../helpers/latestTime'); const { latestTime } = require('../../helpers/latestTime');
const { increaseTimeTo, duration } = require('../../helpers/increaseTime'); const { increaseTimeTo, duration } = require('../../helpers/increaseTime');
...@@ -6,7 +7,6 @@ const { ethGetBlock } = require('../../helpers/web3'); ...@@ -6,7 +7,6 @@ const { ethGetBlock } = require('../../helpers/web3');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
...@@ -29,12 +29,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { ...@@ -29,12 +29,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
}); });
it('cannot be released before cliff', async function () { it('cannot be released before cliff', async function () {
await this.vesting.release(this.token.address).should.be.rejectedWith(EVMRevert); await expectThrow(
this.vesting.release(this.token.address),
EVMRevert,
);
}); });
it('can be released after cliff', async function () { it('can be released after cliff', async function () {
await increaseTimeTo(this.start + this.cliff + duration.weeks(1)); await increaseTimeTo(this.start + this.cliff + duration.weeks(1));
await this.vesting.release(this.token.address).should.be.fulfilled; await this.vesting.release(this.token.address);
}); });
it('should release proper amount after cliff', async function () { it('should release proper amount after cliff', async function () {
...@@ -72,12 +75,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { ...@@ -72,12 +75,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
}); });
it('should be revoked by owner if revocable is set', async function () { it('should be revoked by owner if revocable is set', async function () {
await this.vesting.revoke(this.token.address, { from: owner }).should.be.fulfilled; await this.vesting.revoke(this.token.address, { from: owner });
}); });
it('should fail to be revoked by owner if revocable not set', async function () { it('should fail to be revoked by owner if revocable not set', async function () {
const vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, false, { from: owner }); const vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, false, { from: owner });
await vesting.revoke(this.token.address, { from: owner }).should.be.rejectedWith(EVMRevert); await expectThrow(
vesting.revoke(this.token.address, { from: owner }),
EVMRevert,
);
}); });
it('should return the non-vested tokens when revoked by owner', async function () { it('should return the non-vested tokens when revoked by owner', async function () {
...@@ -110,6 +116,9 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { ...@@ -110,6 +116,9 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
await this.vesting.revoke(this.token.address, { from: owner }); await this.vesting.revoke(this.token.address, { from: owner });
await this.vesting.revoke(this.token.address, { from: owner }).should.be.rejectedWith(EVMRevert); await expectThrow(
this.vesting.revoke(this.token.address, { from: owner }),
EVMRevert,
);
}); });
}); });
...@@ -8,7 +8,6 @@ const ERC721Receiver = artifacts.require('ERC721ReceiverMock.sol'); ...@@ -8,7 +8,6 @@ const ERC721Receiver = artifacts.require('ERC721ReceiverMock.sol');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
...@@ -5,7 +5,6 @@ const BigNumber = web3.BigNumber; ...@@ -5,7 +5,6 @@ const BigNumber = web3.BigNumber;
const ERC721BasicToken = artifacts.require('ERC721BasicTokenMock.sol'); const ERC721BasicToken = artifacts.require('ERC721BasicTokenMock.sol');
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
...@@ -2,7 +2,6 @@ const { assertRevert } = require('../../helpers/assertRevert'); ...@@ -2,7 +2,6 @@ const { assertRevert } = require('../../helpers/assertRevert');
const BigNumber = web3.BigNumber; const BigNumber = web3.BigNumber;
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
...@@ -8,7 +8,6 @@ const BigNumber = web3.BigNumber; ...@@ -8,7 +8,6 @@ const BigNumber = web3.BigNumber;
const ERC721Token = artifacts.require('ERC721TokenMock.sol'); const ERC721Token = artifacts.require('ERC721TokenMock.sol');
require('chai') require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber)) .use(require('chai-bignumber')(BigNumber))
.should(); .should();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment