Skip to content

Commit

Permalink
Fix upgrade interface version detection (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Lau <[email protected]>
  • Loading branch information
qRoC and ericglau authored May 21, 2024
1 parent 315a089 commit 4cd15fc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.1 (2024-05-21)

- Fix upgrade interface version detection in `upgradeProxy` function. ([#53](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/pull/53))

## 0.3.0 (2024-05-14)

- Adds library variations to support `forge coverage` or upgrade existing deployments using OpenZeppelin Contracts v4. ([#50](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/pull/50))
Expand Down
2 changes: 1 addition & 1 deletion src/internal/Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ library Core {
using strings for *;

function _getUpgradeInterfaceVersion(address addr) private returns (string memory) {
(bool success, bytes memory returndata) = addr.call(abi.encodeWithSignature("getUpgradeInterfaceVersion()"));
(bool success, bytes memory returndata) = addr.call(abi.encodeWithSignature("UPGRADE_INTERFACE_VERSION()"));
if (success) {
return abi.decode(returndata, (string));
} else {
Expand Down
32 changes: 32 additions & 0 deletions test/UnsafeUpgrades.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ contract UnsafeUpgradesTest is Test {
assertFalse(implAddressV2 == implAddressV1);
}

function testUUPS_upgradeWithoutData() public {
address proxy = UnsafeUpgrades.deployUUPSProxy(
address(new GreeterProxiable()),
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
);
address implAddressV1 = UnsafeUpgrades.getImplementationAddress(proxy);

UnsafeUpgrades.upgradeProxy(proxy, address(new GreeterV2Proxiable()), "", msg.sender);
address implAddressV2 = UnsafeUpgrades.getImplementationAddress(proxy);

assertFalse(implAddressV2 == implAddressV1);
}

function testTransparent() public {
address proxy = UnsafeUpgrades.deployTransparentProxy(
address(new Greeter()),
Expand Down Expand Up @@ -68,6 +81,25 @@ contract UnsafeUpgradesTest is Test {
assertFalse(implAddressV2 == implAddressV1);
}

function testTransparent_upgradeWithoutData() public {
address proxy = UnsafeUpgrades.deployTransparentProxy(
address(new Greeter()),
msg.sender,
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
);
address implAddressV1 = UnsafeUpgrades.getImplementationAddress(proxy);
address adminAddress = UnsafeUpgrades.getAdminAddress(proxy);

assertFalse(adminAddress == address(0));

UnsafeUpgrades.upgradeProxy(proxy, address(new GreeterV2()), "", msg.sender);
address implAddressV2 = UnsafeUpgrades.getImplementationAddress(proxy);

assertEq(UnsafeUpgrades.getAdminAddress(proxy), adminAddress);

assertFalse(implAddressV2 == implAddressV1);
}

function testBeacon() public {
address beacon = UnsafeUpgrades.deployBeacon(address(new Greeter()), msg.sender);
address implAddressV1 = IBeacon(beacon).implementation();
Expand Down
32 changes: 32 additions & 0 deletions test/Upgrades.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ contract UpgradesTest is Test {
assertFalse(implAddressV2 == implAddressV1);
}

function testUUPS_upgradeWithoutData() public {
address proxy = Upgrades.deployUUPSProxy(
"GreeterProxiable.sol",
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
);
address implAddressV1 = Upgrades.getImplementationAddress(proxy);

Upgrades.upgradeProxy(proxy, "GreeterV2Proxiable.sol", "", msg.sender);
address implAddressV2 = Upgrades.getImplementationAddress(proxy);

assertFalse(implAddressV2 == implAddressV1);
}

function testTransparent() public {
address proxy = Upgrades.deployTransparentProxy(
"Greeter.sol",
Expand All @@ -65,6 +78,25 @@ contract UpgradesTest is Test {
assertFalse(implAddressV2 == implAddressV1);
}

function testTransparent_upgradeWithoutData() public {
address proxy = Upgrades.deployTransparentProxy(
"Greeter.sol",
msg.sender,
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
);
address implAddressV1 = Upgrades.getImplementationAddress(proxy);
address adminAddress = Upgrades.getAdminAddress(proxy);

assertFalse(adminAddress == address(0));

Upgrades.upgradeProxy(proxy, "GreeterV2.sol", "", msg.sender);
address implAddressV2 = Upgrades.getImplementationAddress(proxy);

assertEq(Upgrades.getAdminAddress(proxy), adminAddress);

assertFalse(implAddressV2 == implAddressV1);
}

function testBeacon() public {
address beacon = Upgrades.deployBeacon("Greeter.sol", msg.sender);
address implAddressV1 = IBeacon(beacon).implementation();
Expand Down

0 comments on commit 4cd15fc

Please sign in to comment.