|
| 1 | +// SPDX-License-Identifier: AGPL-3.0-only |
| 2 | +pragma solidity 0.8.26; |
| 3 | + |
| 4 | +import {Test, console2} from "forge-std/Test.sol"; |
| 5 | +import {SubmitUpgradeProposalScript} from "script/SubmitUpgradeProposalScript.s.sol"; |
| 6 | +import {IGovernor} from "openzeppelin-v5/governance/IGovernor.sol"; |
| 7 | +import {TimelockRolesUpgrader} from |
| 8 | + "src/gov-action-contracts/gov-upgrade-contracts/update-timelock-roles/TimelockRolesUpgrader.sol"; |
| 9 | +import {SetupNewGovernors} from "test/util/SetupNewGovernors.sol"; |
| 10 | + |
| 11 | +contract SubmitUpgradeProposalTest is SetupNewGovernors { |
| 12 | + function test_SuccessfullyExecuteUpgradeProposal() public { |
| 13 | + TimelockRolesUpgrader timelockRolesUpgrader = new TimelockRolesUpgrader( |
| 14 | + L2_CORE_GOVERNOR_TIMELOCK, |
| 15 | + L2_CORE_GOVERNOR, |
| 16 | + L2_CORE_GOVERNOR_NEW_DEPLOY, |
| 17 | + L2_TREASURY_GOVERNOR_TIMELOCK, |
| 18 | + L2_TREASURY_GOVERNOR, |
| 19 | + L2_TREASURY_GOVERNOR_NEW_DEPLOY |
| 20 | + ); |
| 21 | + |
| 22 | + // Propose |
| 23 | + ( |
| 24 | + address[] memory _targets, |
| 25 | + uint256[] memory _values, |
| 26 | + bytes[] memory _calldatas, |
| 27 | + string memory _description, |
| 28 | + uint256 _proposalId |
| 29 | + ) = submitUpgradeProposalScript.run(address(timelockRolesUpgrader), L1_TIMELOCK_MIN_DELAY); |
| 30 | + assertEq( |
| 31 | + uint256(currentCoreGovernor.state(_proposalId)), |
| 32 | + uint256(IGovernor.ProposalState.Pending) |
| 33 | + ); |
| 34 | + vm.roll(vm.getBlockNumber() + currentCoreGovernor.votingDelay() + 1); |
| 35 | + assertEq( |
| 36 | + uint256(currentCoreGovernor.state(_proposalId)), uint256(IGovernor.ProposalState.Active) |
| 37 | + ); |
| 38 | + |
| 39 | + // Vote |
| 40 | + for (uint256 i; i < _majorDelegates.length; i++) { |
| 41 | + vm.prank(_majorDelegates[i]); |
| 42 | + currentCoreGovernor.castVote(_proposalId, uint8(VoteType.For)); |
| 43 | + } |
| 44 | + |
| 45 | + // Success |
| 46 | + vm.roll(vm.getBlockNumber() + currentCoreGovernor.votingPeriod() + 1); |
| 47 | + assertEq( |
| 48 | + uint256(currentCoreGovernor.state(_proposalId)), |
| 49 | + uint256(IGovernor.ProposalState.Succeeded) |
| 50 | + ); |
| 51 | + |
| 52 | + // Queue |
| 53 | + currentCoreGovernor.queue(_targets, _values, _calldatas, keccak256(bytes(_description))); |
| 54 | + assertEq( |
| 55 | + uint256(currentCoreGovernor.state(_proposalId)), uint256(IGovernor.ProposalState.Queued) |
| 56 | + ); |
| 57 | + vm.warp(vm.getBlockTimestamp() + currentCoreTimelock.getMinDelay() + 1); |
| 58 | + |
| 59 | + // Execute |
| 60 | + currentCoreGovernor.execute(_targets, _values, _calldatas, keccak256(bytes(_description))); |
| 61 | + assertEq( |
| 62 | + uint256(currentCoreGovernor.state(_proposalId)), |
| 63 | + uint256(IGovernor.ProposalState.Executed) |
| 64 | + ); |
| 65 | + |
| 66 | + assertEq( |
| 67 | + currentCoreTimelock.hasRole(keccak256("PROPOSER_ROLE"), address(newCoreGovernor)), true |
| 68 | + ); |
| 69 | + assertEq( |
| 70 | + currentCoreTimelock.hasRole(keccak256("CANCELLER_ROLE"), address(newCoreGovernor)), true |
| 71 | + ); |
| 72 | + assertEq(currentCoreTimelock.hasRole(keccak256("PROPOSER_ROLE"), L2_CORE_GOVERNOR), false); |
| 73 | + assertEq(currentCoreTimelock.hasRole(keccak256("CANCELLER_ROLE"), L2_CORE_GOVERNOR), false); |
| 74 | + |
| 75 | + assertEq( |
| 76 | + currentTreasuryTimelock.hasRole( |
| 77 | + keccak256("PROPOSER_ROLE"), address(newTreasuryGovernor) |
| 78 | + ), |
| 79 | + true |
| 80 | + ); |
| 81 | + assertEq( |
| 82 | + currentTreasuryTimelock.hasRole( |
| 83 | + keccak256("CANCELLER_ROLE"), address(newTreasuryGovernor) |
| 84 | + ), |
| 85 | + true |
| 86 | + ); |
| 87 | + assertEq( |
| 88 | + currentTreasuryTimelock.hasRole(keccak256("PROPOSER_ROLE"), L2_TREASURY_GOVERNOR), false |
| 89 | + ); |
| 90 | + assertEq( |
| 91 | + currentTreasuryTimelock.hasRole(keccak256("CANCELLER_ROLE"), L2_TREASURY_GOVERNOR), |
| 92 | + false |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + function test_DefeatedExecuteUpgradeProposalDoesNotChangeRoles() public { |
| 97 | + TimelockRolesUpgrader timelockRolesUpgrader = new TimelockRolesUpgrader( |
| 98 | + L2_CORE_GOVERNOR_TIMELOCK, |
| 99 | + L2_CORE_GOVERNOR, |
| 100 | + address(newCoreGovernor), |
| 101 | + L2_TREASURY_GOVERNOR_TIMELOCK, |
| 102 | + L2_TREASURY_GOVERNOR, |
| 103 | + address(newTreasuryGovernor) |
| 104 | + ); |
| 105 | + |
| 106 | + // Propose |
| 107 | + ( |
| 108 | + /*address[] memory _targets*/ |
| 109 | + , |
| 110 | + /*uint256[] memory _values*/ |
| 111 | + , |
| 112 | + /*bytes[] memory _calldatas*/ |
| 113 | + , |
| 114 | + /*string memory _description*/ |
| 115 | + , |
| 116 | + uint256 _proposalId |
| 117 | + ) = submitUpgradeProposalScript.run(address(timelockRolesUpgrader), L1_TIMELOCK_MIN_DELAY); |
| 118 | + assertEq( |
| 119 | + uint256(currentCoreGovernor.state(_proposalId)), |
| 120 | + uint256(IGovernor.ProposalState.Pending) |
| 121 | + ); |
| 122 | + vm.roll(vm.getBlockNumber() + currentCoreGovernor.votingDelay() + 1); |
| 123 | + assertEq( |
| 124 | + uint256(currentCoreGovernor.state(_proposalId)), uint256(IGovernor.ProposalState.Active) |
| 125 | + ); |
| 126 | + |
| 127 | + // Vote |
| 128 | + for (uint256 i; i < _majorDelegates.length; i++) { |
| 129 | + vm.prank(_majorDelegates[i]); |
| 130 | + currentCoreGovernor.castVote(_proposalId, uint8(VoteType.Against)); |
| 131 | + } |
| 132 | + |
| 133 | + // Defeat |
| 134 | + vm.roll(vm.getBlockNumber() + currentCoreGovernor.votingPeriod() + 1); |
| 135 | + assertEq( |
| 136 | + uint256(currentCoreGovernor.state(_proposalId)), |
| 137 | + uint256(IGovernor.ProposalState.Defeated) |
| 138 | + ); |
| 139 | + |
| 140 | + assertEq( |
| 141 | + currentCoreTimelock.hasRole(keccak256("PROPOSER_ROLE"), address(newCoreGovernor)), false |
| 142 | + ); |
| 143 | + assertEq( |
| 144 | + currentCoreTimelock.hasRole(keccak256("CANCELLER_ROLE"), address(newCoreGovernor)), |
| 145 | + false |
| 146 | + ); |
| 147 | + assertEq(currentCoreTimelock.hasRole(keccak256("PROPOSER_ROLE"), L2_CORE_GOVERNOR), true); |
| 148 | + assertEq(currentCoreTimelock.hasRole(keccak256("CANCELLER_ROLE"), L2_CORE_GOVERNOR), true); |
| 149 | + |
| 150 | + assertEq( |
| 151 | + currentTreasuryTimelock.hasRole( |
| 152 | + keccak256("PROPOSER_ROLE"), address(newTreasuryGovernor) |
| 153 | + ), |
| 154 | + false |
| 155 | + ); |
| 156 | + assertEq( |
| 157 | + currentTreasuryTimelock.hasRole( |
| 158 | + keccak256("CANCELLER_ROLE"), address(newTreasuryGovernor) |
| 159 | + ), |
| 160 | + false |
| 161 | + ); |
| 162 | + assertEq( |
| 163 | + currentTreasuryTimelock.hasRole(keccak256("PROPOSER_ROLE"), L2_TREASURY_GOVERNOR), true |
| 164 | + ); |
| 165 | + assertEq( |
| 166 | + currentTreasuryTimelock.hasRole(keccak256("CANCELLER_ROLE"), L2_TREASURY_GOVERNOR), true |
| 167 | + ); |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +interface IUpgradeExecutor { |
| 172 | + function execute(address to, bytes calldata data) external payable; |
| 173 | +} |
0 commit comments