Skip to content

Commit

Permalink
Merge pull request #66 from lidofinance/feature/protected-timelock-im…
Browse files Browse the repository at this point in the history
…provements

Integration tests for proposal deployment modes
  • Loading branch information
Psirex authored Jul 24, 2024
2 parents 836594e + f5df40c commit b69da03
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
147 changes: 147 additions & 0 deletions test/scenario/proposal-deployment-modes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {EmergencyState} from "contracts/libraries/EmergencyProtection.sol";
import {Proposals} from "contracts/libraries/Proposals.sol";
import {Durations, Timestamps} from "test/utils/unit-test.sol";

import {percents, ScenarioTestBlueprint, ExecutorCall} from "../utils/scenario-test-blueprint.sol";

contract ProposalDeploymentModesTest is ScenarioTestBlueprint {
function setUp() external {
_selectFork();

_deployTarget();
}

function test_regular_deployment_mode() external {
_deployDualGovernanceSetup(false);

(uint256 proposalId, ExecutorCall[] memory regularStaffCalls) = _createAndAssertProposal();

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2));

vm.expectRevert(abi.encodeWithSelector(Proposals.AfterSubmitDelayNotPassed.selector, (proposalId)));
_scheduleProposal(_dualGovernance, proposalId);

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2).plusSeconds(1));

_assertCanSchedule(_dualGovernance, proposalId, true);
_scheduleProposal(_dualGovernance, proposalId);
_assertProposalScheduled(proposalId);

_waitAfterScheduleDelayPassed();

_assertCanExecute(proposalId, true);
_executeProposal(proposalId);

_assertTargetMockCalls(_config.ADMIN_EXECUTOR(), regularStaffCalls);
}

function test_protected_deployment_mode_execute_after_timelock() external {
_deployDualGovernanceSetup(true);

(uint256 proposalId, ExecutorCall[] memory regularStaffCalls) = _createAndAssertProposal();

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2));

vm.expectRevert(abi.encodeWithSelector(Proposals.AfterSubmitDelayNotPassed.selector, (proposalId)));
_scheduleProposal(_dualGovernance, proposalId);

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2).plusSeconds(1));

_assertCanSchedule(_dualGovernance, proposalId, true);
_scheduleProposal(_dualGovernance, proposalId);
_assertProposalScheduled(proposalId);

_waitAfterScheduleDelayPassed();

_assertCanExecute(proposalId, true);
_executeProposal(proposalId);

_assertTargetMockCalls(_config.ADMIN_EXECUTOR(), regularStaffCalls);
}

function test_protected_deployment_mode_execute_in_emergency_mode() external {
_deployDualGovernanceSetup(true);

(uint256 proposalId, ExecutorCall[] memory regularStaffCalls) = _createAndAssertProposal();

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2));

vm.expectRevert(abi.encodeWithSelector(Proposals.AfterSubmitDelayNotPassed.selector, (proposalId)));
_scheduleProposal(_dualGovernance, proposalId);

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2).plusSeconds(1));

_assertCanSchedule(_dualGovernance, proposalId, true);
_scheduleProposal(_dualGovernance, proposalId);
_assertProposalScheduled(proposalId);

_waitAfterScheduleDelayPassed();

_assertCanExecute(proposalId, true);

vm.prank(address(_emergencyActivationCommittee));
_timelock.activateEmergencyMode();

EmergencyState memory emergencyState = _timelock.getEmergencyState();

assertEq(emergencyState.isEmergencyModeActivated, true);

_assertCanExecute(proposalId, false);

vm.prank(address(_emergencyExecutionCommittee));
_timelock.emergencyExecute(proposalId);

_assertTargetMockCalls(_config.ADMIN_EXECUTOR(), regularStaffCalls);
}

function test_protected_deployment_mode_deactivation_in_emergency_mode() external {
_deployDualGovernanceSetup(true);

(uint256 proposalId, ExecutorCall[] memory regularStaffCalls) = _createAndAssertProposal();

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2));

vm.expectRevert(abi.encodeWithSelector(Proposals.AfterSubmitDelayNotPassed.selector, (proposalId)));
_scheduleProposal(_dualGovernance, proposalId);

_wait(_config.AFTER_SUBMIT_DELAY().dividedBy(2).plusSeconds(1));

_assertCanSchedule(_dualGovernance, proposalId, true);
_scheduleProposal(_dualGovernance, proposalId);
_assertProposalScheduled(proposalId);

_waitAfterScheduleDelayPassed();

_assertCanExecute(proposalId, true);

vm.prank(address(_emergencyActivationCommittee));
_timelock.activateEmergencyMode();

EmergencyState memory emergencyState = _timelock.getEmergencyState();

assertEq(emergencyState.isEmergencyModeActivated, true);
_assertCanExecute(proposalId, false);

_wait(emergencyState.emergencyModeDuration.plusSeconds(1));

_timelock.deactivateEmergencyMode();

_assertCanExecute(proposalId, false);
assertEq(_timelock.isEmergencyProtectionEnabled(), false);
}

function _createAndAssertProposal() internal returns (uint256, ExecutorCall[] memory) {
ExecutorCall[] memory regularStaffCalls = _getTargetRegularStaffCalls();

uint256 proposalId = _submitProposal(
_dualGovernance, "DAO does regular staff on potentially dangerous contract", regularStaffCalls
);
_assertProposalSubmitted(proposalId);
_assertSubmittedProposalData(proposalId, regularStaffCalls);

return (proposalId, regularStaffCalls);
}
}
2 changes: 2 additions & 0 deletions test/utils/scenario-test-blueprint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ contract ScenarioTestBlueprint is Test {
)
)
);

assertEq(_timelock.isEmergencyProtectionEnabled(), true);
}

_resealManager = new ResealManager(address(_timelock));
Expand Down

0 comments on commit b69da03

Please sign in to comment.