Update test-helpers to v0.4.0. (#1770)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
const { shouldFail } = require('openzeppelin-test-helpers');
|
||||
const { expectRevert } = require('openzeppelin-test-helpers');
|
||||
|
||||
const CountersImpl = artifacts.require('CountersImpl');
|
||||
|
||||
@ -39,7 +39,7 @@ contract('Counters', function () {
|
||||
|
||||
it('reverts if the current value is 0', async function () {
|
||||
await this.counter.decrement();
|
||||
await shouldFail.reverting.withMessage(this.counter.decrement(), 'SafeMath: subtraction overflow');
|
||||
await expectRevert(this.counter.decrement(), 'SafeMath: subtraction overflow');
|
||||
});
|
||||
|
||||
it('can be called multiple times', async function () {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
|
||||
const { BN, constants, expectRevert } = require('openzeppelin-test-helpers');
|
||||
const { ZERO_ADDRESS } = constants;
|
||||
|
||||
const ERC20Mock = artifacts.require('ERC20Mock');
|
||||
@ -9,7 +9,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
|
||||
const totalSupply = new BN('200');
|
||||
|
||||
it('reverts with a null legacy token address', async function () {
|
||||
await shouldFail.reverting.withMessage(ERC20Migrator.new(ZERO_ADDRESS),
|
||||
await expectRevert(ERC20Migrator.new(ZERO_ADDRESS),
|
||||
'ERC20Migrator: legacy token is the zero address'
|
||||
);
|
||||
});
|
||||
@ -27,13 +27,13 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
|
||||
|
||||
describe('beginMigration', function () {
|
||||
it('reverts with a null new token address', async function () {
|
||||
await shouldFail.reverting.withMessage(this.migrator.beginMigration(ZERO_ADDRESS),
|
||||
await expectRevert(this.migrator.beginMigration(ZERO_ADDRESS),
|
||||
'ERC20Migrator: new token is the zero address'
|
||||
);
|
||||
});
|
||||
|
||||
it('reverts if not a minter of the token', async function () {
|
||||
await shouldFail.reverting.withMessage(this.migrator.beginMigration(this.newToken.address),
|
||||
await expectRevert(this.migrator.beginMigration(this.newToken.address),
|
||||
'ERC20Migrator: not a minter for new token'
|
||||
);
|
||||
});
|
||||
@ -46,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 shouldFail.reverting.withMessage(this.migrator.beginMigration(this.newToken.address),
|
||||
await expectRevert(this.migrator.beginMigration(this.newToken.address),
|
||||
'ERC20Migrator: migration already started'
|
||||
);
|
||||
});
|
||||
@ -66,7 +66,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
|
||||
});
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting.withMessage(this.migrator.migrateAll(owner),
|
||||
await expectRevert(this.migrator.migrateAll(owner),
|
||||
'ERC20Migrator: migration not started'
|
||||
);
|
||||
});
|
||||
@ -82,7 +82,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
|
||||
});
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting.withMessage(this.migrator.migrate(owner, amount),
|
||||
await expectRevert(this.migrator.migrate(owner, amount),
|
||||
'ERC20Migrator: migration not started'
|
||||
);
|
||||
});
|
||||
@ -186,7 +186,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
|
||||
const amount = baseAmount.addn(1);
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting.withMessage(this.migrator.migrate(owner, amount),
|
||||
await expectRevert(this.migrator.migrate(owner, amount),
|
||||
'SafeERC20: low-level call failed'
|
||||
);
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { BN, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
|
||||
const { BN, expectEvent, expectRevert } = require('openzeppelin-test-helpers');
|
||||
const ERC20SnapshotMock = artifacts.require('ERC20SnapshotMock');
|
||||
|
||||
contract('ERC20Snapshot', function ([_, initialHolder, recipient, other]) {
|
||||
@ -24,11 +24,11 @@ contract('ERC20Snapshot', function ([_, initialHolder, recipient, other]) {
|
||||
|
||||
describe('totalSupplyAt', function () {
|
||||
it('reverts with a snapshot id of 0', async function () {
|
||||
await shouldFail.reverting.withMessage(this.token.totalSupplyAt(0), 'ERC20Snapshot: id is 0');
|
||||
await expectRevert(this.token.totalSupplyAt(0), 'ERC20Snapshot: id is 0');
|
||||
});
|
||||
|
||||
it('reverts with a not-yet-created snapshot id', async function () {
|
||||
await shouldFail.reverting.withMessage(this.token.totalSupplyAt(1), 'ERC20Snapshot: nonexistent id');
|
||||
await expectRevert(this.token.totalSupplyAt(1), 'ERC20Snapshot: nonexistent id');
|
||||
});
|
||||
|
||||
context('with initial snapshot', function () {
|
||||
@ -98,11 +98,11 @@ contract('ERC20Snapshot', function ([_, initialHolder, recipient, other]) {
|
||||
|
||||
describe('balanceOfAt', function () {
|
||||
it('reverts with a snapshot id of 0', async function () {
|
||||
await shouldFail.reverting.withMessage(this.token.balanceOfAt(other, 0), 'ERC20Snapshot: id is 0');
|
||||
await expectRevert(this.token.balanceOfAt(other, 0), 'ERC20Snapshot: id is 0');
|
||||
});
|
||||
|
||||
it('reverts with a not-yet-created snapshot id', async function () {
|
||||
await shouldFail.reverting.withMessage(this.token.balanceOfAt(other, 1), 'ERC20Snapshot: nonexistent id');
|
||||
await expectRevert(this.token.balanceOfAt(other, 1), 'ERC20Snapshot: nonexistent id');
|
||||
});
|
||||
|
||||
context('with initial snapshot', function () {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { shouldFail } = require('openzeppelin-test-helpers');
|
||||
const { expectRevert } = require('openzeppelin-test-helpers');
|
||||
const { getSignFor } = require('../helpers/sign');
|
||||
const { shouldBehaveLikePublicRole } = require('../behaviors/access/roles/PublicRole.behavior');
|
||||
|
||||
@ -30,21 +30,21 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, other, authorize
|
||||
});
|
||||
|
||||
it('does not allow invalid signature for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignature(INVALID_SIGNATURE, { from: authorizedUser }),
|
||||
'SignatureBouncer: invalid signature for caller'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not allow valid signature for other sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser), { from: other }),
|
||||
'SignatureBouncer: invalid signature for caller'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not allow valid signature for method for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser, 'onlyWithValidSignature'),
|
||||
{ from: authorizedUser }), 'SignatureBouncer: invalid signature for caller'
|
||||
);
|
||||
@ -59,14 +59,14 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, other, authorize
|
||||
});
|
||||
|
||||
it('does not allow invalid signature with correct method for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndMethod(INVALID_SIGNATURE, { from: authorizedUser }),
|
||||
'SignatureBouncer: invalid signature for caller and method'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not allow valid signature with correct method for other sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndMethod(
|
||||
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: other }
|
||||
),
|
||||
@ -75,14 +75,14 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, other, authorize
|
||||
});
|
||||
|
||||
it('does not allow valid method signature with incorrect method for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndMethod(await this.signFor(authorizedUser, 'theWrongMethod'),
|
||||
{ from: authorizedUser }), 'SignatureBouncer: invalid signature for caller and method'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not allow valid non-method signature method for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndMethod(await this.signFor(authorizedUser), { from: authorizedUser }),
|
||||
'SignatureBouncer: invalid signature for caller and method'
|
||||
);
|
||||
@ -97,14 +97,14 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, other, authorize
|
||||
});
|
||||
|
||||
it('does not allow invalid signature with correct method and data for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE, INVALID_SIGNATURE, { from: authorizedUser }),
|
||||
'SignatureBouncer: invalid signature for caller and data'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not allow valid signature with correct method and incorrect data for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE + 10,
|
||||
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
|
||||
{ from: authorizedUser }
|
||||
@ -113,7 +113,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, other, authorize
|
||||
});
|
||||
|
||||
it('does not allow valid signature with correct method and data for other sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
|
||||
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
|
||||
{ from: other }
|
||||
@ -122,7 +122,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, other, authorize
|
||||
});
|
||||
|
||||
it('does not allow valid non-method signature for sender', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
|
||||
await this.signFor(authorizedUser), { from: authorizedUser }
|
||||
), 'SignatureBouncer: invalid signature for caller and data'
|
||||
@ -130,7 +130,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, other, authorize
|
||||
});
|
||||
|
||||
it('does not allow msg.data shorter than SIGNATURE_SIZE', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
this.sigBouncer.tooShortMsgData({ from: authorizedUser }), 'SignatureBouncer: data is too short'
|
||||
);
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
|
||||
const { BN, constants, expectRevert } = require('openzeppelin-test-helpers');
|
||||
const { MAX_INT256, MIN_INT256 } = constants;
|
||||
|
||||
const SignedSafeMathMock = artifacts.require('SignedSafeMathMock');
|
||||
@ -14,8 +14,8 @@ contract('SignedSafeMath', function () {
|
||||
}
|
||||
|
||||
async function testFailsCommutative (fn, lhs, rhs, reason) {
|
||||
await shouldFail.reverting.withMessage(fn(lhs, rhs), reason);
|
||||
await shouldFail.reverting.withMessage(fn(rhs, lhs), reason);
|
||||
await expectRevert(fn(lhs, rhs), reason);
|
||||
await expectRevert(fn(rhs, lhs), reason);
|
||||
}
|
||||
|
||||
describe('add', function () {
|
||||
@ -69,14 +69,14 @@ contract('SignedSafeMath', function () {
|
||||
const a = MAX_INT256;
|
||||
const b = new BN('-1');
|
||||
|
||||
await shouldFail.reverting.withMessage(this.safeMath.sub(a, b), 'SignedSafeMath: subtraction overflow');
|
||||
await expectRevert(this.safeMath.sub(a, b), 'SignedSafeMath: subtraction overflow');
|
||||
});
|
||||
|
||||
it('reverts on negative subtraction overflow', async function () {
|
||||
const a = MIN_INT256;
|
||||
const b = new BN('1');
|
||||
|
||||
await shouldFail.reverting.withMessage(this.safeMath.sub(a, b), 'SignedSafeMath: subtraction overflow');
|
||||
await expectRevert(this.safeMath.sub(a, b), 'SignedSafeMath: subtraction overflow');
|
||||
});
|
||||
});
|
||||
|
||||
@ -137,14 +137,14 @@ contract('SignedSafeMath', function () {
|
||||
const a = new BN('-5678');
|
||||
const b = new BN('0');
|
||||
|
||||
await shouldFail.reverting.withMessage(this.safeMath.div(a, b), 'SignedSafeMath: division by zero');
|
||||
await expectRevert(this.safeMath.div(a, b), 'SignedSafeMath: division by zero');
|
||||
});
|
||||
|
||||
it('reverts on overflow, negative second', async function () {
|
||||
const a = new BN(MIN_INT256);
|
||||
const b = new BN('-1');
|
||||
|
||||
await shouldFail.reverting.withMessage(this.safeMath.div(a, b), 'SignedSafeMath: division overflow');
|
||||
await expectRevert(this.safeMath.div(a, b), 'SignedSafeMath: division overflow');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { BN, constants, expectEvent, shouldFail, time } = require('openzeppelin-test-helpers');
|
||||
const { BN, constants, expectEvent, expectRevert, time } = require('openzeppelin-test-helpers');
|
||||
const { ZERO_ADDRESS } = constants;
|
||||
|
||||
const ERC20Mintable = artifacts.require('ERC20Mintable');
|
||||
@ -20,14 +20,14 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
|
||||
cliffDuration.should.be.bignumber.that.is.at.least(duration);
|
||||
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
TokenVesting.new(beneficiary, this.start, cliffDuration, duration, true, { from: owner }),
|
||||
'TokenVesting: cliff is longer than duration'
|
||||
);
|
||||
});
|
||||
|
||||
it('reverts with a null beneficiary', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
TokenVesting.new(ZERO_ADDRESS, this.start, this.cliffDuration, this.duration, true, { from: owner }),
|
||||
'TokenVesting: beneficiary is the zero address'
|
||||
);
|
||||
@ -35,7 +35,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
|
||||
it('reverts with a null duration', async function () {
|
||||
// cliffDuration should also be 0, since the duration must be larger than the cliff
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
TokenVesting.new(beneficiary, this.start, 0, 0, true, { from: owner }), 'TokenVesting: duration is 0'
|
||||
);
|
||||
});
|
||||
@ -44,7 +44,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
const now = await time.latest();
|
||||
|
||||
this.start = now.sub(this.duration).sub(time.duration.minutes(1));
|
||||
await shouldFail.reverting.withMessage(
|
||||
await expectRevert(
|
||||
TokenVesting.new(beneficiary, this.start, this.cliffDuration, this.duration, true, { from: owner }),
|
||||
'TokenVesting: final time is before current time'
|
||||
);
|
||||
@ -68,7 +68,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
});
|
||||
|
||||
it('cannot be released before cliff', async function () {
|
||||
await shouldFail.reverting.withMessage(this.vesting.release(this.token.address),
|
||||
await expectRevert(this.vesting.release(this.token.address),
|
||||
'TokenVesting: no tokens are due'
|
||||
);
|
||||
});
|
||||
@ -126,7 +126,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
beneficiary, this.start, this.cliffDuration, this.duration, false, { from: owner }
|
||||
);
|
||||
|
||||
await shouldFail.reverting.withMessage(vesting.revoke(this.token.address, { from: owner }),
|
||||
await expectRevert(vesting.revoke(this.token.address, { from: owner }),
|
||||
'TokenVesting: cannot revoke'
|
||||
);
|
||||
});
|
||||
@ -155,7 +155,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
|
||||
it('should fail to be revoked a second time', async function () {
|
||||
await this.vesting.revoke(this.token.address, { from: owner });
|
||||
await shouldFail.reverting.withMessage(this.vesting.revoke(this.token.address, { from: owner }),
|
||||
await expectRevert(this.vesting.revoke(this.token.address, { from: owner }),
|
||||
'TokenVesting: token already revoked'
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user