From 0d317d320231f11a74de6a19a87e62ffe77dc319 Mon Sep 17 00:00:00 2001 From: wshino Date: Wed, 16 Oct 2024 21:27:13 +0900 Subject: [PATCH] Add upgrade test --- packages/contracts/test/EmailAuth.t.sol | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/contracts/test/EmailAuth.t.sol b/packages/contracts/test/EmailAuth.t.sol index d4010ff5..ac7d1341 100644 --- a/packages/contracts/test/EmailAuth.t.sol +++ b/packages/contracts/test/EmailAuth.t.sol @@ -492,4 +492,36 @@ contract EmailAuthTest is StructHelper { vm.expectRevert("only controller"); emailAuth.setTimestampCheckEnabled(false); } + + function testUpgradeEmailAuth() public { + vm.startPrank(deployer); + + // Deploy new implementation + EmailAuth newImplementation = new EmailAuth(); + + // Execute upgrade using proxy + // Upgrade implementation through proxy contract + ERC1967Proxy proxy = new ERC1967Proxy( + address(emailAuth), + abi.encodeCall( + emailAuth.initialize, + (deployer, accountSalt, deployer) + ) + ); + EmailAuth emailAuthProxy = EmailAuth(payable(proxy)); + bytes32 beforeAccountSalt = emailAuthProxy.accountSalt(); + + // Upgrade to new implementation through proxy + emailAuthProxy.upgradeToAndCall( + address(newImplementation), + new bytes(0) + ); + + bytes32 afterAccountSalt = emailAuthProxy.accountSalt(); + + // Verify the upgrade + assertEq(beforeAccountSalt, afterAccountSalt); + + vm.stopPrank(); + } }