Replaced assertJump, assertRevert and expectThrow with shouldFail. (#1363)

* Replaced assertJump, assertRevert and expectThrow with shouldFail.

* Fixed linter errors.

* Fixed typo.

* Made the helpers async.

(cherry picked from commit b0da0fded0)
This commit is contained in:
Nicolás Venturo
2018-10-09 16:23:55 -03:00
committed by Leo Arias
parent 620d524398
commit 7cd0d5a452
45 changed files with 274 additions and 344 deletions

View File

@ -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));
});
});
});

View File

@ -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 })
);
});