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

@ -8,6 +8,7 @@ const ITransparentUpgradeableProxy = artifacts.require('ITransparentUpgradeableP
const { getAddressInSlot, ImplementationSlot } = require('../../helpers/erc1967');
const { expectRevertCustomError } = require('../../helpers/customError');
const { computeCreateAddress } = require('../../helpers/create');
contract('ProxyAdmin', function (accounts) {
const [proxyAdminOwner, anotherAccount] = accounts;
@ -19,12 +20,12 @@ contract('ProxyAdmin', function (accounts) {
beforeEach(async function () {
const initializeData = Buffer.from('');
this.proxyAdmin = await ProxyAdmin.new(proxyAdminOwner);
const proxy = await TransparentUpgradeableProxy.new(
this.implementationV1.address,
this.proxyAdmin.address,
initializeData,
);
const proxy = await TransparentUpgradeableProxy.new(this.implementationV1.address, proxyAdminOwner, initializeData);
const proxyNonce = await web3.eth.getTransactionCount(proxy.address);
const proxyAdminAddress = computeCreateAddress(proxy.address, proxyNonce - 1); // Nonce already used
this.proxyAdmin = await ProxyAdmin.at(proxyAdminAddress);
this.proxy = await ITransparentUpgradeableProxy.at(proxy.address);
});
@ -32,11 +33,13 @@ contract('ProxyAdmin', function (accounts) {
expect(await this.proxyAdmin.owner()).to.equal(proxyAdminOwner);
});
describe('#upgrade', function () {
describe('without data', function () {
context('with unauthorized account', function () {
it('fails to upgrade', async function () {
await expectRevertCustomError(
this.proxyAdmin.upgrade(this.proxy.address, this.implementationV2.address, { from: anotherAccount }),
this.proxyAdmin.upgradeAndCall(this.proxy.address, this.implementationV2.address, '0x', {
from: anotherAccount,
}),
'OwnableUnauthorizedAccount',
[anotherAccount],
);
@ -45,7 +48,9 @@ contract('ProxyAdmin', function (accounts) {
context('with authorized account', function () {
it('upgrades implementation', async function () {
await this.proxyAdmin.upgrade(this.proxy.address, this.implementationV2.address, { from: proxyAdminOwner });
await this.proxyAdmin.upgradeAndCall(this.proxy.address, this.implementationV2.address, '0x', {
from: proxyAdminOwner,
});
const implementationAddress = await getAddressInSlot(this.proxy, ImplementationSlot);
expect(implementationAddress).to.be.equal(this.implementationV2.address);
@ -53,7 +58,7 @@ contract('ProxyAdmin', function (accounts) {
});
});
describe('#upgradeAndCall', function () {
describe('with data', function () {
context('with unauthorized account', function () {
it('fails to upgrade', async function () {
const callData = new ImplV1('').contract.methods.initializeNonPayableWithValue(1337).encodeABI();