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;
import "../lifecycle/Destructible.sol";
contract DestructibleMock is Destructible {
function() payable public {}
}
......@@ -38,7 +38,6 @@
"homepage": "https://github.com/OpenZeppelin/zeppelin-solidity",
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.0.0",
"chai-bignumber": "^2.0.2",
"coveralls": "^3.0.1",
"dotenv": "^4.0.0",
......
......@@ -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;
......
......@@ -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();
......@@ -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 });
});
});
......
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();
......@@ -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,
);
});
});
......
......@@ -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();
......@@ -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 });
});
});
......
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();
......@@ -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 () {
......
......@@ -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();
......
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();
......@@ -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);
});
});
......@@ -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);
});
});
......
......@@ -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();
......@@ -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 });
});
});
......
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();
......@@ -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 () {
......
......@@ -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();
......@@ -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 () {
......@@ -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);
});
......
......@@ -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();
......@@ -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);
});
});
});
const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.should();
const WhitelistedCrowdsale = artifacts.require('WhitelistedCrowdsaleImpl');
......@@ -24,20 +24,20 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,
describe('accepting payments', 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.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized }).should.be.fulfilled;
await this.crowdsale.sendTransaction({ value, from: authorized });
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized });
await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized });
});
it('should reject payments to not whitelisted (from whichever buyers)', async function () {
await this.crowdsale.sendTransaction({ value, from: unauthorized }).should.be.rejected;
await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected;
await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected;
await expectThrow(this.crowdsale.sendTransaction({ value, from: unauthorized }));
await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }));
await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }));
});
it('should reject payments to addresses removed from whitelist', async function () {
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,
describe('accepting payments', 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: unauthorized }).should.be.fulfilled;
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.fulfilled;
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: unauthorized }).should.be.fulfilled;
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized });
await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized });
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized });
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: unauthorized });
});
it('should reject payments to not whitelisted (with whichever buyers)', async function () {
await this.crowdsale.send(value).should.be.rejected;
await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected;
await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected;
await expectThrow(this.crowdsale.send(value));
await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }));
await expectThrow(this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }));
});
it('should reject payments to addresses removed from whitelist', async function () {
await this.crowdsale.removeAddressFromWhitelist(anotherAuthorized);
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.rejected;
await this.crowdsale.buyTokens(authorized, { value: value, from: authorized });
await expectThrow(this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }));
});
});
......
......@@ -2,6 +2,7 @@ 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 { assertRevert } = require('../helpers/assertRevert');
const { ethGetBalance } = require('../helpers/web3');
......@@ -9,7 +10,6 @@ const { ethGetBalance } = require('../helpers/web3');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......@@ -58,8 +58,14 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
});
it('should not accept payments before start', async function () {
await this.crowdsale.send(ether(1)).should.be.rejectedWith(EVMRevert);
await this.crowdsale.buyTokens(investor, { from: investor, value: ether(1) }).should.be.rejectedWith(EVMRevert);
await expectThrow(
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 () {
......@@ -67,7 +73,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
const expectedTokenAmount = RATE.mul(investmentAmount);
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.totalSupply()).should.be.bignumber.equal(expectedTokenAmount);
......@@ -75,14 +81,14 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
it('should reject payments after end', async function () {
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.send(ether(1)).should.be.rejectedWith(EVMRevert);
await this.crowdsale.buyTokens(investor, { value: ether(1), from: investor }).should.be.rejectedWith(EVMRevert);
await expectThrow(this.crowdsale.send(ether(1)), EVMRevert);
await expectThrow(this.crowdsale.buyTokens(investor, { value: ether(1), from: investor }), EVMRevert);
});
it('should reject payments over cap', async function () {
await increaseTimeTo(this.openingTime);
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 () {
......@@ -105,7 +111,7 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
await increaseTimeTo(this.afterClosingTime);
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);
balanceBeforeInvestment.should.be.bignumber.equal(balanceAfterRefund);
......
async function expectThrow (promise) {
async function expectThrow (promise, message) {
try {
await promise;
} catch (error) {
// TODO: Check jump destination to destinguish between a throw
// and an actual invalid jump.
const invalidOpcode = error.message.search('invalid opcode') >= 0;
// 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
// 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;
// Message is an optional parameter here
if (message) {
assert(
error.message.search(message) >= 0,
'Expected \'' + message + '\', got \'' + error + '\' instead',
);
return;
} else {
// TODO: Check jump destination to destinguish between a throw
// and an actual invalid jump.
const invalidOpcode = error.message.search('invalid opcode') >= 0;
// 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
// 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');
}
......
......@@ -4,7 +4,6 @@ const { assertRevert } = require('../helpers/assertRevert');
const SupportsInterfaceWithLookup = artifacts.require('SupportsInterfaceWithLookupMock');
require('chai')
.use(require('chai-as-promised'))
.should();
contract('SupportsInterfaceWithLookup', function (accounts) {
......
......@@ -4,7 +4,6 @@ const { expectThrow } = require('../helpers/expectThrow');
const ECRecoveryMock = artifacts.require('ECRecoveryMock');
require('chai')
.use(require('chai-as-promised'))
.should();
contract('ECRecovery', function (accounts) {
......
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
require('chai')
.use(require('chai-as-promised'))
.should();
function shouldBehaveLikeOwnable (accounts) {
......@@ -25,12 +25,12 @@ function shouldBehaveLikeOwnable (accounts) {
const other = accounts[2];
const owner = await this.ownable.owner.call();
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 () {
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 () {
......@@ -44,7 +44,7 @@ function shouldBehaveLikeOwnable (accounts) {
const other = accounts[2];
const owner = await this.ownable.owner.call();
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');
const Superuser = artifacts.require('Superuser');
require('chai')
.use(require('chai-as-promised'))
.should();
contract('Superuser', function (accounts) {
......
......@@ -4,7 +4,6 @@ const expectEvent = require('../helpers/expectEvent');
const WhitelistMock = artifacts.require('WhitelistMock');
require('chai')
.use(require('chai-as-promised'))
.should();
contract('Whitelist', function (accounts) {
......@@ -69,8 +68,7 @@ contract('Whitelist', function (accounts) {
it('should allow whitelisted address to call #onlyWhitelistedCanDoThis', async function () {
await this.mock.addAddressToWhitelist(whitelistedAddress1, { from: owner });
await this.mock.onlyWhitelistedCanDoThis({ from: whitelistedAddress1 })
.should.be.fulfilled;
await this.mock.onlyWhitelistedCanDoThis({ from: whitelistedAddress1 });
});
});
......
......@@ -4,7 +4,6 @@ const expectEvent = require('../../helpers/expectEvent');
const RBACMock = artifacts.require('RBACMock');
require('chai')
.use(require('chai-as-promised'))
.should();
const ROLE_ADVISOR = 'advisor';
......@@ -25,47 +24,36 @@ contract('RBAC', function (accounts) {
context('in normal conditions', () => {
it('allows admin to call #onlyAdminsCanDoThis', async () => {
await mock.onlyAdminsCanDoThis({ from: admin })
.should.be.fulfilled;
await mock.onlyAdminsCanDoThis({ from: admin });
});
it('allows admin to call #onlyAdvisorsCanDoThis', async () => {
await mock.onlyAdvisorsCanDoThis({ from: admin })
.should.be.fulfilled;
await mock.onlyAdvisorsCanDoThis({ from: admin });
});
it('allows advisors to call #onlyAdvisorsCanDoThis', async () => {
await mock.onlyAdvisorsCanDoThis({ from: advisors[0] })
.should.be.fulfilled;
await mock.onlyAdvisorsCanDoThis({ from: advisors[0] });
});
it('allows admin to call #eitherAdminOrAdvisorCanDoThis', async () => {
await mock.eitherAdminOrAdvisorCanDoThis({ from: admin })
.should.be.fulfilled;
await mock.eitherAdminOrAdvisorCanDoThis({ from: admin });
});
it('allows advisors to call #eitherAdminOrAdvisorCanDoThis', async () => {
await mock.eitherAdminOrAdvisorCanDoThis({ from: advisors[0] })
.should.be.fulfilled;
await mock.eitherAdminOrAdvisorCanDoThis({ from: advisors[0] });
});
it('does not allow admins to call #nobodyCanDoThis', async () => {
await expectThrow(
mock.nobodyCanDoThis({ from: admin })
);
await expectThrow(mock.nobodyCanDoThis({ from: admin }));
});
it('does not allow advisors to call #nobodyCanDoThis', async () => {
await expectThrow(
mock.nobodyCanDoThis({ from: advisors[0] })
);
await expectThrow(mock.nobodyCanDoThis({ from: advisors[0] }));
});
it('does not allow anyone to call #nobodyCanDoThis', async () => {
await expectThrow(
mock.nobodyCanDoThis({ from: anyone })
);
await expectThrow(mock.nobodyCanDoThis({ from: anyone }));
});
it('allows an admin to remove an advisor\'s role', async () => {
await mock.removeAdvisor(advisors[0], { from: admin })
.should.be.fulfilled;
;
});
it('allows admins to #adminRemoveRole', async () => {
await mock.adminRemoveRole(advisors[3], ROLE_ADVISOR, { from: admin })
.should.be.fulfilled;
;
});
it('announces a RoleAdded event on addRole', async () => {
......@@ -85,14 +73,10 @@ contract('RBAC', function (accounts) {
context('in adversarial conditions', () => {
it('does not allow an advisor to remove another advisor', async () => {
await expectThrow(
mock.removeAdvisor(advisors[1], { from: advisors[0] })
);
await expectThrow(mock.removeAdvisor(advisors[1], { from: advisors[0] }));
});
it('does not allow "anyone" to remove an advisor', async () => {
await expectThrow(
mock.removeAdvisor(advisors[0], { from: anyone })
);
await expectThrow(mock.removeAdvisor(advisors[0], { from: anyone }));
});
});
});
const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const BigNumber = web3.BigNumber;
......@@ -35,7 +36,7 @@ contract('ConditionalEscrow', function (accounts) {
it('reverts on withdrawals', async function () {
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 { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const { ethGetBalance } = require('../helpers/web3');
......@@ -28,7 +29,7 @@ function shouldBehaveLikeEscrow (owner, [payee1, payee2]) {
});
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 () {
......@@ -84,7 +85,7 @@ function shouldBehaveLikeEscrow (owner, [payee1, payee2]) {
});
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 () {
......
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const expectEvent = require('../helpers/expectEvent');
const { ethGetBalance } = require('../helpers/web3');
......@@ -28,17 +29,17 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
it('does not refund refundees', async function () {
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 () {
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 () {
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 });
......@@ -53,11 +54,11 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
});
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 () {
await this.escrow.withdraw(refundee1).should.be.rejectedWith(EVMRevert);
await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
});
it('allows beneficiary withdrawal', async function () {
......@@ -70,7 +71,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
});
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 });
......@@ -85,7 +86,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
});
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 () {
......@@ -99,7 +100,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
});
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');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
const { expectThrow } = require('../helpers/expectThrow');
const EVMThrow = require('../helpers/EVMThrow.js');
const SplitPayment = artifacts.require('SplitPayment');
......@@ -38,12 +38,12 @@ contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, pa
});
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 () {
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 () {
......
const ERC20WithMetadata = artifacts.require('ERC20WithMetadataMock');
require('chai')
.use(require('chai-as-promised'))
.should();
const metadataURI = 'https://example.com';
......
......@@ -5,7 +5,6 @@ const BigNumber = web3.BigNumber;
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......
......@@ -3,7 +3,6 @@ const { assertRevert } = require('../../helpers/assertRevert');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......
const { expectThrow } = require('../../helpers/expectThrow');
const { EVMRevert } = require('../../helpers/EVMRevert');
require('chai')
.use(require('chai-as-promised'))
.should();
const SafeERC20Helper = artifacts.require('SafeERC20Helper');
......@@ -12,26 +12,26 @@ contract('SafeERC20', 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 () {
await this.helper.doFailingTransferFrom().should.be.rejectedWith(EVMRevert);
await expectThrow(this.helper.doFailingTransferFrom(), EVMRevert);
});
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 () {
await this.helper.doSucceedingTransfer().should.be.fulfilled;
await this.helper.doSucceedingTransfer();
});
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 () {
await this.helper.doSucceedingApprove().should.be.fulfilled;
await this.helper.doSucceedingApprove();
});
});
......@@ -7,7 +7,6 @@ const BigNumber = web3.BigNumber;
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......
const { latestTime } = require('../../helpers/latestTime');
const { increaseTimeTo, duration } = require('../../helpers/increaseTime');
const { expectThrow } = require('../../helpers/expectThrow');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......@@ -22,32 +22,32 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
});
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 () {
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 () {
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);
balance.should.be.bignumber.equal(amount);
});
it('can be released after time limit', async function () {
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);
balance.should.be.bignumber.equal(amount);
});
it('cannot be released twice', async function () {
await increaseTimeTo(this.releaseTime + duration.years(1));
await this.timelock.release().should.be.fulfilled;
await this.timelock.release().should.be.rejected;
await this.timelock.release();
await expectThrow(this.timelock.release());
const balance = await this.token.balanceOf(beneficiary);
balance.should.be.bignumber.equal(amount);
});
......
const { expectThrow } = require('../../helpers/expectThrow');
const { EVMRevert } = require('../../helpers/EVMRevert');
const { latestTime } = require('../../helpers/latestTime');
const { increaseTimeTo, duration } = require('../../helpers/increaseTime');
......@@ -6,7 +7,6 @@ const { ethGetBlock } = require('../../helpers/web3');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......@@ -29,12 +29,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
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 () {
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 () {
......@@ -72,12 +75,15 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
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 () {
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 () {
......@@ -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 }).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');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......
......@@ -5,7 +5,6 @@ const BigNumber = web3.BigNumber;
const ERC721BasicToken = artifacts.require('ERC721BasicTokenMock.sol');
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......
......@@ -2,7 +2,6 @@ const { assertRevert } = require('../../helpers/assertRevert');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
......
......@@ -8,7 +8,6 @@ const BigNumber = web3.BigNumber;
const ERC721Token = artifacts.require('ERC721TokenMock.sol');
require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.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