From 23b15c03f19b46dbdb9065870846a56c0f637c7b Mon Sep 17 00:00:00 2001 From: Theo Date: Sat, 27 May 2023 14:30:29 +0300 Subject: [PATCH] Added tests to ensure that all contracts are updated correctly --- test/TestProxyUpdated.sol | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 test/TestProxyUpdated.sol diff --git a/test/TestProxyUpdated.sol b/test/TestProxyUpdated.sol new file mode 100644 index 0000000..946d4fa --- /dev/null +++ b/test/TestProxyUpdated.sol @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +import { MockProposal } from "./MockProposal.sol"; +import { console2 } from "@forge-std/console2.sol"; +import { GovernancePatchUpgrade } from "@root/v4-patch/GovernancePatchUpgrade.sol"; + +contract TestProxyUpdating is MockProposal { + function isContract(address _addr) private view returns (bool) { + uint32 size; + assembly { + size := extcodesize(_addr) + } + return (size > 0); + } + + function getAddressFromSlot(address _contract, bytes32 slot) internal view returns (address) { + bytes32 slotData = vm.load(_contract, slot); + return address(uint256(slotData)); + } + + function getUpgradeableProxyImplementationAddress(address proxy) internal view returns (address) { + bytes32 proxyImplementationSlot = bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc); + + return getAddressFromSlot(proxy, proxyImplementationSlot); + } + + function getRelayerRegistryImplementationAddress() internal view returns (address) { + return getUpgradeableProxyImplementationAddress(getRelayerRegistryProxyAddress()); + } + + function getStakingImplementationAddress() internal view returns (address) { + return getUpgradeableProxyImplementationAddress(getStakingProxyAddress()); + } + + function testGovernanceStakingProxyUpdated() public { + address stakingProxyAddressBeforeExecution = getStakingProxyAddress(); + console2.log("Staking proxy address before proposal execution: %s", stakingProxyAddressBeforeExecution); + + createAndExecuteProposal(); + + address stakingProxyAddressAfterExecution = getStakingProxyAddress(); + console2.log("Staking proxy address after proposal execution: %s", stakingProxyAddressAfterExecution); + + require(stakingProxyAddressBeforeExecution != stakingProxyAddressAfterExecution, "Staking proxy address didn't changed"); + require(isContract(stakingProxyAddressAfterExecution)); + } + + function testGovernanceStakingImplementationUpdated() public { + address stakingImplementationAddressBeforeExecution = getStakingImplementationAddress(); + console2.log("Staking implementation address before proposal execution: %s", stakingImplementationAddressBeforeExecution); + + createAndExecuteProposal(); + + address stakingImplementationAddressAfterExecution = getStakingImplementationAddress(); + console2.log("Staking implementation address after proposal execution: %s", stakingImplementationAddressAfterExecution); + + require( + stakingImplementationAddressBeforeExecution != stakingImplementationAddressAfterExecution, + "Staking implementation address didn't changed" + ); + require(isContract(stakingImplementationAddressAfterExecution)); + } + + function testRelayerRegistryImplementationUpdated() public { + address relayerRegistryImplementationAddressBeforeExecution = getRelayerRegistryImplementationAddress(); + console2.log( + "Relayer registry implementation address before proposal execution: %s", relayerRegistryImplementationAddressBeforeExecution + ); + + createAndExecuteProposal(); + + address relayerRegistryImplementationAddressAfterExecution = getRelayerRegistryImplementationAddress(); + console2.log( + "Relayer registry implementation address after proposal execution: %s", relayerRegistryImplementationAddressAfterExecution + ); + + require( + relayerRegistryImplementationAddressBeforeExecution != relayerRegistryImplementationAddressAfterExecution, + "Relayer registry implementation address didn't changed" + ); + require(isContract(relayerRegistryImplementationAddressAfterExecution)); + } + + function testGovernanceImplementationUpdated() public { + address governanceImplementationAddressBeforeExecution = getUpgradeableProxyImplementationAddress(_governanceAddress); + console2.log("Governance implementation address before proposal execution: %s", governanceImplementationAddressBeforeExecution); + + createAndExecuteProposal(); + + address governanceImplementationAddressAfterExecution = getUpgradeableProxyImplementationAddress(_governanceAddress); + console2.log("Governance implementation address after proposal execution: %s", governanceImplementationAddressAfterExecution); + + require( + governanceImplementationAddressBeforeExecution != governanceImplementationAddressAfterExecution, + "Governance implementation address didn't changed" + ); + require(isContract(governanceImplementationAddressAfterExecution)); + } + + function testRelayerRegistryProxyNotUpdated() public { + address relayerRegistryProxyAddressBeforeExecution = getRelayerRegistryProxyAddress(); + console2.log("Relayer registry proxy before proposal execution: %s", relayerRegistryProxyAddressBeforeExecution); + + createAndExecuteProposal(); + + address relayerRegistryProxyAddressAfterExecution = getRelayerRegistryProxyAddress(); + console2.log("Relayer registry proxyafter proposal execution: %s", relayerRegistryProxyAddressAfterExecution); + + require( + relayerRegistryProxyAddressBeforeExecution == relayerRegistryProxyAddressAfterExecution, + "Relayer registry proxy address changed" + ); + } +}