Skip to content

Commit

Permalink
Replaced assertJump, assertRevert and expectThrow with shouldFail. (#…
Browse files Browse the repository at this point in the history
…1363)

* Replaced assertJump, assertRevert and expectThrow with shouldFail.

* Fixed linter errors.

* Fixed typo.

* Made the helpers async.

(cherry picked from commit b0da0fd)
  • Loading branch information
nventuro authored and come-maiz committed Oct 20, 2018
1 parent 620d524 commit 7cd0d5a
Show file tree
Hide file tree
Showing 45 changed files with 274 additions and 344 deletions.
9 changes: 5 additions & 4 deletions test/access/Roles.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { assertRevert } = require('../helpers/assertRevert');
const shouldFail = require('../helpers/shouldFail');
const { ZERO_ADDRESS } = require('../helpers/constants');

const RolesMock = artifacts.require('RolesMock');

require('chai')
Expand All @@ -11,7 +12,7 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
});

it('reverts when querying roles for the null account', async function () {
await assertRevert(this.roles.has(ZERO_ADDRESS));
await shouldFail.reverting(this.roles.has(ZERO_ADDRESS));
});

context('initially', function () {
Expand All @@ -35,7 +36,7 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
});

it('reverts when adding roles to the null account', async function () {
await assertRevert(this.roles.add(ZERO_ADDRESS));
await shouldFail.reverting(this.roles.add(ZERO_ADDRESS));
});
});
});
Expand All @@ -58,7 +59,7 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
});

it('reverts when removing roles from the null account', async function () {
await assertRevert(this.roles.remove(ZERO_ADDRESS));
await shouldFail.reverting(this.roles.remove(ZERO_ADDRESS));
});
});
});
Expand Down
10 changes: 5 additions & 5 deletions test/access/roles/PublicRole.behavior.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { assertRevert } = require('../../helpers/assertRevert');
const shouldFail = require('../../helpers/shouldFail');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const expectEvent = require('../../helpers/expectEvent');

Expand All @@ -20,7 +20,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
});

it('reverts when querying roles for the null account', async function () {
await assertRevert(this.contract[`is${rolename}`](ZERO_ADDRESS));
await shouldFail.reverting(this.contract[`is${rolename}`](ZERO_ADDRESS));
});

describe('access control', function () {
Expand All @@ -36,7 +36,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
const from = anyone;

it('reverts', async function () {
await assertRevert(this.contract[`only${rolename}Mock`]({ from }));
await shouldFail.reverting(this.contract[`only${rolename}Mock`]({ from }));
});
});
});
Expand All @@ -58,7 +58,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
});

it('reverts when adding role to the null account', async function () {
await assertRevert(this.contract[`add${rolename}`](ZERO_ADDRESS, { from: authorized }));
await shouldFail.reverting(this.contract[`add${rolename}`](ZERO_ADDRESS, { from: authorized }));
});
});

Expand All @@ -79,7 +79,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
});

it('reverts when removing role from the null account', async function () {
await assertRevert(this.contract[`remove${rolename}`](ZERO_ADDRESS));
await shouldFail.reverting(this.contract[`remove${rolename}`](ZERO_ADDRESS));
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const expectEvent = require('../helpers/expectEvent');
const { ether } = require('../helpers/ether');
const { assertRevert } = require('../helpers/assertRevert');
const shouldFail = require('../helpers/shouldFail');
const { ethGetBalance } = require('../helpers/web3');
const { ZERO_ADDRESS } = require('../helpers/constants');

Expand Down Expand Up @@ -74,7 +74,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
describe('when token wallet is different from token address', function () {
it('creation reverts', async function () {
this.token = await SimpleToken.new({ from: tokenWallet });
await assertRevert(AllowanceCrowdsaleImpl.new(rate, wallet, this.token.address, ZERO_ADDRESS));
await shouldFail.reverting(AllowanceCrowdsaleImpl.new(rate, wallet, this.token.address, ZERO_ADDRESS));
});
});
});
18 changes: 4 additions & 14 deletions test/crowdsale/CappedCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const shouldFail = require('../helpers/shouldFail');

const BigNumber = web3.BigNumber;

Expand All @@ -22,10 +21,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
});

it('rejects a cap of zero', async function () {
await expectThrow(
CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0),
EVMRevert,
);
await shouldFail.reverting(CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0));
});

context('with crowdsale', function () {
Expand All @@ -42,17 +38,11 @@ contract('CappedCrowdsale', function ([_, wallet]) {

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

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

Expand Down
14 changes: 7 additions & 7 deletions test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const expectEvent = require('../helpers/expectEvent');
const { assertRevert } = require('../helpers/assertRevert');
const shouldFail = require('../helpers/shouldFail');
const { ether } = require('../helpers/ether');
const { ethGetBalance } = require('../helpers/web3');
const { ZERO_ADDRESS } = require('../helpers/constants');
Expand All @@ -20,7 +20,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
const expectedTokenAmount = rate.mul(value);

it('requires a non-null token', async function () {
await assertRevert(
await shouldFail.reverting(
Crowdsale.new(rate, wallet, ZERO_ADDRESS)
);
});
Expand All @@ -31,13 +31,13 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
});

it('requires a non-zero rate', async function () {
await assertRevert(
await shouldFail.reverting(
Crowdsale.new(0, wallet, this.token.address)
);
});

it('requires a non-null wallet', async function () {
await assertRevert(
await shouldFail.reverting(
Crowdsale.new(rate, ZERO_ADDRESS, this.token.address)
);
});
Expand All @@ -55,7 +55,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
});

it('reverts on zero-valued payments', async function () {
await assertRevert(
await shouldFail.reverting(
this.crowdsale.send(0, { from: purchaser })
);
});
Expand All @@ -67,13 +67,13 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
});

it('reverts on zero-valued payments', async function () {
await assertRevert(
await shouldFail.reverting(
this.crowdsale.buyTokens(investor, { value: 0, from: purchaser })
);
});

it('requires a non-null beneficiary', async function () {
await assertRevert(
await shouldFail.reverting(
this.crowdsale.buyTokens(ZERO_ADDRESS, { value: value, from: purchaser })
);
});
Expand Down
7 changes: 3 additions & 4 deletions test/crowdsale/FinalizableCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const expectEvent = require('../helpers/expectEvent');
const { advanceBlock } = require('../helpers/advanceToBlock');
const time = require('../helpers/time');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const shouldFail = require('../helpers/shouldFail');

const BigNumber = web3.BigNumber;

Expand Down Expand Up @@ -33,7 +32,7 @@ contract('FinalizableCrowdsale', function ([_, wallet, anyone]) {
});

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

it('can be finalized by anyone after ending', async function () {
Expand All @@ -44,7 +43,7 @@ contract('FinalizableCrowdsale', function ([_, wallet, anyone]) {
it('cannot be finalized twice', async function () {
await time.increaseTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: anyone });
await expectThrow(this.crowdsale.finalize({ from: anyone }), EVMRevert);
await shouldFail.reverting(this.crowdsale.finalize({ from: anyone }));
});

it('logs finalized', async function () {
Expand Down
6 changes: 3 additions & 3 deletions test/crowdsale/IncreasingPriceCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ether } = require('../helpers/ether');
const { advanceBlock } = require('../helpers/advanceToBlock');
const time = require('../helpers/time');
const { assertRevert } = require('../helpers/assertRevert');
const shouldFail = require('../helpers/shouldFail');

const BigNumber = web3.BigNumber;

Expand Down Expand Up @@ -35,13 +35,13 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
});

it('rejects a final rate larger than the initial rate', async function () {
await assertRevert(IncreasingPriceCrowdsaleImpl.new(
await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new(
this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate.plus(1)
));
});

it('rejects a final rate of zero', async function () {
await assertRevert(IncreasingPriceCrowdsaleImpl.new(
await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new(
this.startTime, this.closingTime, wallet, this.token.address, initialRate, 0
));
});
Expand Down
15 changes: 7 additions & 8 deletions test/crowdsale/IndividuallyCappedCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { ether } = require('../helpers/ether');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const shouldFail = require('../helpers/shouldFail');

const BigNumber = web3.BigNumber;

Expand Down Expand Up @@ -42,7 +41,7 @@ contract('IndividuallyCappedCrowdsale', function (
});

it('reverts when a non-capper sets a cap', async function () {
await expectThrow(this.crowdsale.setCap(alice, capAlice, { from: anyone }), EVMRevert);
await shouldFail.reverting(this.crowdsale.setCap(alice, capAlice, { from: anyone }));
});

context('with individual caps', function () {
Expand All @@ -60,21 +59,21 @@ contract('IndividuallyCappedCrowdsale', function (

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

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions test/crowdsale/MintedCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behavior');
const { ether } = require('../helpers/ether');
const { assertRevert } = require('../helpers/assertRevert');
const shouldFail = require('../helpers/shouldFail');

const BigNumber = web3.BigNumber;

Expand Down Expand Up @@ -35,11 +35,11 @@ contract('MintedCrowdsale', function ([_, deployer, investor, wallet, purchaser]
});

it('rejects bare payments', async function () {
await assertRevert(this.crowdsale.send(value));
await shouldFail.reverting(this.crowdsale.send(value));
});

it('rejects token purchases', async function () {
await assertRevert(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
});
});
});
7 changes: 3 additions & 4 deletions test/crowdsale/PostDeliveryCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { advanceBlock } = require('../helpers/advanceToBlock');
const time = require('../helpers/time');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const shouldFail = require('../helpers/shouldFail');
const { ether } = require('../helpers/ether');

const BigNumber = web3.BigNumber;
Expand Down Expand Up @@ -51,7 +50,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
});

it('does not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
await expectThrow(this.crowdsale.withdrawTokens(investor), EVMRevert);
await shouldFail.reverting(this.crowdsale.withdrawTokens(investor));
});

context('after closing time', function () {
Expand All @@ -67,7 +66,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {

it('rejects multiple withdrawals', async function () {
await this.crowdsale.withdrawTokens(investor);
await expectThrow(this.crowdsale.withdrawTokens(investor), EVMRevert);
await shouldFail.reverting(this.crowdsale.withdrawTokens(investor));
});
});
});
Expand Down
16 changes: 6 additions & 10 deletions test/crowdsale/RefundableCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { ether } = require('../helpers/ether');
const { advanceBlock } = require('../helpers/advanceToBlock');
const shouldFail = require('../helpers/shouldFail');
const time = require('../helpers/time');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const { ethGetBalance } = require('../helpers/web3');

const BigNumber = web3.BigNumber;
Expand Down Expand Up @@ -35,11 +34,8 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
});

it('rejects a goal of zero', async function () {
await expectThrow(
RefundableCrowdsaleImpl.new(
this.openingTime, this.closingTime, rate, wallet, this.token.address, 0,
),
EVMRevert,
await shouldFail.reverting(
RefundableCrowdsaleImpl.new(this.openingTime, this.closingTime, rate, wallet, this.token.address, 0)
);
});

Expand All @@ -54,7 +50,7 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon

context('before opening time', function () {
it('denies refunds', async function () {
await expectThrow(this.crowdsale.claimRefund(investor), EVMRevert);
await shouldFail.reverting(this.crowdsale.claimRefund(investor));
});
});

Expand All @@ -64,7 +60,7 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
});

it('denies refunds', async function () {
await expectThrow(this.crowdsale.claimRefund(investor), EVMRevert);
await shouldFail.reverting(this.crowdsale.claimRefund(investor));
});

context('with unreached goal', function () {
Expand Down Expand Up @@ -99,7 +95,7 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
});

it('denies refunds', async function () {
await expectThrow(this.crowdsale.claimRefund(investor), EVMRevert);
await shouldFail.reverting(this.crowdsale.claimRefund(investor));
});

it('forwards funds to wallet', async function () {
Expand Down
Loading

0 comments on commit 7cd0d5a

Please sign in to comment.