Replace revert strings with custom errors (#4261)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
const { constants, expectEvent, expectRevert, time } = require('@openzeppelin/test-helpers');
|
||||
const { constants, expectEvent, time } = require('@openzeppelin/test-helpers');
|
||||
|
||||
const { MAX_UINT256, ZERO_ADDRESS } = constants;
|
||||
|
||||
@ -9,6 +9,7 @@ const Wallet = require('ethereumjs-wallet').default;
|
||||
const { shouldBehaveLikeEIP6372 } = require('./EIP6372.behavior');
|
||||
const { getDomain, domainType } = require('../../helpers/eip712');
|
||||
const { clockFromReceipt } = require('../../helpers/time');
|
||||
const { expectRevertCustomError } = require('../../helpers/customError');
|
||||
|
||||
const Delegation = [
|
||||
{ name: 'delegatee', type: 'address' },
|
||||
@ -176,7 +177,11 @@ function shouldBehaveLikeVotes(accounts, tokens, { mode = 'blocknumber', fungibl
|
||||
|
||||
await this.votes.delegateBySig(delegatee, nonce, MAX_UINT256, v, r, s);
|
||||
|
||||
await expectRevert(this.votes.delegateBySig(delegatee, nonce, MAX_UINT256, v, r, s), 'Votes: invalid nonce');
|
||||
await expectRevertCustomError(
|
||||
this.votes.delegateBySig(delegatee, nonce, MAX_UINT256, v, r, s),
|
||||
'InvalidAccountNonce',
|
||||
[delegator.address, nonce + 1],
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects bad delegatee', async function () {
|
||||
@ -208,9 +213,10 @@ function shouldBehaveLikeVotes(accounts, tokens, { mode = 'blocknumber', fungibl
|
||||
delegator.getPrivateKey(),
|
||||
);
|
||||
|
||||
await expectRevert(
|
||||
await expectRevertCustomError(
|
||||
this.votes.delegateBySig(delegatee, nonce + 1, MAX_UINT256, v, r, s),
|
||||
'Votes: invalid nonce',
|
||||
'InvalidAccountNonce',
|
||||
[delegator.address, 0],
|
||||
);
|
||||
});
|
||||
|
||||
@ -226,7 +232,11 @@ function shouldBehaveLikeVotes(accounts, tokens, { mode = 'blocknumber', fungibl
|
||||
delegator.getPrivateKey(),
|
||||
);
|
||||
|
||||
await expectRevert(this.votes.delegateBySig(delegatee, nonce, expiry, v, r, s), 'Votes: signature expired');
|
||||
await expectRevertCustomError(
|
||||
this.votes.delegateBySig(delegatee, nonce, expiry, v, r, s),
|
||||
'VotesExpiredSignature',
|
||||
[expiry],
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -237,7 +247,12 @@ function shouldBehaveLikeVotes(accounts, tokens, { mode = 'blocknumber', fungibl
|
||||
});
|
||||
|
||||
it('reverts if block number >= current block', async function () {
|
||||
await expectRevert(this.votes.getPastTotalSupply(5e10), 'future lookup');
|
||||
const timepoint = 5e10;
|
||||
const clock = await this.votes.clock();
|
||||
await expectRevertCustomError(this.votes.getPastTotalSupply(timepoint), 'ERC5805FutureLookup', [
|
||||
timepoint,
|
||||
clock,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 0 if there are no checkpoints', async function () {
|
||||
@ -285,7 +300,10 @@ function shouldBehaveLikeVotes(accounts, tokens, { mode = 'blocknumber', fungibl
|
||||
expect(await this.votes.getPastTotalSupply(t4.timepoint)).to.be.bignumber.equal(weight[2]);
|
||||
expect(await this.votes.getPastTotalSupply(t4.timepoint + 1)).to.be.bignumber.equal(weight[2]);
|
||||
expect(await this.votes.getPastTotalSupply(t5.timepoint)).to.be.bignumber.equal('0');
|
||||
await expectRevert(this.votes.getPastTotalSupply(t5.timepoint + 1), 'Votes: future lookup');
|
||||
await expectRevertCustomError(this.votes.getPastTotalSupply(t5.timepoint + 1), 'ERC5805FutureLookup', [
|
||||
t5.timepoint + 1, // timepoint
|
||||
t5.timepoint + 1, // clock
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -300,7 +318,12 @@ function shouldBehaveLikeVotes(accounts, tokens, { mode = 'blocknumber', fungibl
|
||||
|
||||
describe('getPastVotes', function () {
|
||||
it('reverts if block number >= current block', async function () {
|
||||
await expectRevert(this.votes.getPastVotes(accounts[2], 5e10), 'future lookup');
|
||||
const clock = await this.votes.clock();
|
||||
const timepoint = 5e10; // far in the future
|
||||
await expectRevertCustomError(this.votes.getPastVotes(accounts[2], timepoint), 'ERC5805FutureLookup', [
|
||||
timepoint,
|
||||
clock,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 0 if there are no checkpoints', async function () {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
const { constants, expectRevert } = require('@openzeppelin/test-helpers');
|
||||
const { constants } = require('@openzeppelin/test-helpers');
|
||||
const { expect } = require('chai');
|
||||
const { clockFromReceipt } = require('../../helpers/time');
|
||||
const { BNsum } = require('../../helpers/math');
|
||||
const { expectRevertCustomError } = require('../../helpers/customError');
|
||||
|
||||
require('array.prototype.at/auto');
|
||||
|
||||
@ -45,7 +46,11 @@ contract('Votes', function (accounts) {
|
||||
|
||||
it('reverts if block number >= current block', async function () {
|
||||
const lastTxTimepoint = await clockFromReceipt[mode](this.txs.at(-1).receipt);
|
||||
await expectRevert(this.votes.getPastTotalSupply(lastTxTimepoint + 1), 'Votes: future lookup');
|
||||
const clock = await this.votes.clock();
|
||||
await expectRevertCustomError(this.votes.getPastTotalSupply(lastTxTimepoint + 1), 'ERC5805FutureLookup', [
|
||||
lastTxTimepoint + 1,
|
||||
clock,
|
||||
]);
|
||||
});
|
||||
|
||||
it('delegates', async function () {
|
||||
|
||||
Reference in New Issue
Block a user