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:
Ernesto García
2023-06-12 17:41:52 -06:00
committed by GitHub
parent 08fd777f6d
commit b425a72240
138 changed files with 3220 additions and 1287 deletions

View File

@ -1,6 +1,8 @@
const { expectRevert } = require('@openzeppelin/test-helpers');
const { getSlot, BeaconSlot } = require('../../helpers/erc1967');
const { expectRevertCustomError } = require('../../helpers/customError');
const { expect } = require('chai');
const UpgradeableBeacon = artifacts.require('UpgradeableBeacon');
@ -15,7 +17,7 @@ contract('BeaconProxy', function (accounts) {
describe('bad beacon is not accepted', async function () {
it('non-contract beacon', async function () {
await expectRevert(BeaconProxy.new(anotherAccount, '0x'), 'ERC1967: new beacon is not a contract');
await expectRevertCustomError(BeaconProxy.new(anotherAccount, '0x'), 'ERC1967InvalidBeacon', [anotherAccount]);
});
it('non-compliant beacon', async function () {
@ -25,7 +27,10 @@ contract('BeaconProxy', function (accounts) {
it('non-contract implementation', async function () {
const beacon = await BadBeaconNotContract.new();
await expectRevert(BeaconProxy.new(beacon.address, '0x'), 'ERC1967: beacon implementation is not a contract');
const implementation = await beacon.implementation();
await expectRevertCustomError(BeaconProxy.new(beacon.address, '0x'), 'ERC1967InvalidImplementation', [
implementation,
]);
});
});

View File

@ -1,6 +1,8 @@
const { expectRevert, expectEvent } = require('@openzeppelin/test-helpers');
const { expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { expectRevertCustomError } = require('../../helpers/customError');
const UpgradeableBeacon = artifacts.require('UpgradeableBeacon');
const Implementation1 = artifacts.require('Implementation1');
const Implementation2 = artifacts.require('Implementation2');
@ -9,10 +11,7 @@ contract('UpgradeableBeacon', function (accounts) {
const [owner, other] = accounts;
it('cannot be created with non-contract implementation', async function () {
await expectRevert(
UpgradeableBeacon.new(accounts[0], owner),
'UpgradeableBeacon: implementation is not a contract',
);
await expectRevertCustomError(UpgradeableBeacon.new(other, owner), 'BeaconInvalidImplementation', [other]);
});
context('once deployed', async function () {
@ -33,15 +32,16 @@ contract('UpgradeableBeacon', function (accounts) {
});
it('cannot be upgraded to a non-contract', async function () {
await expectRevert(
this.beacon.upgradeTo(other, { from: owner }),
'UpgradeableBeacon: implementation is not a contract',
);
await expectRevertCustomError(this.beacon.upgradeTo(other, { from: owner }), 'BeaconInvalidImplementation', [
other,
]);
});
it('cannot be upgraded by other account', async function () {
const v2 = await Implementation2.new();
await expectRevert(this.beacon.upgradeTo(v2.address, { from: other }), 'Ownable: caller is not the owner');
await expectRevertCustomError(this.beacon.upgradeTo(v2.address, { from: other }), 'OwnableUnauthorizedAccount', [
other,
]);
});
});
});