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

Co-authored-by: Francisco <fg@frang.io>
Co-authored-by: Eric Lau <ericglau@outlook.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Ernesto García
2023-07-13 16:25:22 -06:00
committed by GitHub
parent 9cf873ea14
commit 121be5dd09
27 changed files with 521 additions and 356 deletions

View File

@ -25,8 +25,12 @@ contract('UUPSUpgradeable', function () {
this.instance = await UUPSUpgradeableMock.at(address);
});
it('has an interface version', async function () {
expect(await this.instance.UPGRADE_INTERFACE_VERSION()).to.equal('5.0.0');
});
it('upgrade to upgradeable implementation', async function () {
const { receipt } = await this.instance.upgradeTo(this.implUpgradeOk.address);
const { receipt } = await this.instance.upgradeToAndCall(this.implUpgradeOk.address, '0x');
expect(receipt.logs.filter(({ event }) => event === 'Upgraded').length).to.be.equal(1);
expectEvent(receipt, 'Upgraded', { implementation: this.implUpgradeOk.address });
expect(await getAddressInSlot(this.instance, ImplementationSlot)).to.be.equal(this.implUpgradeOk.address);
@ -48,7 +52,7 @@ contract('UUPSUpgradeable', function () {
it('calling upgradeTo on the implementation reverts', async function () {
await expectRevertCustomError(
this.implInitial.upgradeTo(this.implUpgradeOk.address),
this.implInitial.upgradeToAndCall(this.implUpgradeOk.address, '0x'),
'UUPSUnauthorizedCallContext',
[],
);
@ -72,7 +76,7 @@ contract('UUPSUpgradeable', function () {
);
await expectRevertCustomError(
instance.upgradeTo(this.implUpgradeUnsafe.address),
instance.upgradeToAndCall(this.implUpgradeUnsafe.address, '0x'),
'UUPSUnauthorizedCallContext',
[],
);
@ -93,14 +97,14 @@ contract('UUPSUpgradeable', function () {
it('rejects upgrading to an unsupported UUID', async function () {
await expectRevertCustomError(
this.instance.upgradeTo(this.implUnsupportedUUID.address),
this.instance.upgradeToAndCall(this.implUnsupportedUUID.address, '0x'),
'UUPSUnsupportedProxiableUUID',
[web3.utils.keccak256('invalid UUID')],
);
});
it('upgrade to and unsafe upgradeable implementation', async function () {
const { receipt } = await this.instance.upgradeTo(this.implUpgradeUnsafe.address);
const { receipt } = await this.instance.upgradeToAndCall(this.implUpgradeUnsafe.address, '0x');
expectEvent(receipt, 'Upgraded', { implementation: this.implUpgradeUnsafe.address });
expect(await getAddressInSlot(this.instance, ImplementationSlot)).to.be.equal(this.implUpgradeUnsafe.address);
});
@ -108,7 +112,7 @@ contract('UUPSUpgradeable', function () {
// delegate to a non existing upgradeTo function causes a low level revert
it('reject upgrade to non uups implementation', async function () {
await expectRevertCustomError(
this.instance.upgradeTo(this.implUpgradeNonUUPS.address),
this.instance.upgradeToAndCall(this.implUpgradeNonUUPS.address, '0x'),
'ERC1967InvalidImplementation',
[this.implUpgradeNonUUPS.address],
);
@ -118,8 +122,10 @@ contract('UUPSUpgradeable', function () {
const { address } = await ERC1967Proxy.new(this.implInitial.address, '0x');
const otherInstance = await UUPSUpgradeableMock.at(address);
await expectRevertCustomError(this.instance.upgradeTo(otherInstance.address), 'ERC1967InvalidImplementation', [
otherInstance.address,
]);
await expectRevertCustomError(
this.instance.upgradeToAndCall(otherInstance.address, '0x'),
'ERC1967InvalidImplementation',
[otherInstance.address],
);
});
});