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,5 +1,4 @@
const { expectRevert } = require('@openzeppelin/test-helpers');
const { getAddressInSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');
const { expect } = require('chai');
const ImplV1 = artifacts.require('DummyImplementation');
const ImplV2 = artifacts.require('DummyImplementationV2');
@ -7,6 +6,9 @@ const ProxyAdmin = artifacts.require('ProxyAdmin');
const TransparentUpgradeableProxy = artifacts.require('TransparentUpgradeableProxy');
const ITransparentUpgradeableProxy = artifacts.require('ITransparentUpgradeableProxy');
const { getAddressInSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');
const { expectRevertCustomError } = require('../../helpers/customError');
contract('ProxyAdmin', function (accounts) {
const [proxyAdminOwner, newAdmin, anotherAccount] = accounts;
@ -32,9 +34,10 @@ contract('ProxyAdmin', function (accounts) {
describe('#changeProxyAdmin', function () {
it('fails to change proxy admin if its not the proxy owner', async function () {
await expectRevert(
await expectRevertCustomError(
this.proxyAdmin.changeProxyAdmin(this.proxy.address, newAdmin, { from: anotherAccount }),
'caller is not the owner',
'OwnableUnauthorizedAccount',
[anotherAccount],
);
});
@ -49,9 +52,10 @@ contract('ProxyAdmin', function (accounts) {
describe('#upgrade', function () {
context('with unauthorized account', function () {
it('fails to upgrade', async function () {
await expectRevert(
await expectRevertCustomError(
this.proxyAdmin.upgrade(this.proxy.address, this.implementationV2.address, { from: anotherAccount }),
'caller is not the owner',
'OwnableUnauthorizedAccount',
[anotherAccount],
);
});
});
@ -70,11 +74,12 @@ contract('ProxyAdmin', function (accounts) {
context('with unauthorized account', function () {
it('fails to upgrade', async function () {
const callData = new ImplV1('').contract.methods.initializeNonPayableWithValue(1337).encodeABI();
await expectRevert(
await expectRevertCustomError(
this.proxyAdmin.upgradeAndCall(this.proxy.address, this.implementationV2.address, callData, {
from: anotherAccount,
}),
'caller is not the owner',
'OwnableUnauthorizedAccount',
[anotherAccount],
);
});
});

View File

@ -1,6 +1,7 @@
const { BN, expectRevert, expectEvent, constants } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { getAddressInSlot, ImplementationSlot, AdminSlot } = require('../../helpers/erc1967');
const { expectRevertCustomError } = require('../../helpers/customError');
const { expect } = require('chai');
const { web3 } = require('hardhat');
@ -67,10 +68,9 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy(createProx
describe('when the given implementation is the zero address', function () {
it('reverts', async function () {
await expectRevert(
this.proxy.upgradeTo(ZERO_ADDRESS, { from }),
'ERC1967: new implementation is not a contract',
);
await expectRevertCustomError(this.proxy.upgradeTo(ZERO_ADDRESS, { from }), 'ERC1967InvalidImplementation', [
ZERO_ADDRESS,
]);
});
});
});
@ -289,9 +289,10 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy(createProx
describe('when the new proposed admin is the zero address', function () {
it('reverts', async function () {
await expectRevert(
await expectRevertCustomError(
this.proxy.changeAdmin(ZERO_ADDRESS, { from: proxyAdminAddress }),
'ERC1967: new admin is the zero address',
'ERC1967InvalidAdmin',
[ZERO_ADDRESS],
);
});
});
@ -306,9 +307,10 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy(createProx
});
it('proxy admin cannot call delegated functions', async function () {
await expectRevert(
await expectRevertCustomError(
this.clashing.delegatedFunction({ from: proxyAdminAddress }),
'TransparentUpgradeableProxy: admin cannot fallback to proxy target',
'ProxyDeniedAdminAccess',
[],
);
});