// 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" ); } }