Replace error strings with custom errors (#4261)

This commit is contained in:
Francisco Giordano
2023-06-06 01:08:31 -03:00
parent 253bfa68c2
commit 99a4cfca17
133 changed files with 3157 additions and 1204 deletions

View File

@ -1,7 +1,9 @@
const { expectRevert } = require('@openzeppelin/test-helpers');
require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { VALUE_SIZES } = require('../../../scripts/generate/templates/Checkpoints.opts.js');
const { expectRevertCustomError } = require('../../helpers/customError.js');
const $Checkpoints = artifacts.require('$Checkpoints');
@ -77,7 +79,11 @@ contract('Checkpoints', function () {
});
it('cannot push values in the past', async function () {
await expectRevert(this.methods.push(last(this.checkpoints).key - 1, '0'), 'Checkpoint: decreasing keys');
await expectRevertCustomError(
this.methods.push(last(this.checkpoints).key - 1, '0'),
'CheckpointUnorderedInsertion',
[],
);
});
it('can update last value', async function () {

View File

@ -30,10 +30,10 @@ contract('DoubleEndedQueue', function () {
});
it('reverts on accesses', async function () {
await expectRevertCustomError(this.deque.$popBack(0), 'Empty()');
await expectRevertCustomError(this.deque.$popFront(0), 'Empty()');
await expectRevertCustomError(this.deque.$back(0), 'Empty()');
await expectRevertCustomError(this.deque.$front(0), 'Empty()');
await expectRevertCustomError(this.deque.$popBack(0), 'Empty', []);
await expectRevertCustomError(this.deque.$popFront(0), 'Empty', []);
await expectRevertCustomError(this.deque.$back(0), 'Empty', []);
await expectRevertCustomError(this.deque.$front(0), 'Empty', []);
});
});
@ -54,7 +54,7 @@ contract('DoubleEndedQueue', function () {
});
it('out of bounds access', async function () {
await expectRevertCustomError(this.deque.$at(0, this.content.length), 'OutOfBounds()');
await expectRevertCustomError(this.deque.$at(0, this.content.length), 'OutOfBounds', []);
});
describe('push', function () {

View File

@ -1,7 +1,8 @@
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const zip = require('lodash.zip');
const { expectRevertCustomError } = require('../../helpers/customError');
function shouldBehaveLikeMap(keys, values, zeroValue, methods, events) {
const [keyA, keyB, keyC] = keys;
@ -150,7 +151,10 @@ function shouldBehaveLikeMap(keys, values, zeroValue, methods, events) {
expect(await methods.get(this.map, keyA).then(r => r.toString())).to.be.equal(valueA.toString());
});
it('missing value', async function () {
await expectRevert(methods.get(this.map, keyB), 'EnumerableMap: nonexistent key');
const key = web3.utils.toHex(keyB);
await expectRevertCustomError(methods.get(this.map, keyB), 'EnumerableMapNonexistentKey', [
key.length == 66 ? key : web3.utils.padLeft(key, 64, '0'),
]);
});
});