Skip to content

Commit 4cd15fc

Browse files
qRoCericglau
andauthored
Fix upgrade interface version detection (#53)
Co-authored-by: Eric Lau <[email protected]>
1 parent 315a089 commit 4cd15fc

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.3.1 (2024-05-21)
4+
5+
- Fix upgrade interface version detection in `upgradeProxy` function. ([#53](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/pull/53))
6+
37
## 0.3.0 (2024-05-14)
48

59
- 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))

src/internal/Core.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ library Core {
303303
using strings for *;
304304

305305
function _getUpgradeInterfaceVersion(address addr) private returns (string memory) {
306-
(bool success, bytes memory returndata) = addr.call(abi.encodeWithSignature("getUpgradeInterfaceVersion()"));
306+
(bool success, bytes memory returndata) = addr.call(abi.encodeWithSignature("UPGRADE_INTERFACE_VERSION()"));
307307
if (success) {
308308
return abi.decode(returndata, (string));
309309
} else {

test/UnsafeUpgrades.t.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ contract UnsafeUpgradesTest is Test {
4040
assertFalse(implAddressV2 == implAddressV1);
4141
}
4242

43+
function testUUPS_upgradeWithoutData() public {
44+
address proxy = UnsafeUpgrades.deployUUPSProxy(
45+
address(new GreeterProxiable()),
46+
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
47+
);
48+
address implAddressV1 = UnsafeUpgrades.getImplementationAddress(proxy);
49+
50+
UnsafeUpgrades.upgradeProxy(proxy, address(new GreeterV2Proxiable()), "", msg.sender);
51+
address implAddressV2 = UnsafeUpgrades.getImplementationAddress(proxy);
52+
53+
assertFalse(implAddressV2 == implAddressV1);
54+
}
55+
4356
function testTransparent() public {
4457
address proxy = UnsafeUpgrades.deployTransparentProxy(
4558
address(new Greeter()),
@@ -68,6 +81,25 @@ contract UnsafeUpgradesTest is Test {
6881
assertFalse(implAddressV2 == implAddressV1);
6982
}
7083

84+
function testTransparent_upgradeWithoutData() public {
85+
address proxy = UnsafeUpgrades.deployTransparentProxy(
86+
address(new Greeter()),
87+
msg.sender,
88+
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
89+
);
90+
address implAddressV1 = UnsafeUpgrades.getImplementationAddress(proxy);
91+
address adminAddress = UnsafeUpgrades.getAdminAddress(proxy);
92+
93+
assertFalse(adminAddress == address(0));
94+
95+
UnsafeUpgrades.upgradeProxy(proxy, address(new GreeterV2()), "", msg.sender);
96+
address implAddressV2 = UnsafeUpgrades.getImplementationAddress(proxy);
97+
98+
assertEq(UnsafeUpgrades.getAdminAddress(proxy), adminAddress);
99+
100+
assertFalse(implAddressV2 == implAddressV1);
101+
}
102+
71103
function testBeacon() public {
72104
address beacon = UnsafeUpgrades.deployBeacon(address(new Greeter()), msg.sender);
73105
address implAddressV1 = IBeacon(beacon).implementation();

test/Upgrades.t.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ contract UpgradesTest is Test {
4242
assertFalse(implAddressV2 == implAddressV1);
4343
}
4444

45+
function testUUPS_upgradeWithoutData() public {
46+
address proxy = Upgrades.deployUUPSProxy(
47+
"GreeterProxiable.sol",
48+
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
49+
);
50+
address implAddressV1 = Upgrades.getImplementationAddress(proxy);
51+
52+
Upgrades.upgradeProxy(proxy, "GreeterV2Proxiable.sol", "", msg.sender);
53+
address implAddressV2 = Upgrades.getImplementationAddress(proxy);
54+
55+
assertFalse(implAddressV2 == implAddressV1);
56+
}
57+
4558
function testTransparent() public {
4659
address proxy = Upgrades.deployTransparentProxy(
4760
"Greeter.sol",
@@ -65,6 +78,25 @@ contract UpgradesTest is Test {
6578
assertFalse(implAddressV2 == implAddressV1);
6679
}
6780

81+
function testTransparent_upgradeWithoutData() public {
82+
address proxy = Upgrades.deployTransparentProxy(
83+
"Greeter.sol",
84+
msg.sender,
85+
abi.encodeCall(Greeter.initialize, (msg.sender, "hello"))
86+
);
87+
address implAddressV1 = Upgrades.getImplementationAddress(proxy);
88+
address adminAddress = Upgrades.getAdminAddress(proxy);
89+
90+
assertFalse(adminAddress == address(0));
91+
92+
Upgrades.upgradeProxy(proxy, "GreeterV2.sol", "", msg.sender);
93+
address implAddressV2 = Upgrades.getImplementationAddress(proxy);
94+
95+
assertEq(Upgrades.getAdminAddress(proxy), adminAddress);
96+
97+
assertFalse(implAddressV2 == implAddressV1);
98+
}
99+
68100
function testBeacon() public {
69101
address beacon = Upgrades.deployBeacon("Greeter.sol", msg.sender);
70102
address implAddressV1 = IBeacon(beacon).implementation();

0 commit comments

Comments
 (0)