Skip to content

Commit

Permalink
restore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bulbozaur committed Aug 2, 2024
1 parent 0b1b3de commit 2add982
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 9 deletions.
2 changes: 1 addition & 1 deletion contracts/committees/EmergencyActivationCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract EmergencyActivationCommittee is HashConsensus {

/// @notice Approves the emergency activation by casting a vote
/// @dev Only callable by committee members
function approveexecuteActivateEmergencyMode() public onlyMember {
function approveActivateEmergencyMode() public onlyMember {
_vote(EMERGENCY_ACTIVATION_HASH, true);
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/committees/ResealCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {HashConsensus} from "./HashConsensus.sol";
import {ProposalsList} from "./ProposalsList.sol";

interface IDualGovernance {
function reseal(address[] memory sealables) external;
function resealSealables(address[] memory sealables) external;
}

/// @title Reseal Committee Contract
Expand Down Expand Up @@ -59,7 +59,9 @@ contract ResealCommittee is HashConsensus, ProposalsList {
(, bytes32 key) = _encodeResealProposal(sealables);
_markUsed(key);

Address.functionCall(DUAL_GOVERNANCE, abi.encodeWithSelector(IDualGovernance.reseal.selector, sealables));
Address.functionCall(
DUAL_GOVERNANCE, abi.encodeWithSelector(IDualGovernance.resealSealables.selector, sealables)
);

bytes32 resealNonceHash = keccak256(abi.encode(sealables));
_resealNonces[resealNonceHash]++;
Expand Down
15 changes: 10 additions & 5 deletions test/scenario/emergency-committee.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ contract EmergencyCommitteeTest is ScenarioTestBlueprint {

function setUp() external {
_selectFork();
_deployDualGovernanceSetup( /* isEmergencyProtectionEnabled */ false);
_deployTarget();
_deployDualGovernanceSetup( /* isEmergencyProtectionEnabled */ true);
_depositStETH(_VETOER, 1 ether);
}

function test_proposal_approval() external {
function test_emergency_committees_happy_path() external {
uint256 quorum;
uint256 support;
bool isExecuted;

address[] memory members;

ExternalCall[] memory proposalCalls = ExternalCallHelpers.create(address(0), new bytes(0));
ExternalCall[] memory proposalCalls = _getTargetRegularStaffCalls();
uint256 proposalIdToExecute = _submitProposal(_dualGovernance, "Proposal for execution", proposalCalls);

_wait(_config.AFTER_SUBMIT_DELAY().plusSeconds(1));
_assertCanSchedule(_dualGovernance, proposalIdToExecute, true);
_scheduleProposal(_dualGovernance, proposalIdToExecute);

// Emergency Activation
members = _emergencyActivationCommittee.getMembers();
for (uint256 i = 0; i < _emergencyActivationCommittee.quorum() - 1; i++) {
Expand All @@ -47,7 +52,7 @@ contract EmergencyCommitteeTest is ScenarioTestBlueprint {

_emergencyActivationCommittee.executeActivateEmergencyMode();
(support, quorum, isExecuted) = _emergencyActivationCommittee.getActivateEmergencyModeState();
assert(support < quorum);
assert(isExecuted == true);

// Emergency Execute
members = _emergencyExecutionCommittee.getMembers();
Expand All @@ -67,6 +72,6 @@ contract EmergencyCommitteeTest is ScenarioTestBlueprint {

_emergencyExecutionCommittee.executeEmergencyExecute(proposalIdToExecute);
(support, quorum, isExecuted) = _emergencyExecutionCommittee.getEmergencyExecuteState(proposalIdToExecute);
assert(support < quorum);
assert(isExecuted == true);
}
}
67 changes: 67 additions & 0 deletions test/scenario/reseal-committee.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {ScenarioTestBlueprint, ExternalCall, percents} from "../utils/scenario-test-blueprint.sol";
import {DualGovernance} from "../../contracts/DualGovernance.sol";
import {ResealManager} from "../../contracts/ResealManager.sol";
import {DAO_AGENT} from "../utils/mainnet-addresses.sol";

contract ResealCommitteeTest is ScenarioTestBlueprint {
address internal immutable _VETOER = makeAddr("VETOER");
uint256 public constant PAUSE_INFINITELY = type(uint256).max;

function setUp() external {
_selectFork();
_deployTarget();
_deployDualGovernanceSetup( /* isEmergencyProtectionEnabled */ true);
_depositStETH(_VETOER, 1 ether);
}

function test_reseal_committees_happy_path() external {
uint256 quorum;
uint256 support;
bool isExecuted;

address[] memory members;

address[] memory sealables = new address[](1);
sealables[0] = address(_WITHDRAWAL_QUEUE);

vm.prank(DAO_AGENT);
_WITHDRAWAL_QUEUE.grantRole(0x139c2898040ef16910dc9f44dc697df79363da767d8bc92f2e310312b816e46d, address(this));

// Reseal
members = _resealCommittee.getMembers();
for (uint256 i = 0; i < _resealCommittee.quorum() - 1; i++) {
vm.prank(members[i]);
_resealCommittee.voteReseal(sealables, true);
(support, quorum, isExecuted) = _resealCommittee.getResealState(sealables);
assert(support < quorum);
assert(isExecuted == false);
}

vm.prank(members[members.length - 1]);
_resealCommittee.voteReseal(sealables, true);
(support, quorum, isExecuted) = _resealCommittee.getResealState(sealables);
assert(support == quorum);
assert(isExecuted == false);

_assertNormalState();

vm.expectRevert(abi.encodeWithSelector(DualGovernance.ResealIsNotAllowedInNormalState.selector));
_resealCommittee.executeReseal(sealables);

_lockStETH(_VETOER, percents(_config.FIRST_SEAL_RAGE_QUIT_SUPPORT()));
_lockStETH(_VETOER, 1 gwei);
_assertVetoSignalingState();

assertEq(_WITHDRAWAL_QUEUE.isPaused(), false);
vm.expectRevert(abi.encodeWithSelector(ResealManager.SealableWrongPauseState.selector));
_resealCommittee.executeReseal(sealables);

_WITHDRAWAL_QUEUE.pauseFor(3600 * 24 * 6);
assertEq(_WITHDRAWAL_QUEUE.isPaused(), true);

_resealCommittee.executeReseal(sealables);
}
}
22 changes: 21 additions & 1 deletion test/utils/scenario-test-blueprint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {Executor} from "contracts/Executor.sol";

import {EmergencyActivationCommittee} from "contracts/committees/EmergencyActivationCommittee.sol";
import {EmergencyExecutionCommittee} from "contracts/committees/EmergencyExecutionCommittee.sol";
import {ResealCommittee} from "contracts/committees/ResealCommittee.sol";
import {TiebreakerCore} from "contracts/committees/TiebreakerCore.sol";
import {TiebreakerSubCommittee} from "contracts/committees/TiebreakerSubCommittee.sol";

Expand Down Expand Up @@ -82,6 +83,7 @@ contract ScenarioTestBlueprint is Test {

EmergencyActivationCommittee internal _emergencyActivationCommittee;
EmergencyExecutionCommittee internal _emergencyExecutionCommittee;
ResealCommittee internal _resealCommittee;
TiebreakerCore internal _tiebreakerCommittee;
TiebreakerSubCommittee[] internal _tiebreakerSubCommittees;

Expand Down Expand Up @@ -529,6 +531,7 @@ contract ScenarioTestBlueprint is Test {
_deployDualGovernance();
_deployEmergencyActivationCommittee();
_deployEmergencyExecutionCommittee();
_deployResealCommittee();
_deployTiebreaker();
_finishTimelockSetup(address(_dualGovernance), isEmergencyProtectionEnabled);
}
Expand All @@ -542,6 +545,7 @@ contract ScenarioTestBlueprint is Test {
_deployTimelockedGovernance();
_deployEmergencyActivationCommittee();
_deployEmergencyExecutionCommittee();
_deployResealCommittee();
_deployTiebreaker();
_finishTimelockSetup(address(_timelockedGovernance), isEmergencyProtectionEnabled);
}
Expand Down Expand Up @@ -627,6 +631,17 @@ contract ScenarioTestBlueprint is Test {
new EmergencyExecutionCommittee(address(_adminExecutor), committeeMembers, quorum, address(_timelock));
}

function _deployResealCommittee() internal {
uint256 quorum = 3;
uint256 membersCount = 5;
address[] memory committeeMembers = new address[](membersCount);
for (uint256 i = 0; i < membersCount; ++i) {
committeeMembers[i] = makeAddr(string(abi.encode(0xFA + i * membersCount + 65)));
}
_resealCommittee =
new ResealCommittee(address(_adminExecutor), committeeMembers, quorum, address(_dualGovernance), 0);
}

function _finishTimelockSetup(address governance, bool isEmergencyProtectionEnabled) internal {
if (isEmergencyProtectionEnabled) {
_adminExecutor.execute(
Expand Down Expand Up @@ -656,7 +671,6 @@ contract ScenarioTestBlueprint is Test {
_WITHDRAWAL_QUEUE.grantRole(
0x2fc10cc8ae19568712f7a176fb4978616a610650813c9d05326c34abb62749c7, address(_resealManager)
);

if (governance == address(_dualGovernance)) {
_adminExecutor.execute(
address(_dualGovernance),
Expand All @@ -665,6 +679,12 @@ contract ScenarioTestBlueprint is Test {
_dualGovernance.setTiebreakerProtection, (address(_tiebreakerCommittee), address(_resealManager))
)
);

_adminExecutor.execute(
address(_dualGovernance),
0,
abi.encodeCall(_dualGovernance.setReseal, (address(_resealManager), address(_resealCommittee)))
);
}
_adminExecutor.execute(address(_timelock), 0, abi.encodeCall(_timelock.setGovernance, (governance)));
_adminExecutor.transferOwnership(address(_timelock));
Expand Down

0 comments on commit 2add982

Please sign in to comment.