diff --git a/CHANGELOG.md b/CHANGELOG.md index ea330b9..14d14ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/internal/Core.sol b/src/internal/Core.sol index 79dbed4..de292e8 100644 --- a/src/internal/Core.sol +++ b/src/internal/Core.sol @@ -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 { diff --git a/test/UnsafeUpgrades.t.sol b/test/UnsafeUpgrades.t.sol index 6aa6558..70f92fe 100644 --- a/test/UnsafeUpgrades.t.sol +++ b/test/UnsafeUpgrades.t.sol @@ -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()), @@ -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(); diff --git a/test/Upgrades.t.sol b/test/Upgrades.t.sol index f784a8c..d13eb68 100644 --- a/test/Upgrades.t.sol +++ b/test/Upgrades.t.sol @@ -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", @@ -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();