diff --git a/test/access/Roles.test.js b/test/access/Roles.test.js index 76517492c..869217776 100644 --- a/test/access/Roles.test.js +++ b/test/access/Roles.test.js @@ -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') @@ -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 () { @@ -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)); }); }); }); @@ -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)); }); }); }); diff --git a/test/access/roles/PublicRole.behavior.js b/test/access/roles/PublicRole.behavior.js index a3067f88e..57b94cf97 100644 --- a/test/access/roles/PublicRole.behavior.js +++ b/test/access/roles/PublicRole.behavior.js @@ -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'); @@ -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 () { @@ -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 })); }); }); }); @@ -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 })); }); }); @@ -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)); }); }); diff --git a/test/crowdsale/AllowanceCrowdsale.test.js b/test/crowdsale/AllowanceCrowdsale.test.js index c6f825126..4298dcce6 100644 --- a/test/crowdsale/AllowanceCrowdsale.test.js +++ b/test/crowdsale/AllowanceCrowdsale.test.js @@ -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'); @@ -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)); }); }); }); diff --git a/test/crowdsale/CappedCrowdsale.test.js b/test/crowdsale/CappedCrowdsale.test.js index 5ccfafba3..a073d7a4e 100644 --- a/test/crowdsale/CappedCrowdsale.test.js +++ b/test/crowdsale/CappedCrowdsale.test.js @@ -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; @@ -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 () { @@ -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))); }); }); diff --git a/test/crowdsale/Crowdsale.test.js b/test/crowdsale/Crowdsale.test.js index b1f3b381f..8875e9157 100644 --- a/test/crowdsale/Crowdsale.test.js +++ b/test/crowdsale/Crowdsale.test.js @@ -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'); @@ -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) ); }); @@ -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) ); }); @@ -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 }) ); }); @@ -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 }) ); }); diff --git a/test/crowdsale/FinalizableCrowdsale.test.js b/test/crowdsale/FinalizableCrowdsale.test.js index 6eea7f2f2..93d406432 100644 --- a/test/crowdsale/FinalizableCrowdsale.test.js +++ b/test/crowdsale/FinalizableCrowdsale.test.js @@ -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; @@ -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 () { @@ -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 () { diff --git a/test/crowdsale/IncreasingPriceCrowdsale.test.js b/test/crowdsale/IncreasingPriceCrowdsale.test.js index 2024d7751..a76186bbc 100644 --- a/test/crowdsale/IncreasingPriceCrowdsale.test.js +++ b/test/crowdsale/IncreasingPriceCrowdsale.test.js @@ -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; @@ -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 )); }); diff --git a/test/crowdsale/IndividuallyCappedCrowdsale.test.js b/test/crowdsale/IndividuallyCappedCrowdsale.test.js index 70c01a6b9..c92fad466 100644 --- a/test/crowdsale/IndividuallyCappedCrowdsale.test.js +++ b/test/crowdsale/IndividuallyCappedCrowdsale.test.js @@ -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; @@ -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 () { @@ -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 })); }); }); diff --git a/test/crowdsale/MintedCrowdsale.test.js b/test/crowdsale/MintedCrowdsale.test.js index a3c846b2d..0b95f9ab8 100644 --- a/test/crowdsale/MintedCrowdsale.test.js +++ b/test/crowdsale/MintedCrowdsale.test.js @@ -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; @@ -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 })); }); }); }); diff --git a/test/crowdsale/PostDeliveryCrowdsale.test.js b/test/crowdsale/PostDeliveryCrowdsale.test.js index 866e4da15..723cb1fca 100644 --- a/test/crowdsale/PostDeliveryCrowdsale.test.js +++ b/test/crowdsale/PostDeliveryCrowdsale.test.js @@ -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; @@ -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 () { @@ -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)); }); }); }); diff --git a/test/crowdsale/RefundableCrowdsale.test.js b/test/crowdsale/RefundableCrowdsale.test.js index 77e0bfebb..6b863abad 100644 --- a/test/crowdsale/RefundableCrowdsale.test.js +++ b/test/crowdsale/RefundableCrowdsale.test.js @@ -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; @@ -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) ); }); @@ -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)); }); }); @@ -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 () { @@ -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 () { diff --git a/test/crowdsale/TimedCrowdsale.test.js b/test/crowdsale/TimedCrowdsale.test.js index cfbc3d3cf..eb2a9bf51 100644 --- a/test/crowdsale/TimedCrowdsale.test.js +++ b/test/crowdsale/TimedCrowdsale.test.js @@ -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 BigNumber = web3.BigNumber; @@ -31,15 +30,15 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { }); it('rejects an opening time in the past', async function () { - await expectThrow(TimedCrowdsaleImpl.new( + await shouldFail.reverting(TimedCrowdsaleImpl.new( (await time.latest()) - time.duration.days(1), this.closingTime, rate, wallet, this.token.address - ), EVMRevert); + )); }); it('rejects a closing time before the opening time', async function () { - await expectThrow(TimedCrowdsaleImpl.new( + await shouldFail.reverting(TimedCrowdsaleImpl.new( this.openingTime, this.openingTime - time.duration.seconds(1), rate, wallet, this.token.address - ), EVMRevert); + )); }); context('with crowdsale', function () { @@ -60,8 +59,8 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { describe('accepting payments', function () { it('should reject payments before start', async function () { (await this.crowdsale.isOpen()).should.equal(false); - await expectThrow(this.crowdsale.send(value), EVMRevert); - await expectThrow(this.crowdsale.buyTokens(investor, { from: purchaser, value: value }), EVMRevert); + await shouldFail.reverting(this.crowdsale.send(value)); + await shouldFail.reverting(this.crowdsale.buyTokens(investor, { from: purchaser, value: value })); }); it('should accept payments after start', async function () { @@ -73,8 +72,8 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { it('should reject payments after end', async function () { await time.increaseTo(this.afterClosingTime); - await expectThrow(this.crowdsale.send(value), EVMRevert); - await expectThrow(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }), EVMRevert); + await shouldFail.reverting(this.crowdsale.send(value)); + await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: value, from: purchaser })); }); }); }); diff --git a/test/drafts/ERC20Migrator.test.js b/test/drafts/ERC20Migrator.test.js index 608dce860..92763a219 100644 --- a/test/drafts/ERC20Migrator.test.js +++ b/test/drafts/ERC20Migrator.test.js @@ -1,5 +1,6 @@ -const { assertRevert } = require('../helpers/assertRevert'); +const shouldFail = require('../helpers/shouldFail'); const { ZERO_ADDRESS } = require('../helpers/constants'); + const ERC20Mock = artifacts.require('ERC20Mock'); const ERC20Mintable = artifacts.require('ERC20Mintable'); const ERC20Migrator = artifacts.require('ERC20Migrator'); @@ -14,7 +15,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) { const totalSupply = 200; it('reverts with a null legacy token address', async function () { - await assertRevert(ERC20Migrator.new(ZERO_ADDRESS)); + await shouldFail.reverting(ERC20Migrator.new(ZERO_ADDRESS)); }); describe('with tokens and migrator', function () { @@ -30,11 +31,11 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) { describe('beginMigration', function () { it('reverts with a null new token address', async function () { - await assertRevert(this.migrator.beginMigration(ZERO_ADDRESS)); + await shouldFail.reverting(this.migrator.beginMigration(ZERO_ADDRESS)); }); it('reverts if not a minter of the token', async function () { - await assertRevert(this.migrator.beginMigration(this.newToken.address)); + await shouldFail.reverting(this.migrator.beginMigration(this.newToken.address)); }); it('succeeds if it is a minter of the token', async function () { @@ -45,7 +46,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) { it('reverts the second time it is called', async function () { await this.newToken.addMinter(this.migrator.address); await this.migrator.beginMigration(this.newToken.address); - await assertRevert(this.migrator.beginMigration(this.newToken.address)); + await shouldFail.reverting(this.migrator.beginMigration(this.newToken.address)); }); }); @@ -145,7 +146,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) { const amount = baseAmount + 1; it('reverts', async function () { - await assertRevert(this.migrator.migrate(owner, amount)); + await shouldFail.reverting(this.migrator.migrate(owner, amount)); }); }); }); diff --git a/test/drafts/SignatureBouncer.test.js b/test/drafts/SignatureBouncer.test.js index c234687fc..e1bb294f3 100644 --- a/test/drafts/SignatureBouncer.test.js +++ b/test/drafts/SignatureBouncer.test.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../helpers/assertRevert'); +const shouldFail = require('../helpers/shouldFail'); const { getSignFor } = require('../helpers/sign'); const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior'); @@ -36,19 +36,19 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz }); it('does not allow invalid signature for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignature(INVALID_SIGNATURE, { from: authorizedUser }) ); }); it('does not allow valid signature for other sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser), { from: anyone }) ); }); it('does not allow valid signature for method for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser, 'onlyWithValidSignature'), { from: authorizedUser }) ); @@ -63,13 +63,13 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz }); it('does not allow invalid signature with correct method for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndMethod(INVALID_SIGNATURE, { from: authorizedUser }) ); }); it('does not allow valid signature with correct method for other sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndMethod( this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: anyone } ) @@ -77,14 +77,14 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz }); it('does not allow valid method signature with incorrect method for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndMethod(this.signFor(authorizedUser, 'theWrongMethod'), { from: authorizedUser }) ); }); it('does not allow valid non-method signature method for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndMethod(this.signFor(authorizedUser), { from: authorizedUser }) ); }); @@ -98,13 +98,13 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz }); it('does not allow invalid signature with correct method and data for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE, INVALID_SIGNATURE, { from: authorizedUser }) ); }); it('does not allow valid signature with correct method and incorrect data for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE + 10, this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: authorizedUser } @@ -113,7 +113,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz }); it('does not allow valid signature with correct method and data for other sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE, this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: anyone } @@ -122,7 +122,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz }); it('does not allow valid non-method signature for sender', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE, this.signFor(authorizedUser), { from: authorizedUser } ) @@ -130,7 +130,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz }); it('does not allow msg.data shorter than SIGNATURE_SIZE', async function () { - await assertRevert( + await shouldFail.reverting( this.sigBouncer.tooShortMsgData({ from: authorizedUser }) ); }); diff --git a/test/examples/SampleCrowdsale.test.js b/test/examples/SampleCrowdsale.test.js index 303ddf704..da367c970 100644 --- a/test/examples/SampleCrowdsale.test.js +++ b/test/examples/SampleCrowdsale.test.js @@ -1,9 +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 { assertRevert } = require('../helpers/assertRevert'); const { ethGetBalance } = require('../helpers/web3'); const BigNumber = web3.BigNumber; @@ -53,14 +51,8 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { }); it('should not accept payments before start', async function () { - await expectThrow( - this.crowdsale.send(ether(1)), - EVMRevert, - ); - await expectThrow( - this.crowdsale.buyTokens(investor, { from: investor, value: ether(1) }), - EVMRevert, - ); + await shouldFail.reverting(this.crowdsale.send(ether(1))); + await shouldFail.reverting(this.crowdsale.buyTokens(investor, { from: investor, value: ether(1) })); }); it('should accept payments during the sale', async function () { @@ -76,14 +68,14 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { it('should reject payments after end', async function () { await time.increaseTo(this.afterClosingTime); - await expectThrow(this.crowdsale.send(ether(1)), EVMRevert); - await expectThrow(this.crowdsale.buyTokens(investor, { value: ether(1), from: investor }), EVMRevert); + await shouldFail.reverting(this.crowdsale.send(ether(1))); + await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: ether(1), from: investor })); }); it('should reject payments over cap', async function () { await time.increaseTo(this.openingTime); await this.crowdsale.send(CAP); - await expectThrow(this.crowdsale.send(1), EVMRevert); + await shouldFail.reverting(this.crowdsale.send(1)); }); it('should allow finalization and transfer funds to wallet if the goal is reached', async function () { @@ -117,7 +109,7 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) { const HIGH_GOAL = ether(30); it('creation reverts', async function () { - await assertRevert(SampleCrowdsale.new( + await shouldFail.reverting(SampleCrowdsale.new( this.openingTime, this.closingTime, RATE, wallet, CAP, this.token.address, HIGH_GOAL )); }); diff --git a/test/helpers/EVMRevert.js b/test/helpers/EVMRevert.js deleted file mode 100644 index cb0c8e02e..000000000 --- a/test/helpers/EVMRevert.js +++ /dev/null @@ -1,5 +0,0 @@ -const EVMRevert = 'revert'; - -module.exports = { - EVMRevert, -}; diff --git a/test/helpers/EVMThrow.js b/test/helpers/EVMThrow.js deleted file mode 100644 index afe21d277..000000000 --- a/test/helpers/EVMThrow.js +++ /dev/null @@ -1,5 +0,0 @@ -const EVMThrow = 'invalid opcode'; - -module.exports = { - EVMThrow, -}; diff --git a/test/helpers/assertJump.js b/test/helpers/assertJump.js deleted file mode 100644 index 979307088..000000000 --- a/test/helpers/assertJump.js +++ /dev/null @@ -1,15 +0,0 @@ -const should = require('chai') - .should(); - -async function assertJump (promise) { - try { - await promise; - should.fail('Expected invalid opcode not received'); - } catch (error) { - error.message.should.include('invalid opcode', `Expected "invalid opcode", got ${error} instead`); - } -} - -module.exports = { - assertJump, -}; diff --git a/test/helpers/assertRevert.js b/test/helpers/assertRevert.js deleted file mode 100644 index 3d1aa2e16..000000000 --- a/test/helpers/assertRevert.js +++ /dev/null @@ -1,16 +0,0 @@ -const should = require('chai') - .should(); - -async function assertRevert (promise) { - try { - await promise; - } catch (error) { - error.message.should.include('revert', `Expected "revert", got ${error} instead`); - return; - } - should.fail('Expected revert not received'); -} - -module.exports = { - assertRevert, -}; diff --git a/test/helpers/expectThrow.js b/test/helpers/expectThrow.js deleted file mode 100644 index f46a981c8..000000000 --- a/test/helpers/expectThrow.js +++ /dev/null @@ -1,28 +0,0 @@ -const should = require('chai') - .should(); - -async function expectThrow (promise, message) { - try { - await promise; - } catch (error) { - // Message is an optional parameter here - if (message) { - error.message.should.include(message, 'Expected \'' + message + '\', got \'' + error + '\' instead'); - return; - } else { - // TODO: Check jump destination to destinguish between a throw - // and an actual invalid jump. - // 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.) - error.message.should.match(/[invalid opcode|out of gas|revert]/, 'Expected throw, got \'' + error + '\' instead'); - return; - } - } - should.fail('Expected throw not received'); -} - -module.exports = { - expectThrow, -}; diff --git a/test/helpers/shouldFail.js b/test/helpers/shouldFail.js new file mode 100644 index 000000000..45e72f921 --- /dev/null +++ b/test/helpers/shouldFail.js @@ -0,0 +1,31 @@ +const should = require('chai') + .should(); + +async function shouldFailWithMessage (promise, message) { + try { + await promise; + } catch (error) { + error.message.should.include(message, 'Wrong failure type'); + return; + } + + should.fail(`Expected '${message}' failure not received`); +} + +async function reverting (promise) { + await shouldFailWithMessage(promise, 'revert'); +} + +async function throwing (promise) { + await shouldFailWithMessage(promise, 'invalid opcode'); +} + +async function outOfGas (promise) { + await shouldFailWithMessage(promise, 'out of gas'); +} + +module.exports = { + reverting, + throwing, + outOfGas, +}; diff --git a/test/introspection/ERC165.test.js b/test/introspection/ERC165.test.js index dc04edaa2..0dc2f8471 100644 --- a/test/introspection/ERC165.test.js +++ b/test/introspection/ERC165.test.js @@ -1,5 +1,5 @@ const { shouldSupportInterfaces } = require('./SupportsInterface.behavior'); -const { assertRevert } = require('../helpers/assertRevert'); +const shouldFail = require('../helpers/shouldFail'); const ERC165Mock = artifacts.require('ERC165Mock'); @@ -12,7 +12,7 @@ contract('ERC165', function () { }); it('does not allow 0xffffffff', async function () { - await assertRevert( + await shouldFail.reverting( this.mock.registerInterface(0xffffffff) ); }); diff --git a/test/library/ECDSA.test.js b/test/library/ECDSA.test.js index f8d333a5f..b07178b20 100644 --- a/test/library/ECDSA.test.js +++ b/test/library/ECDSA.test.js @@ -1,5 +1,5 @@ const { signMessage, toEthSignedMessageHash } = require('../helpers/sign'); -const { expectThrow } = require('../helpers/expectThrow'); +const shouldFail = require('../helpers/shouldFail'); const ECDSAMock = artifacts.require('ECDSAMock'); @@ -113,7 +113,7 @@ contract('ECDSA', function ([_, anyone]) { it.skip('reverts', async function () { // Create the signature const signature = signMessage(anyone, TEST_MESSAGE); - await expectThrow( + await shouldFail.reverting( this.ecdsa.recover(TEST_MESSAGE.substring(2), signature) ); }); diff --git a/test/lifecycle/Pausable.test.js b/test/lifecycle/Pausable.test.js index 2ae4c90d7..a7f6d637d 100644 --- a/test/lifecycle/Pausable.test.js +++ b/test/lifecycle/Pausable.test.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../helpers/assertRevert'); +const shouldFail = require('../helpers/shouldFail'); const expectEvent = require('../helpers/expectEvent'); const PausableMock = artifacts.require('PausableMock'); @@ -37,7 +37,7 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts }); it('cannot take drastic measure in non-pause', async function () { - await assertRevert(this.pausable.drasticMeasure({ from: anyone })); + await shouldFail.reverting(this.pausable.drasticMeasure({ from: anyone })); (await this.pausable.drasticMeasureTaken()).should.equal(false); }); @@ -48,7 +48,7 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts }); it('reverts when pausing from non-pauser', async function () { - await assertRevert(this.pausable.pause({ from: anyone })); + await shouldFail.reverting(this.pausable.pause({ from: anyone })); }); context('when paused', function () { @@ -61,7 +61,7 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts }); it('cannot perform normal process in pause', async function () { - await assertRevert(this.pausable.normalProcess({ from: anyone })); + await shouldFail.reverting(this.pausable.normalProcess({ from: anyone })); }); it('can take a drastic measure in a pause', async function () { @@ -70,7 +70,7 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts }); it('reverts when re-pausing', async function () { - await assertRevert(this.pausable.pause({ from: pauser })); + await shouldFail.reverting(this.pausable.pause({ from: pauser })); }); describe('unpausing', function () { @@ -80,7 +80,7 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts }); it('reverts when unpausing from non-pauser', async function () { - await assertRevert(this.pausable.unpause({ from: anyone })); + await shouldFail.reverting(this.pausable.unpause({ from: anyone })); }); context('when unpaused', function () { @@ -99,11 +99,11 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts }); it('should prevent drastic measure', async function () { - await assertRevert(this.pausable.drasticMeasure({ from: anyone })); + await shouldFail.reverting(this.pausable.drasticMeasure({ from: anyone })); }); it('reverts when re-unpausing', async function () { - await assertRevert(this.pausable.unpause({ from: pauser })); + await shouldFail.reverting(this.pausable.unpause({ from: pauser })); }); }); }); diff --git a/test/math/SafeMath.test.js b/test/math/SafeMath.test.js index 56cedeb84..dcbb4fbb6 100644 --- a/test/math/SafeMath.test.js +++ b/test/math/SafeMath.test.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../helpers/assertRevert'); +const shouldFail = require('../helpers/shouldFail'); const { MAX_UINT256 } = require('../helpers/constants'); const BigNumber = web3.BigNumber; @@ -25,7 +25,7 @@ contract('SafeMath', function () { const a = MAX_UINT256; const b = new BigNumber(1); - await assertRevert(this.safeMath.add(a, b)); + await shouldFail.reverting(this.safeMath.add(a, b)); }); }); @@ -41,7 +41,7 @@ contract('SafeMath', function () { const a = new BigNumber(1234); const b = new BigNumber(5678); - await assertRevert(this.safeMath.sub(a, b)); + await shouldFail.reverting(this.safeMath.sub(a, b)); }); }); @@ -64,7 +64,7 @@ contract('SafeMath', function () { const a = MAX_UINT256; const b = new BigNumber(2); - await assertRevert(this.safeMath.mul(a, b)); + await shouldFail.reverting(this.safeMath.mul(a, b)); }); }); @@ -80,7 +80,7 @@ contract('SafeMath', function () { const a = new BigNumber(5678); const b = new BigNumber(0); - await assertRevert(this.safeMath.div(a, b)); + await shouldFail.reverting(this.safeMath.div(a, b)); }); }); @@ -119,7 +119,7 @@ contract('SafeMath', function () { const a = new BigNumber(5678); const b = new BigNumber(0); - await assertRevert(this.safeMath.mod(a, b)); + await shouldFail.reverting(this.safeMath.mod(a, b)); }); }); }); diff --git a/test/ownership/Ownable.behavior.js b/test/ownership/Ownable.behavior.js index 1e2fd7564..dd6007cef 100644 --- a/test/ownership/Ownable.behavior.js +++ b/test/ownership/Ownable.behavior.js @@ -1,5 +1,4 @@ -const { expectThrow } = require('../helpers/expectThrow'); -const { EVMRevert } = require('../helpers/EVMRevert'); +const shouldFail = require('../helpers/shouldFail'); const expectEvent = require('../helpers/expectEvent'); const { ZERO_ADDRESS } = require('../helpers/constants'); @@ -22,11 +21,11 @@ function shouldBehaveLikeOwnable (owner, [anyone]) { }); it('should prevent non-owners from transfering', async function () { - await expectThrow(this.ownable.transferOwnership(anyone, { from: anyone }), EVMRevert); + await shouldFail.reverting(this.ownable.transferOwnership(anyone, { from: anyone })); }); it('should guard ownership against stuck state', async function () { - await expectThrow(this.ownable.transferOwnership(null, { from: owner }), EVMRevert); + await shouldFail.reverting(this.ownable.transferOwnership(null, { from: owner })); }); it('loses owner after renouncement', async function () { @@ -37,7 +36,7 @@ function shouldBehaveLikeOwnable (owner, [anyone]) { }); it('should prevent non-owners from renouncement', async function () { - await expectThrow(this.ownable.renounceOwnership({ from: anyone }), EVMRevert); + await shouldFail.reverting(this.ownable.renounceOwnership({ from: anyone })); }); }); } diff --git a/test/ownership/Secondary.test.js b/test/ownership/Secondary.test.js index 31676be79..55283963b 100644 --- a/test/ownership/Secondary.test.js +++ b/test/ownership/Secondary.test.js @@ -1,5 +1,6 @@ -const { assertRevert } = require('../helpers/assertRevert'); +const shouldFail = require('../helpers/shouldFail'); const { ZERO_ADDRESS } = require('../helpers/constants'); + const SecondaryMock = artifacts.require('SecondaryMock'); require('chai') @@ -20,7 +21,7 @@ contract('Secondary', function ([_, primary, newPrimary, anyone]) { }); it('reverts when anyone calls onlyPrimary functions', async function () { - await assertRevert(this.secondary.onlyPrimaryMock({ from: anyone })); + await shouldFail.reverting(this.secondary.onlyPrimaryMock({ from: anyone })); }); }); @@ -31,11 +32,11 @@ contract('Secondary', function ([_, primary, newPrimary, anyone]) { }); it('reverts when transfering to the null address', async function () { - await assertRevert(this.secondary.transferPrimary(ZERO_ADDRESS, { from: primary })); + await shouldFail.reverting(this.secondary.transferPrimary(ZERO_ADDRESS, { from: primary })); }); it('reverts when called by anyone', async function () { - await assertRevert(this.secondary.transferPrimary(newPrimary, { from: anyone })); + await shouldFail.reverting(this.secondary.transferPrimary(newPrimary, { from: anyone })); }); context('with new primary', function () { @@ -48,7 +49,7 @@ contract('Secondary', function ([_, primary, newPrimary, anyone]) { }); it('reverts when the old primary account calls onlyPrimary functions', async function () { - await assertRevert(this.secondary.onlyPrimaryMock({ from: primary })); + await shouldFail.reverting(this.secondary.onlyPrimaryMock({ from: primary })); }); }); }); diff --git a/test/payment/ConditionalEscrow.test.js b/test/payment/ConditionalEscrow.test.js index 03eed68f7..bfb38dd86 100644 --- a/test/payment/ConditionalEscrow.test.js +++ b/test/payment/ConditionalEscrow.test.js @@ -1,6 +1,6 @@ const { shouldBehaveLikeEscrow } = require('./Escrow.behavior'); -const { expectThrow } = require('../helpers/expectThrow'); -const { EVMRevert } = require('../helpers/EVMRevert'); + +const shouldFail = require('../helpers/shouldFail'); const { ether } = require('../helpers/ether'); const BigNumber = web3.BigNumber; @@ -34,7 +34,7 @@ contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) { it('reverts on withdrawals', async function () { await this.escrow.deposit(payee, { from: owner, value: amount }); - await expectThrow(this.escrow.withdraw(payee, { from: owner }), EVMRevert); + await shouldFail.reverting(this.escrow.withdraw(payee, { from: owner })); }); }); }); diff --git a/test/payment/Escrow.behavior.js b/test/payment/Escrow.behavior.js index 9769291e1..c724c5395 100644 --- a/test/payment/Escrow.behavior.js +++ b/test/payment/Escrow.behavior.js @@ -1,6 +1,5 @@ const expectEvent = require('../helpers/expectEvent'); -const { expectThrow } = require('../helpers/expectThrow'); -const { EVMRevert } = require('../helpers/EVMRevert'); +const shouldFail = require('../helpers/shouldFail'); const { ethGetBalance } = require('../helpers/web3'); const { ether } = require('../helpers/ether'); @@ -28,7 +27,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) { }); it('only the primary account can deposit', async function () { - await expectThrow(this.escrow.deposit(payee1, { from: payee2 }), EVMRevert); + await shouldFail.reverting(this.escrow.deposit(payee1, { from: payee2 })); }); it('emits a deposited event', async function () { @@ -80,7 +79,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) { }); it('only the primary account can withdraw', async function () { - await expectThrow(this.escrow.withdraw(payee1, { from: payee1 }), EVMRevert); + await shouldFail.reverting(this.escrow.withdraw(payee1, { from: payee1 })); }); it('emits a withdrawn event', async function () { diff --git a/test/payment/RefundEscrow.test.js b/test/payment/RefundEscrow.test.js index a3d669d69..123da9d82 100644 --- a/test/payment/RefundEscrow.test.js +++ b/test/payment/RefundEscrow.test.js @@ -1,5 +1,4 @@ -const { expectThrow } = require('../helpers/expectThrow'); -const { EVMRevert } = require('../helpers/EVMRevert'); +const shouldFail = require('../helpers/shouldFail'); const expectEvent = require('../helpers/expectEvent'); const { ethGetBalance } = require('../helpers/web3'); const { ether } = require('../helpers/ether'); @@ -18,7 +17,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee const refundees = [refundee1, refundee2]; it('requires a non-null beneficiary', async function () { - await expectThrow( + await shouldFail.reverting( RefundEscrow.new(ZERO_ADDRESS, { from: primary }) ); }); @@ -42,17 +41,17 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee it('does not refund refundees', async function () { await this.escrow.deposit(refundee1, { from: primary, value: amount }); - await expectThrow(this.escrow.withdraw(refundee1), EVMRevert); + await shouldFail.reverting(this.escrow.withdraw(refundee1)); }); it('does not allow beneficiary withdrawal', async function () { await this.escrow.deposit(refundee1, { from: primary, value: amount }); - await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert); + await shouldFail.reverting(this.escrow.beneficiaryWithdraw()); }); }); it('only the primary account can enter closed state', async function () { - await expectThrow(this.escrow.close({ from: beneficiary }), EVMRevert); + await shouldFail.reverting(this.escrow.close({ from: beneficiary })); const { logs } = await this.escrow.close({ from: primary }); expectEvent.inLogs(logs, 'Closed'); @@ -66,11 +65,11 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee }); it('rejects deposits', async function () { - await expectThrow(this.escrow.deposit(refundee1, { from: primary, value: amount }), EVMRevert); + await shouldFail.reverting(this.escrow.deposit(refundee1, { from: primary, value: amount })); }); it('does not refund refundees', async function () { - await expectThrow(this.escrow.withdraw(refundee1), EVMRevert); + await shouldFail.reverting(this.escrow.withdraw(refundee1)); }); it('allows beneficiary withdrawal', async function () { @@ -82,16 +81,16 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee }); it('prevents entering the refund state', async function () { - await expectThrow(this.escrow.enableRefunds({ from: primary }), EVMRevert); + await shouldFail.reverting(this.escrow.enableRefunds({ from: primary })); }); it('prevents re-entering the closed state', async function () { - await expectThrow(this.escrow.close({ from: primary }), EVMRevert); + await shouldFail.reverting(this.escrow.close({ from: primary })); }); }); it('only the primary account can enter refund state', async function () { - await expectThrow(this.escrow.enableRefunds({ from: beneficiary }), EVMRevert); + await shouldFail.reverting(this.escrow.enableRefunds({ from: beneficiary })); const { logs } = await this.escrow.enableRefunds({ from: primary }); expectEvent.inLogs(logs, 'RefundsEnabled'); @@ -105,7 +104,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee }); it('rejects deposits', async function () { - await expectThrow(this.escrow.deposit(refundee1, { from: primary, value: amount }), EVMRevert); + await shouldFail.reverting(this.escrow.deposit(refundee1, { from: primary, value: amount })); }); it('refunds refundees', async function () { @@ -119,15 +118,15 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee }); it('does not allow beneficiary withdrawal', async function () { - await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert); + await shouldFail.reverting(this.escrow.beneficiaryWithdraw()); }); it('prevents entering the closed state', async function () { - await expectThrow(this.escrow.close({ from: primary }), EVMRevert); + await shouldFail.reverting(this.escrow.close({ from: primary })); }); it('prevents re-entering the refund state', async function () { - await expectThrow(this.escrow.enableRefunds({ from: primary }), EVMRevert); + await shouldFail.reverting(this.escrow.enableRefunds({ from: primary })); }); }); }); diff --git a/test/payment/SplitPayment.test.js b/test/payment/SplitPayment.test.js index c4a720fb9..6a10a5131 100644 --- a/test/payment/SplitPayment.test.js +++ b/test/payment/SplitPayment.test.js @@ -9,35 +9,34 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -const { expectThrow } = require('../helpers/expectThrow'); -const { EVMRevert } = require('../helpers/EVMRevert.js'); +const shouldFail = require('../helpers/shouldFail'); const SplitPayment = artifacts.require('SplitPayment'); contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) { const amount = ether(1.0); it('rejects an empty set of payees', async function () { - await expectThrow(SplitPayment.new([], []), EVMRevert); + await shouldFail.reverting(SplitPayment.new([], [])); }); it('rejects more payees than shares', async function () { - await expectThrow(SplitPayment.new([payee1, payee2, payee3], [20, 30]), EVMRevert); + await shouldFail.reverting(SplitPayment.new([payee1, payee2, payee3], [20, 30])); }); it('rejects more shares than payees', async function () { - await expectThrow(SplitPayment.new([payee1, payee2], [20, 30, 40]), EVMRevert); + await shouldFail.reverting(SplitPayment.new([payee1, payee2], [20, 30, 40])); }); it('rejects null payees', async function () { - await expectThrow(SplitPayment.new([payee1, ZERO_ADDRESS], [20, 30]), EVMRevert); + await shouldFail.reverting(SplitPayment.new([payee1, ZERO_ADDRESS], [20, 30])); }); it('rejects zero-valued shares', async function () { - await expectThrow(SplitPayment.new([payee1, payee2], [20, 0]), EVMRevert); + await shouldFail.reverting(SplitPayment.new([payee1, payee2], [20, 0])); }); it('rejects repeated payees', async function () { - await expectThrow(SplitPayment.new([payee1, payee1], [20, 30]), EVMRevert); + await shouldFail.reverting(SplitPayment.new([payee1, payee1], [20, 30])); }); context('once deployed', function () { @@ -74,12 +73,12 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, }); it('should throw if no funds to claim', async function () { - await expectThrow(this.contract.release(payee1), EVMRevert); + await shouldFail.reverting(this.contract.release(payee1)); }); it('should throw if non-payee want to claim', async function () { await sendEther(payer1, this.contract.address, amount); - await expectThrow(this.contract.release(nonpayee1), EVMRevert); + await shouldFail.reverting(this.contract.release(nonpayee1)); }); it('should distribute funds to payees', async function () { diff --git a/test/token/ERC20/ERC20.test.js b/test/token/ERC20/ERC20.test.js index e224de942..d60e9130c 100644 --- a/test/token/ERC20/ERC20.test.js +++ b/test/token/ERC20/ERC20.test.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../../helpers/assertRevert'); +const shouldFail = require('../../helpers/shouldFail'); const expectEvent = require('../../helpers/expectEvent'); const { ZERO_ADDRESS } = require('../../helpers/constants'); @@ -43,7 +43,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const amount = 101; it('reverts', async function () { - await assertRevert(this.token.transfer(to, amount, { from: owner })); + await shouldFail.reverting(this.token.transfer(to, amount, { from: owner })); }); }); @@ -74,7 +74,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const to = ZERO_ADDRESS; it('reverts', async function () { - await assertRevert(this.token.transfer(to, 100, { from: owner })); + await shouldFail.reverting(this.token.transfer(to, 100, { from: owner })); }); }); }); @@ -157,7 +157,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const spender = ZERO_ADDRESS; it('reverts', async function () { - await assertRevert(this.token.approve(spender, amount, { from: owner })); + await shouldFail.reverting(this.token.approve(spender, amount, { from: owner })); }); }); }); @@ -205,7 +205,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const amount = 101; it('reverts', async function () { - await assertRevert(this.token.transferFrom(owner, to, amount, { from: spender })); + await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender })); }); }); }); @@ -219,7 +219,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const amount = 100; it('reverts', async function () { - await assertRevert(this.token.transferFrom(owner, to, amount, { from: spender })); + await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender })); }); }); @@ -227,7 +227,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const amount = 101; it('reverts', async function () { - await assertRevert(this.token.transferFrom(owner, to, amount, { from: spender })); + await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender })); }); }); }); @@ -242,7 +242,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { }); it('reverts', async function () { - await assertRevert(this.token.transferFrom(owner, to, amount, { from: spender })); + await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender })); }); }); }); @@ -254,7 +254,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { function shouldDecreaseApproval (amount) { describe('when there was no approved amount before', function () { it('reverts', async function () { - await assertRevert(this.token.decreaseAllowance(spender, amount, { from: owner })); + await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: owner })); }); }); @@ -287,7 +287,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { }); it('reverts when more than the full allowance is removed', async function () { - await assertRevert(this.token.decreaseAllowance(spender, approvedAmount + 1, { from: owner })); + await shouldFail.reverting(this.token.decreaseAllowance(spender, approvedAmount + 1, { from: owner })); }); }); } @@ -310,7 +310,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const spender = ZERO_ADDRESS; it('reverts', async function () { - await assertRevert(this.token.decreaseAllowance(spender, amount, { from: owner })); + await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: owner })); }); }); }); @@ -392,7 +392,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const spender = ZERO_ADDRESS; it('reverts', async function () { - await assertRevert(this.token.increaseAllowance(spender, amount, { from: owner })); + await shouldFail.reverting(this.token.increaseAllowance(spender, amount, { from: owner })); }); }); }); @@ -402,7 +402,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const amount = new BigNumber(50); it('rejects a null account', async function () { - await assertRevert(this.token.mint(ZERO_ADDRESS, amount)); + await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, amount)); }); describe('for a non null account', function () { @@ -435,12 +435,12 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { const initialSupply = new BigNumber(100); it('rejects a null account', async function () { - await assertRevert(this.token.burn(ZERO_ADDRESS, 1)); + await shouldFail.reverting(this.token.burn(ZERO_ADDRESS, 1)); }); describe('for a non null account', function () { it('rejects burning more than balance', async function () { - await assertRevert(this.token.burn(owner, initialSupply.plus(1))); + await shouldFail.reverting(this.token.burn(owner, initialSupply.plus(1))); }); const describeBurn = function (description, amount) { @@ -487,16 +487,16 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { }); it('rejects a null account', async function () { - await assertRevert(this.token.burnFrom(ZERO_ADDRESS, 1)); + await shouldFail.reverting(this.token.burnFrom(ZERO_ADDRESS, 1)); }); describe('for a non null account', function () { it('rejects burning more than allowance', async function () { - await assertRevert(this.token.burnFrom(owner, allowance.plus(1))); + await shouldFail.reverting(this.token.burnFrom(owner, allowance.plus(1))); }); it('rejects burning more than balance', async function () { - await assertRevert(this.token.burnFrom(owner, initialSupply.plus(1))); + await shouldFail.reverting(this.token.burnFrom(owner, initialSupply.plus(1))); }); const describeBurnFrom = function (description, amount) { diff --git a/test/token/ERC20/ERC20Capped.test.js b/test/token/ERC20/ERC20Capped.test.js index 45558a162..dbb35e23b 100644 --- a/test/token/ERC20/ERC20Capped.test.js +++ b/test/token/ERC20/ERC20Capped.test.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../../helpers/assertRevert'); +const shouldFail = require('../../helpers/shouldFail'); const { ether } = require('../../helpers/ether'); const { shouldBehaveLikeERC20Mintable } = require('./behaviors/ERC20Mintable.behavior'); const { shouldBehaveLikeERC20Capped } = require('./behaviors/ERC20Capped.behavior'); @@ -9,7 +9,7 @@ contract('ERC20Capped', function ([_, minter, ...otherAccounts]) { const cap = ether(1000); it('requires a non-zero cap', async function () { - await assertRevert( + await shouldFail.reverting( ERC20Capped.new(0, { from: minter }) ); }); diff --git a/test/token/ERC20/ERC20Pausable.test.js b/test/token/ERC20/ERC20Pausable.test.js index a524e2442..05a0532ed 100644 --- a/test/token/ERC20/ERC20Pausable.test.js +++ b/test/token/ERC20/ERC20Pausable.test.js @@ -1,5 +1,5 @@ const expectEvent = require('../../helpers/expectEvent'); -const { assertRevert } = require('../../helpers/assertRevert'); +const shouldFail = require('../../helpers/shouldFail'); const ERC20PausableMock = artifacts.require('ERC20PausableMock'); const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior'); @@ -41,7 +41,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA }); it('reverts', async function () { - await assertRevert(this.token.pause({ from })); + await shouldFail.reverting(this.token.pause({ from })); }); }); }); @@ -50,7 +50,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA const from = anotherAccount; it('reverts', async function () { - await assertRevert(this.token.pause({ from })); + await shouldFail.reverting(this.token.pause({ from })); }); }); }); @@ -78,7 +78,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA describe('when the token is unpaused', function () { it('reverts', async function () { - await assertRevert(this.token.unpause({ from })); + await shouldFail.reverting(this.token.unpause({ from })); }); }); }); @@ -87,7 +87,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA const from = anotherAccount; it('reverts', async function () { - await assertRevert(this.token.unpause({ from })); + await shouldFail.reverting(this.token.unpause({ from })); }); }); }); @@ -133,7 +133,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA it('reverts when trying to transfer when paused', async function () { await this.token.pause({ from: pauser }); - await assertRevert(this.token.transfer(recipient, 100, { from: pauser })); + await shouldFail.reverting(this.token.transfer(recipient, 100, { from: pauser })); }); }); @@ -156,7 +156,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA it('reverts when trying to transfer when paused', async function () { await this.token.pause({ from: pauser }); - await assertRevert(this.token.approve(anotherAccount, 40, { from: pauser })); + await shouldFail.reverting(this.token.approve(anotherAccount, 40, { from: pauser })); }); }); @@ -185,7 +185,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA it('reverts when trying to transfer from when paused', async function () { await this.token.pause({ from: pauser }); - await assertRevert(this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount })); + await shouldFail.reverting(this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount })); }); }); @@ -212,7 +212,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA it('reverts when trying to transfer when paused', async function () { await this.token.pause({ from: pauser }); - await assertRevert(this.token.decreaseAllowance(anotherAccount, 40, { from: pauser })); + await shouldFail.reverting(this.token.decreaseAllowance(anotherAccount, 40, { from: pauser })); }); }); @@ -239,7 +239,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA it('reverts when trying to increase approval when paused', async function () { await this.token.pause({ from: pauser }); - await assertRevert(this.token.increaseAllowance(anotherAccount, 40, { from: pauser })); + await shouldFail.reverting(this.token.increaseAllowance(anotherAccount, 40, { from: pauser })); }); }); }); diff --git a/test/token/ERC20/SafeERC20.test.js b/test/token/ERC20/SafeERC20.test.js index 6d61a2037..b6c87554b 100644 --- a/test/token/ERC20/SafeERC20.test.js +++ b/test/token/ERC20/SafeERC20.test.js @@ -1,5 +1,4 @@ -const { expectThrow } = require('../../helpers/expectThrow'); -const { EVMRevert } = require('../../helpers/EVMRevert'); +const shouldFail = require('../../helpers/shouldFail'); require('chai') .should(); @@ -12,15 +11,15 @@ contract('SafeERC20', function () { }); it('should throw on failed transfer', async function () { - await expectThrow(this.helper.doFailingTransfer(), EVMRevert); + await shouldFail.reverting(this.helper.doFailingTransfer()); }); it('should throw on failed transferFrom', async function () { - await expectThrow(this.helper.doFailingTransferFrom(), EVMRevert); + await shouldFail.reverting(this.helper.doFailingTransferFrom()); }); it('should throw on failed approve', async function () { - await expectThrow(this.helper.doFailingApprove(), EVMRevert); + await shouldFail.reverting(this.helper.doFailingApprove()); }); it('should not throw on succeeding transfer', async function () { diff --git a/test/token/ERC20/TokenTimelock.test.js b/test/token/ERC20/TokenTimelock.test.js index 04441fd1e..1816bf902 100644 --- a/test/token/ERC20/TokenTimelock.test.js +++ b/test/token/ERC20/TokenTimelock.test.js @@ -1,5 +1,5 @@ +const shouldFail = require('../../helpers/shouldFail'); const time = require('../../helpers/time'); -const { expectThrow } = require('../../helpers/expectThrow'); const BigNumber = web3.BigNumber; @@ -20,7 +20,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) { it('rejects a release time in the past', async function () { const pastReleaseTime = (await time.latest()) - time.duration.years(1); - await expectThrow( + await shouldFail.reverting( TokenTimelock.new(this.token.address, beneficiary, pastReleaseTime) ); }); @@ -39,12 +39,12 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) { }); it('cannot be released before time limit', async function () { - await expectThrow(this.timelock.release()); + await shouldFail.reverting(this.timelock.release()); }); it('cannot be released just before time limit', async function () { await time.increaseTo(this.releaseTime - time.duration.seconds(3)); - await expectThrow(this.timelock.release()); + await shouldFail.reverting(this.timelock.release()); }); it('can be released just after limit', async function () { @@ -62,7 +62,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) { it('cannot be released twice', async function () { await time.increaseTo(this.releaseTime + time.duration.years(1)); await this.timelock.release(); - await expectThrow(this.timelock.release()); + await shouldFail.reverting(this.timelock.release()); (await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount); }); }); diff --git a/test/token/ERC20/TokenVesting.test.js b/test/token/ERC20/TokenVesting.test.js index acfdb9adc..8fd767be1 100644 --- a/test/token/ERC20/TokenVesting.test.js +++ b/test/token/ERC20/TokenVesting.test.js @@ -1,5 +1,4 @@ -const { expectThrow } = require('../../helpers/expectThrow'); -const { EVMRevert } = require('../../helpers/EVMRevert'); +const shouldFail = require('../../helpers/shouldFail'); const time = require('../../helpers/time'); const { ethGetBlock } = require('../../helpers/web3'); const { ZERO_ADDRESS } = require('../../helpers/constants'); @@ -29,13 +28,13 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { cliffDuration.should.be.gt(duration); - await expectThrow( + await shouldFail.reverting( TokenVesting.new(beneficiary, this.start, cliffDuration, duration, true, { from: owner }) ); }); it('requires a valid beneficiary', async function () { - await expectThrow( + await shouldFail.reverting( TokenVesting.new(ZERO_ADDRESS, this.start, this.cliffDuration, this.duration, true, { from: owner }) ); }); @@ -58,10 +57,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { }); it('cannot be released before cliff', async function () { - await expectThrow( - this.vesting.release(this.token.address), - EVMRevert, - ); + await shouldFail.reverting(this.vesting.release(this.token.address)); }); it('can be released after cliff', async function () { @@ -113,10 +109,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { beneficiary, this.start, this.cliffDuration, this.duration, false, { from: owner } ); - await expectThrow( - vesting.revoke(this.token.address, { from: owner }), - EVMRevert, - ); + await shouldFail.reverting(vesting.revoke(this.token.address, { from: owner })); }); it('should return the non-vested tokens when revoked by owner', async function () { @@ -148,10 +141,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { await this.vesting.revoke(this.token.address, { from: owner }); - await expectThrow( - this.vesting.revoke(this.token.address, { from: owner }), - EVMRevert, - ); + await shouldFail.reverting(this.vesting.revoke(this.token.address, { from: owner })); }); }); }); diff --git a/test/token/ERC20/behaviors/ERC20Burnable.behavior.js b/test/token/ERC20/behaviors/ERC20Burnable.behavior.js index 25af3254c..6e550afcb 100644 --- a/test/token/ERC20/behaviors/ERC20Burnable.behavior.js +++ b/test/token/ERC20/behaviors/ERC20Burnable.behavior.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../../../helpers/assertRevert'); +const shouldFail = require('../../../helpers/shouldFail'); const expectEvent = require('../../../helpers/expectEvent'); const { ZERO_ADDRESS } = require('../../../helpers/constants'); @@ -42,7 +42,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) { const amount = initialBalance + 1; it('reverts', async function () { - await assertRevert(this.token.burn(amount, { from: owner })); + await shouldFail.reverting(this.token.burn(amount, { from: owner })); }); }); }); @@ -88,7 +88,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) { const amount = initialBalance + 1; it('reverts', async function () { await this.token.approve(burner, amount, { from: owner }); - await assertRevert(this.token.burnFrom(owner, amount, { from: burner })); + await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner })); }); }); @@ -96,7 +96,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) { const amount = 100; it('reverts', async function () { await this.token.approve(burner, amount - 1, { from: owner }); - await assertRevert(this.token.burnFrom(owner, amount, { from: burner })); + await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner })); }); }); }); diff --git a/test/token/ERC20/behaviors/ERC20Capped.behavior.js b/test/token/ERC20/behaviors/ERC20Capped.behavior.js index 3c3ab7fbf..e61db5702 100644 --- a/test/token/ERC20/behaviors/ERC20Capped.behavior.js +++ b/test/token/ERC20/behaviors/ERC20Capped.behavior.js @@ -1,4 +1,4 @@ -const { expectThrow } = require('../../../helpers/expectThrow'); +const shouldFail = require('../../../helpers/shouldFail'); const BigNumber = web3.BigNumber; @@ -21,12 +21,12 @@ function shouldBehaveLikeERC20Capped (minter, [anyone], cap) { it('should fail to mint if the ammount exceeds the cap', async function () { await this.token.mint(anyone, cap.sub(1), { from }); - await expectThrow(this.token.mint(anyone, 100, { from })); + await shouldFail.reverting(this.token.mint(anyone, 100, { from })); }); it('should fail to mint after cap is reached', async function () { await this.token.mint(anyone, cap, { from }); - await expectThrow(this.token.mint(anyone, 1, { from })); + await shouldFail.reverting(this.token.mint(anyone, 1, { from })); }); }); } diff --git a/test/token/ERC20/behaviors/ERC20Mintable.behavior.js b/test/token/ERC20/behaviors/ERC20Mintable.behavior.js index f34504afc..bb8c0fe30 100644 --- a/test/token/ERC20/behaviors/ERC20Mintable.behavior.js +++ b/test/token/ERC20/behaviors/ERC20Mintable.behavior.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../../../helpers/assertRevert'); +const shouldFail = require('../../../helpers/shouldFail'); const expectEvent = require('../../../helpers/expectEvent'); const { ZERO_ADDRESS } = require('../../../helpers/constants'); @@ -47,7 +47,7 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) { const from = anyone; it('reverts', async function () { - await assertRevert(this.token.mint(anyone, amount, { from })); + await shouldFail.reverting(this.token.mint(anyone, amount, { from })); }); }); }); diff --git a/test/token/ERC721/ERC721.behavior.js b/test/token/ERC721/ERC721.behavior.js index a18b6b437..aea385a99 100644 --- a/test/token/ERC721/ERC721.behavior.js +++ b/test/token/ERC721/ERC721.behavior.js @@ -1,6 +1,6 @@ const expectEvent = require('../../helpers/expectEvent'); const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior'); -const { assertRevert } = require('../../helpers/assertRevert'); +const shouldFail = require('../../helpers/shouldFail'); const { ZERO_ADDRESS } = require('../../helpers/constants'); const { decodeLogs } = require('../../helpers/decodeLogs'); const { sendTransaction } = require('../../helpers/sendTransaction'); @@ -44,7 +44,7 @@ function shouldBehaveLikeERC721 ( context('when querying the zero address', function () { it('throws', async function () { - await assertRevert(this.token.balanceOf(0)); + await shouldFail.reverting(this.token.balanceOf(0)); }); }); }); @@ -62,7 +62,7 @@ function shouldBehaveLikeERC721 ( const tokenId = unknownTokenId; it('reverts', async function () { - await assertRevert(this.token.ownerOf(tokenId)); + await shouldFail.reverting(this.token.ownerOf(tokenId)); }); }); }); @@ -184,28 +184,28 @@ function shouldBehaveLikeERC721 ( context('when the address of the previous owner is incorrect', function () { it('reverts', async function () { - await assertRevert(transferFunction.call(this, anyone, anyone, tokenId, { from: owner }) + await shouldFail.reverting(transferFunction.call(this, anyone, anyone, tokenId, { from: owner }) ); }); }); context('when the sender is not authorized for the token id', function () { it('reverts', async function () { - await assertRevert(transferFunction.call(this, owner, anyone, tokenId, { from: anyone }) + await shouldFail.reverting(transferFunction.call(this, owner, anyone, tokenId, { from: anyone }) ); }); }); context('when the given token ID does not exist', function () { it('reverts', async function () { - await assertRevert(transferFunction.call(this, owner, anyone, unknownTokenId, { from: owner }) + await shouldFail.reverting(transferFunction.call(this, owner, anyone, unknownTokenId, { from: owner }) ); }); }); context('when the address to transfer the token to is the zero address', function () { it('reverts', async function () { - await assertRevert(transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner })); + await shouldFail.reverting(transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner })); }); }); }; @@ -274,7 +274,7 @@ function shouldBehaveLikeERC721 ( describe('with an invalid token id', function () { it('reverts', async function () { - await assertRevert( + await shouldFail.reverting( transferFun.call( this, owner, @@ -299,21 +299,27 @@ function shouldBehaveLikeERC721 ( describe('to a receiver contract returning unexpected value', function () { it('reverts', async function () { const invalidReceiver = await ERC721ReceiverMock.new('0x42', false); - await assertRevert(this.token.safeTransferFrom(owner, invalidReceiver.address, tokenId, { from: owner })); + await shouldFail.reverting( + this.token.safeTransferFrom(owner, invalidReceiver.address, tokenId, { from: owner }) + ); }); }); describe('to a receiver contract that throws', function () { it('reverts', async function () { const invalidReceiver = await ERC721ReceiverMock.new(RECEIVER_MAGIC_VALUE, true); - await assertRevert(this.token.safeTransferFrom(owner, invalidReceiver.address, tokenId, { from: owner })); + await shouldFail.reverting( + this.token.safeTransferFrom(owner, invalidReceiver.address, tokenId, { from: owner }) + ); }); }); describe('to a contract that does not implement the required function', function () { it('reverts', async function () { const invalidReceiver = this.token; - await assertRevert(this.token.safeTransferFrom(owner, invalidReceiver.address, tokenId, { from: owner })); + await shouldFail.reverting( + this.token.safeTransferFrom(owner, invalidReceiver.address, tokenId, { from: owner }) + ); }); }); }); @@ -400,7 +406,7 @@ function shouldBehaveLikeERC721 ( context('when the address that receives the approval is the owner', function () { it('reverts', async function () { - await assertRevert( + await shouldFail.reverting( this.token.approve(owner, tokenId, { from: owner }) ); }); @@ -408,14 +414,14 @@ function shouldBehaveLikeERC721 ( context('when the sender does not own the given token ID', function () { it('reverts', async function () { - await assertRevert(this.token.approve(approved, tokenId, { from: anyone })); + await shouldFail.reverting(this.token.approve(approved, tokenId, { from: anyone })); }); }); context('when the sender is approved for the given token ID', function () { it('reverts', async function () { await this.token.approve(approved, tokenId, { from: owner }); - await assertRevert(this.token.approve(anotherApproved, tokenId, { from: approved })); + await shouldFail.reverting(this.token.approve(anotherApproved, tokenId, { from: approved })); }); }); @@ -431,7 +437,7 @@ function shouldBehaveLikeERC721 ( context('when the given token ID does not exist', function () { it('reverts', async function () { - await assertRevert(this.token.approve(approved, unknownTokenId, { from: operator })); + await shouldFail.reverting(this.token.approve(approved, unknownTokenId, { from: operator })); }); }); }); @@ -509,7 +515,7 @@ function shouldBehaveLikeERC721 ( context('when the operator is the owner', function () { it('reverts', async function () { - await assertRevert(this.token.setApprovalForAll(owner, true, { from: owner })); + await shouldFail.reverting(this.token.setApprovalForAll(owner, true, { from: owner })); }); }); }); diff --git a/test/token/ERC721/ERC721Full.test.js b/test/token/ERC721/ERC721Full.test.js index 30e4547c8..6789ca28a 100644 --- a/test/token/ERC721/ERC721Full.test.js +++ b/test/token/ERC721/ERC721Full.test.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../../helpers/assertRevert'); +const shouldFail = require('../../helpers/shouldFail'); const { shouldBehaveLikeERC721 } = require('./ERC721.behavior'); const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior'); @@ -69,13 +69,13 @@ contract('ERC721Full', function ([ it('burns all tokens', async function () { await this.token.burn(secondTokenId, { from: owner }); (await this.token.totalSupply()).toNumber().should.be.equal(0); - await assertRevert(this.token.tokenByIndex(0)); + await shouldFail.reverting(this.token.tokenByIndex(0)); }); }); describe('removeTokenFrom', function () { it('reverts if the correct owner is not passed', async function () { - await assertRevert( + await shouldFail.reverting( this.token.removeTokenFrom(anyone, firstTokenId, { from: owner }) ); }); @@ -86,7 +86,7 @@ contract('ERC721Full', function ([ }); it('has been removed', async function () { - await assertRevert(this.token.tokenOfOwnerByIndex(owner, 1)); + await shouldFail.reverting(this.token.tokenOfOwnerByIndex(owner, 1)); }); it('adjusts token list', async function () { @@ -120,7 +120,7 @@ contract('ERC721Full', function ([ }); it('reverts when setting metadata for non existent token id', async function () { - await assertRevert(this.token.setTokenURI(nonExistentTokenId, sampleUri)); + await shouldFail.reverting(this.token.setTokenURI(nonExistentTokenId, sampleUri)); }); it('can burn token with metadata', async function () { @@ -134,7 +134,7 @@ contract('ERC721Full', function ([ }); it('reverts when querying metadata for non existent token id', async function () { - await assertRevert(this.token.tokenURI(nonExistentTokenId)); + await shouldFail.reverting(this.token.tokenURI(nonExistentTokenId)); }); }); @@ -153,13 +153,13 @@ contract('ERC721Full', function ([ describe('when the index is greater than or equal to the total tokens owned by the given address', function () { it('reverts', async function () { - await assertRevert(this.token.tokenOfOwnerByIndex(owner, 2)); + await shouldFail.reverting(this.token.tokenOfOwnerByIndex(owner, 2)); }); }); describe('when the given address does not own any token', function () { it('reverts', async function () { - await assertRevert(this.token.tokenOfOwnerByIndex(another, 0)); + await shouldFail.reverting(this.token.tokenOfOwnerByIndex(another, 0)); }); }); @@ -179,7 +179,7 @@ contract('ERC721Full', function ([ it('returns empty collection for original owner', async function () { (await this.token.balanceOf(owner)).toNumber().should.be.equal(0); - await assertRevert(this.token.tokenOfOwnerByIndex(owner, 0)); + await shouldFail.reverting(this.token.tokenOfOwnerByIndex(owner, 0)); }); }); }); @@ -193,7 +193,7 @@ contract('ERC721Full', function ([ }); it('should revert if index is greater than supply', async function () { - await assertRevert(this.token.tokenByIndex(2)); + await shouldFail.reverting(this.token.tokenByIndex(2)); }); [firstTokenId, secondTokenId].forEach(function (tokenId) { diff --git a/test/token/ERC721/ERC721MintBurn.behavior.js b/test/token/ERC721/ERC721MintBurn.behavior.js index a5141abca..1bb7d1bc7 100644 --- a/test/token/ERC721/ERC721MintBurn.behavior.js +++ b/test/token/ERC721/ERC721MintBurn.behavior.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../../helpers/assertRevert'); +const shouldFail = require('../../helpers/shouldFail'); const expectEvent = require('../../helpers/expectEvent'); const { ZERO_ADDRESS } = require('../../helpers/constants'); const BigNumber = web3.BigNumber; @@ -52,13 +52,13 @@ function shouldBehaveLikeMintAndBurnERC721 ( describe('when the given owner address is the zero address', function () { it('reverts', async function () { - await assertRevert(this.token.mint(ZERO_ADDRESS, thirdTokenId, { from: minter })); + await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, thirdTokenId, { from: minter })); }); }); describe('when the given token ID was already tracked by this contract', function () { it('reverts', async function () { - await assertRevert(this.token.mint(owner, firstTokenId, { from: minter })); + await shouldFail.reverting(this.token.mint(owner, firstTokenId, { from: minter })); }); }); }); @@ -82,7 +82,7 @@ function shouldBehaveLikeMintAndBurnERC721 ( }); it('burns the given token ID and adjusts the balance of the owner', async function () { - await assertRevert(this.token.ownerOf(tokenId)); + await shouldFail.reverting(this.token.ownerOf(tokenId)); (await this.token.balanceOf(owner)).should.be.bignumber.equal(1); }); @@ -104,14 +104,14 @@ function shouldBehaveLikeMintAndBurnERC721 ( context('getApproved', function () { it('reverts', async function () { - await assertRevert(this.token.getApproved(tokenId)); + await shouldFail.reverting(this.token.getApproved(tokenId)); }); }); }); describe('when the given token ID was not tracked by this contract', function () { it('reverts', async function () { - await assertRevert( + await shouldFail.reverting( this.token.burn(unknownTokenId, { from: creator }) ); }); diff --git a/test/token/ERC721/ERC721PausedToken.behavior.js b/test/token/ERC721/ERC721PausedToken.behavior.js index a7196d837..1d83608fa 100644 --- a/test/token/ERC721/ERC721PausedToken.behavior.js +++ b/test/token/ERC721/ERC721PausedToken.behavior.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../../helpers/assertRevert'); +const shouldFail = require('../../helpers/shouldFail'); const { sendTransaction } = require('../../helpers/sendTransaction'); const { ZERO_ADDRESS } = require('../../helpers/constants'); @@ -19,23 +19,23 @@ function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) { }); it('reverts when trying to approve', async function () { - await assertRevert(this.token.approve(recipient, firstTokenId, { from: owner })); + await shouldFail.reverting(this.token.approve(recipient, firstTokenId, { from: owner })); }); it('reverts when trying to setApprovalForAll', async function () { - await assertRevert(this.token.setApprovalForAll(operator, true, { from: owner })); + await shouldFail.reverting(this.token.setApprovalForAll(operator, true, { from: owner })); }); it('reverts when trying to transferFrom', async function () { - await assertRevert(this.token.transferFrom(owner, recipient, firstTokenId, { from: owner })); + await shouldFail.reverting(this.token.transferFrom(owner, recipient, firstTokenId, { from: owner })); }); it('reverts when trying to safeTransferFrom', async function () { - await assertRevert(this.token.safeTransferFrom(owner, recipient, firstTokenId, { from: owner })); + await shouldFail.reverting(this.token.safeTransferFrom(owner, recipient, firstTokenId, { from: owner })); }); it('reverts when trying to safeTransferFrom with data', async function () { - await assertRevert( + await shouldFail.reverting( sendTransaction( this.token, 'safeTransferFrom', diff --git a/test/utils/ReentrancyGuard.test.js b/test/utils/ReentrancyGuard.test.js index 3952b2fcb..16706fe8e 100644 --- a/test/utils/ReentrancyGuard.test.js +++ b/test/utils/ReentrancyGuard.test.js @@ -1,4 +1,4 @@ -const { expectThrow } = require('../helpers/expectThrow'); +const shouldFail = require('../helpers/shouldFail'); const ReentrancyMock = artifacts.require('ReentrancyMock'); const ReentrancyAttack = artifacts.require('ReentrancyAttack'); @@ -16,7 +16,7 @@ contract('ReentrancyGuard', function () { it('should not allow remote callback', async function () { const attacker = await ReentrancyAttack.new(); - await expectThrow(this.reentrancyMock.countAndCall(attacker.address)); + await shouldFail.reverting(this.reentrancyMock.countAndCall(attacker.address)); }); // The following are more side-effects than intended behavior: @@ -24,10 +24,10 @@ contract('ReentrancyGuard', function () { // in the side-effects. it('should not allow local recursion', async function () { - await expectThrow(this.reentrancyMock.countLocalRecursive(10)); + await shouldFail.reverting(this.reentrancyMock.countLocalRecursive(10)); }); it('should not allow indirect local recursion', async function () { - await expectThrow(this.reentrancyMock.countThisRecursive(10)); + await shouldFail.reverting(this.reentrancyMock.countThisRecursive(10)); }); });