Make TransparentUpgradeableProxy deploy its ProxyAdmin and optimize proxy interfaces (#4382)

This commit is contained in:
Francisco Giordano
2023-07-09 16:54:32 -03:00
parent e47b53bce4
commit 8fff875589
24 changed files with 300 additions and 308 deletions

View File

@ -2,15 +2,18 @@ const { expectRevert } = require('@openzeppelin/test-helpers');
const { getSlot, ImplementationSlot } = require('../helpers/erc1967');
const { expect } = require('chai');
const { expectRevertCustomError } = require('../helpers/customError');
const DummyImplementation = artifacts.require('DummyImplementation');
module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress, proxyCreator) {
module.exports = function shouldBehaveLikeProxy(createProxy, accounts) {
const [proxyCreator] = accounts;
it('cannot be initialized with a non-contract address', async function () {
const nonContractAddress = proxyCreator;
const initializeData = Buffer.from('');
await expectRevert.unspecified(
createProxy(nonContractAddress, proxyAdminAddress, initializeData, {
createProxy(nonContractAddress, initializeData, {
from: proxyCreator,
}),
);
@ -43,7 +46,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
describe('when not sending balance', function () {
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
await createProxy(this.implementation, initializeData, {
from: proxyCreator,
})
).address;
@ -55,16 +58,16 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
describe('when sending some balance', function () {
const value = 10e5;
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
it('reverts', async function () {
await expectRevertCustomError(
createProxy(this.implementation, initializeData, {
from: proxyCreator,
value,
})
).address;
}),
'ERC1967NonPayable',
[],
);
});
assertProxyInitialization({ value: 0, balance: value });
});
});
@ -76,7 +79,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
describe('when not sending balance', function () {
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
await createProxy(this.implementation, initializeData, {
from: proxyCreator,
})
).address;
@ -93,7 +96,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
it('reverts', async function () {
await expectRevert.unspecified(
createProxy(this.implementation, proxyAdminAddress, initializeData, { from: proxyCreator, value }),
createProxy(this.implementation, initializeData, { from: proxyCreator, value }),
);
});
});
@ -106,7 +109,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
describe('when not sending balance', function () {
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
await createProxy(this.implementation, initializeData, {
from: proxyCreator,
})
).address;
@ -123,7 +126,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
await createProxy(this.implementation, initializeData, {
from: proxyCreator,
value,
})
@ -148,7 +151,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
describe('when not sending balance', function () {
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
await createProxy(this.implementation, initializeData, {
from: proxyCreator,
})
).address;
@ -165,7 +168,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
it('reverts', async function () {
await expectRevert.unspecified(
createProxy(this.implementation, proxyAdminAddress, initializeData, { from: proxyCreator, value }),
createProxy(this.implementation, initializeData, { from: proxyCreator, value }),
);
});
});
@ -180,7 +183,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
describe('when not sending balance', function () {
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
await createProxy(this.implementation, initializeData, {
from: proxyCreator,
})
).address;
@ -197,7 +200,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
beforeEach('creating proxy', async function () {
this.proxy = (
await createProxy(this.implementation, proxyAdminAddress, initializeData, {
await createProxy(this.implementation, initializeData, {
from: proxyCreator,
value,
})
@ -216,7 +219,7 @@ module.exports = function shouldBehaveLikeProxy(createProxy, proxyAdminAddress,
it('reverts', async function () {
await expectRevert(
createProxy(this.implementation, proxyAdminAddress, initializeData, { from: proxyCreator }),
createProxy(this.implementation, initializeData, { from: proxyCreator }),
'DummyImplementation reverted',
);
});