Skip to content

Commit b0da0fd

Browse files
authored
Replaced assertJump, assertRevert and expectThrow with shouldFail. (#1363)
* Replaced assertJump, assertRevert and expectThrow with shouldFail. * Fixed linter errors. * Fixed typo. * Made the helpers async.
1 parent 58a4244 commit b0da0fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+282
-352
lines changed

test/BreakInvariantBounty.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { ether } = require('./helpers/ether');
33
const { sendEther } = require('./helpers/sendTransaction');
44
const { balanceDifference } = require('./helpers/balanceDiff');
55
const expectEvent = require('./helpers/expectEvent');
6-
const { assertRevert } = require('./helpers/assertRevert');
6+
const shouldFail = require('./helpers/shouldFail');
77

88
const BreakInvariantBountyMock = artifacts.require('BreakInvariantBountyMock');
99
const TargetMock = artifacts.require('TargetMock');
@@ -48,7 +48,7 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
4848

4949
context('before exploiting vulnerability', async function () {
5050
it('reverts when claiming reward', async function () {
51-
await assertRevert(this.bounty.claim(this.target.address, { from: researcher }));
51+
await shouldFail.reverting(this.bounty.claim(this.target.address, { from: researcher }));
5252
});
5353
});
5454

@@ -74,19 +74,19 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
7474
});
7575

7676
it('no longer accepts rewards', async function () {
77-
await assertRevert(ethSendTransaction({ from: owner, to: this.bounty.address, value: reward }));
77+
await shouldFail.reverting(ethSendTransaction({ from: owner, to: this.bounty.address, value: reward }));
7878
});
7979

8080
it('reverts when reclaimed', async function () {
81-
await assertRevert(this.bounty.claim(this.target.address, { from: researcher }));
81+
await shouldFail.reverting(this.bounty.claim(this.target.address, { from: researcher }));
8282
});
8383
});
8484
});
8585
});
8686

8787
context('with non-target', function () {
8888
it('reverts when claiming reward', async function () {
89-
await assertRevert(this.bounty.claim(nonTarget, { from: researcher }));
89+
await shouldFail.reverting(this.bounty.claim(nonTarget, { from: researcher }));
9090
});
9191
});
9292
});
@@ -105,7 +105,7 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
105105
});
106106

107107
it('reverts when canceled by anyone', async function () {
108-
await assertRevert(this.bounty.cancelBounty({ from: anyone }));
108+
await shouldFail.reverting(this.bounty.cancelBounty({ from: anyone }));
109109
});
110110
});
111111

@@ -119,11 +119,11 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
119119
});
120120

121121
it('no longer accepts rewards', async function () {
122-
await assertRevert(ethSendTransaction({ from: owner, to: this.bounty.address, value: reward }));
122+
await shouldFail.reverting(ethSendTransaction({ from: owner, to: this.bounty.address, value: reward }));
123123
});
124124

125125
it('reverts when recanceled', async function () {
126-
await assertRevert(this.bounty.cancelBounty({ from: owner }));
126+
await shouldFail.reverting(this.bounty.cancelBounty({ from: owner }));
127127
});
128128
});
129129
});

test/access/Roles.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const { assertRevert } = require('../helpers/assertRevert');
1+
const shouldFail = require('../helpers/shouldFail');
22
const { ZERO_ADDRESS } = require('../helpers/constants');
3+
34
const RolesMock = artifacts.require('RolesMock');
45

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

1314
it('reverts when querying roles for the null account', async function () {
14-
await assertRevert(this.roles.has(ZERO_ADDRESS));
15+
await shouldFail.reverting(this.roles.has(ZERO_ADDRESS));
1516
});
1617

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

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

6061
it('reverts when removing roles from the null account', async function () {
61-
await assertRevert(this.roles.remove(ZERO_ADDRESS));
62+
await shouldFail.reverting(this.roles.remove(ZERO_ADDRESS));
6263
});
6364
});
6465
});

test/access/roles/PublicRole.behavior.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { assertRevert } = require('../../helpers/assertRevert');
1+
const shouldFail = require('../../helpers/shouldFail');
22
const { ZERO_ADDRESS } = require('../../helpers/constants');
33
const expectEvent = require('../../helpers/expectEvent');
44

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

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

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

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

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

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

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

test/crowdsale/AllowanceCrowdsale.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const expectEvent = require('../helpers/expectEvent');
22
const { ether } = require('../helpers/ether');
3-
const { assertRevert } = require('../helpers/assertRevert');
3+
const shouldFail = require('../helpers/shouldFail');
44
const { ethGetBalance } = require('../helpers/web3');
55
const { ZERO_ADDRESS } = require('../helpers/constants');
66

@@ -74,7 +74,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
7474
describe('when token wallet is different from token address', function () {
7575
it('creation reverts', async function () {
7676
this.token = await SimpleToken.new({ from: tokenWallet });
77-
await assertRevert(AllowanceCrowdsaleImpl.new(rate, wallet, this.token.address, ZERO_ADDRESS));
77+
await shouldFail.reverting(AllowanceCrowdsaleImpl.new(rate, wallet, this.token.address, ZERO_ADDRESS));
7878
});
7979
});
8080
});

test/crowdsale/CappedCrowdsale.test.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { ether } = require('../helpers/ether');
2-
const { expectThrow } = require('../helpers/expectThrow');
3-
const { EVMRevert } = require('../helpers/EVMRevert');
2+
const shouldFail = require('../helpers/shouldFail');
43

54
const BigNumber = web3.BigNumber;
65

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

2423
it('rejects a cap of zero', async function () {
25-
await expectThrow(
26-
CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0),
27-
EVMRevert,
28-
);
24+
await shouldFail.reverting(CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0));
2925
});
3026

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

4339
it('should reject payments outside cap', async function () {
4440
await this.crowdsale.send(cap);
45-
await expectThrow(
46-
this.crowdsale.send(1),
47-
EVMRevert,
48-
);
41+
await shouldFail.reverting(this.crowdsale.send(1));
4942
});
5043

5144
it('should reject payments that exceed cap', async function () {
52-
await expectThrow(
53-
this.crowdsale.send(cap.plus(1)),
54-
EVMRevert,
55-
);
45+
await shouldFail.reverting(this.crowdsale.send(cap.plus(1)));
5646
});
5747
});
5848

test/crowdsale/Crowdsale.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const expectEvent = require('../helpers/expectEvent');
2-
const { assertRevert } = require('../helpers/assertRevert');
2+
const shouldFail = require('../helpers/shouldFail');
33
const { ether } = require('../helpers/ether');
44
const { ethGetBalance } = require('../helpers/web3');
55
const { ZERO_ADDRESS } = require('../helpers/constants');
@@ -20,7 +20,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
2020
const expectedTokenAmount = rate.mul(value);
2121

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

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

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

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

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

7575
it('requires a non-null beneficiary', async function () {
76-
await assertRevert(
76+
await shouldFail.reverting(
7777
this.crowdsale.buyTokens(ZERO_ADDRESS, { value: value, from: purchaser })
7878
);
7979
});

test/crowdsale/FinalizableCrowdsale.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const expectEvent = require('../helpers/expectEvent');
22
const { advanceBlock } = require('../helpers/advanceToBlock');
33
const time = require('../helpers/time');
4-
const { expectThrow } = require('../helpers/expectThrow');
5-
const { EVMRevert } = require('../helpers/EVMRevert');
4+
const shouldFail = require('../helpers/shouldFail');
65

76
const BigNumber = web3.BigNumber;
87

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

3534
it('cannot be finalized before ending', async function () {
36-
await expectThrow(this.crowdsale.finalize({ from: anyone }), EVMRevert);
35+
await shouldFail.reverting(this.crowdsale.finalize({ from: anyone }));
3736
});
3837

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

5049
it('logs finalized', async function () {

test/crowdsale/IncreasingPriceCrowdsale.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { ether } = require('../helpers/ether');
22
const { advanceBlock } = require('../helpers/advanceToBlock');
33
const time = require('../helpers/time');
4-
const { assertRevert } = require('../helpers/assertRevert');
4+
const shouldFail = require('../helpers/shouldFail');
55

66
const BigNumber = web3.BigNumber;
77

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

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

4343
it('rejects a final rate of zero', async function () {
44-
await assertRevert(IncreasingPriceCrowdsaleImpl.new(
44+
await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new(
4545
this.startTime, this.closingTime, wallet, this.token.address, initialRate, 0
4646
));
4747
});

test/crowdsale/IndividuallyCappedCrowdsale.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { ether } = require('../helpers/ether');
2-
const { expectThrow } = require('../helpers/expectThrow');
3-
const { EVMRevert } = require('../helpers/EVMRevert');
2+
const shouldFail = require('../helpers/shouldFail');
43

54
const BigNumber = web3.BigNumber;
65

@@ -42,7 +41,7 @@ contract('IndividuallyCappedCrowdsale', function (
4241
});
4342

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

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

6160
it('should reject payments outside cap', async function () {
6261
await this.crowdsale.buyTokens(alice, { value: capAlice });
63-
await expectThrow(this.crowdsale.buyTokens(alice, { value: 1 }), EVMRevert);
62+
await shouldFail.reverting(this.crowdsale.buyTokens(alice, { value: 1 }));
6463
});
6564

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

7170
it('should manage independent caps', async function () {
7271
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
73-
await expectThrow(this.crowdsale.buyTokens(bob, { value: lessThanCapAlice }), EVMRevert);
72+
await shouldFail.reverting(this.crowdsale.buyTokens(bob, { value: lessThanCapAlice }));
7473
});
7574

7675
it('should default to a cap of zero', async function () {
77-
await expectThrow(this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth }), EVMRevert);
76+
await shouldFail.reverting(this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth }));
7877
});
7978
});
8079

test/crowdsale/MintedCrowdsale.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behavior');
22
const { ether } = require('../helpers/ether');
3-
const { assertRevert } = require('../helpers/assertRevert');
3+
const shouldFail = require('../helpers/shouldFail');
44

55
const BigNumber = web3.BigNumber;
66

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

3737
it('rejects bare payments', async function () {
38-
await assertRevert(this.crowdsale.send(value));
38+
await shouldFail.reverting(this.crowdsale.send(value));
3939
});
4040

4141
it('rejects token purchases', async function () {
42-
await assertRevert(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
42+
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
4343
});
4444
});
4545
});

0 commit comments

Comments
 (0)