Skip to content

Commit

Permalink
Added L2VotingPowerPaused and L2GovernorPaused contract with test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Phanco committed Jun 11, 2024
1 parent ceedb25 commit e0df7f0
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 0 deletions.
151 changes: 151 additions & 0 deletions src/L2/paused/L2GovernorPaused.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.23;

import { Ownable2StepUpgradeable } from "@openzeppelin-upgradeable/contracts/access/Ownable2StepUpgradeable.sol";
import { Initializable } from "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import { TimelockControllerUpgradeable } from
"@openzeppelin-upgradeable/contracts/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import { L2Governor } from "../L2Governor.sol";

contract L2GovernorPaused is L2Governor {
/// @notice Setting global params.
function initializePaused() public reinitializer(2) { }

function version() public pure virtual override returns (string memory) {
return string.concat(super.version(), "-paused");
}

/// @notice Override the cancel function to prevent staking from being processed.
function cancel(
address[] memory,
uint256[] memory,
bytes[] memory,
bytes32
)
public
virtual
override
returns (uint256)
{
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the castVote function to prevent staking from being processed.
function castVote(uint256, uint8) public virtual override returns (uint256) {
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the castVoteBySig function to prevent staking from being processed.
function castVoteBySig(uint256, uint8, address, bytes memory) public virtual override returns (uint256) {
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the castVoteWithReason function to prevent staking from being processed.
function castVoteWithReason(uint256, uint8, string calldata) public virtual override returns (uint256) {
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the castVoteWithReasonAndParams function to prevent staking from being processed.
function castVoteWithReasonAndParams(
uint256,
uint8,
string calldata,
bytes memory
)
public
virtual
override
returns (uint256)
{
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the castVoteWithReasonAndParamsBySig function to prevent staking from being processed.
function castVoteWithReasonAndParamsBySig(
uint256,
uint8,
address,
string calldata,
bytes memory,
bytes memory
)
public
virtual
override
returns (uint256)
{
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the execute function to prevent staking from being processed.
function execute(
address[] memory,
uint256[] memory,
bytes[] memory,
bytes32
)
public
payable
virtual
override
returns (uint256)
{
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the propose function to prevent staking from being processed.
function propose(
address[] memory,
uint256[] memory,
bytes[] memory,
string memory
)
public
virtual
override
returns (uint256)
{
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the queue function to prevent staking from being processed.
function queue(
address[] memory,
uint256[] memory,
bytes[] memory,
bytes32
)
public
virtual
override
returns (uint256)
{
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the relay function to prevent staking from being processed.
function relay(address, uint256, bytes memory) public payable virtual override {
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the setProposalThreshold function to prevent staking from being processed.
function setProposalThreshold(uint256) public virtual override {
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the setVotingDelay function to prevent staking from being processed.
function setVotingDelay(uint48) public virtual override {
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the setVotingPeriod function to prevent staking from being processed.
function setVotingPeriod(uint32) public virtual override {
revert("L2GovernorPaused: Governor is paused");
}

/// @notice Override the updateTimelock function to prevent staking from being processed.
function updateTimelock(TimelockControllerUpgradeable) public virtual override {
revert("L2GovernorPaused: Governor is paused");
}
}
38 changes: 38 additions & 0 deletions src/L2/paused/L2VotingPowerPaused.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.23;

import { Ownable2StepUpgradeable } from "@openzeppelin-upgradeable/contracts/access/Ownable2StepUpgradeable.sol";
import { Initializable } from "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import { IL2LockingPosition } from "../../interfaces/L2/IL2LockingPosition.sol";
import { L2VotingPower } from "../L2VotingPower.sol";

contract L2VotingPowerPaused is L2VotingPower {
/// @notice Setting global params.
function initializePaused() public reinitializer(2) {
version = "1.0.0-paused";
}

/// @notice Override the modifyLockingPosition function to prevent staking from being processed.
function adjustVotingPower(
address,
IL2LockingPosition.LockingPosition memory,
IL2LockingPosition.LockingPosition memory
)
public
virtual
override
{
revert("L2VotingPowerPaused: VotingPower is paused");
}

/// @notice Override the modifyLockingPosition function to prevent staking from being processed.
function delegate(address) public virtual override {
revert("L2VotingPowerPaused: VotingPower is paused");
}

/// @notice Override the modifyLockingPosition function to prevent staking from being processed.
function delegateBySig(address, uint256, uint256, uint8, bytes32, bytes32) public virtual override {
revert("L2VotingPowerPaused: VotingPower is paused");
}
}
155 changes: 155 additions & 0 deletions test/L2/paused/L2GovernorPaused.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.23;

import { IVotes } from "@openzeppelin-upgradeable/contracts/governance/extensions/GovernorVotesUpgradeable.sol";
import { OwnableUpgradeable } from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import { TimelockController } from "@openzeppelin/contracts/governance/TimelockController.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { TimelockControllerUpgradeable } from
"@openzeppelin-upgradeable/contracts/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import { Test, console } from "forge-std/Test.sol";
import { L2Governor } from "src/L2/L2Governor.sol";
import { L2GovernorPaused } from "src/L2/paused/L2GovernorPaused.sol";
import { Utils } from "script/contracts/Utils.sol";

contract MockL2GovernorV2 is L2Governor {
function version() public pure virtual override returns (string memory) {
return "2.0.0";
}
}

contract L2GovernorPausedTest is Test {
Utils public utils;
L2Governor public l2GovernorImplementation;
L2Governor public l2Governor;

IVotes votingPower;
address[] executors;
TimelockController timelock;
address initialOwner;

function setUp() public {
utils = new Utils();

// set initial values
votingPower = IVotes(address(0x1));
executors.push(address(0)); // executor array contains address(0) such that anyone can execute proposals
timelock = new TimelockController(0, new address[](0), executors, address(this));
initialOwner = address(this);

console.log("L2GovernorTest address is: %s", address(this));

// deploy L2Governor Implementation contract
l2GovernorImplementation = new L2Governor();

// deploy L2Governor contract via proxy and initialize it at the same time
l2Governor = L2Governor(
payable(
address(
new ERC1967Proxy(
address(l2GovernorImplementation),
abi.encodeWithSelector(l2Governor.initialize.selector, votingPower, timelock, initialOwner)
)
)
)
);

assertEq(l2Governor.name(), "Lisk Governor");
assertEq(l2Governor.version(), "1.0.0");
assertEq(l2Governor.votingDelay(), 0);
assertEq(l2Governor.votingPeriod(), 604800);
assertEq(l2Governor.proposalThreshold(), 300_000 * 10 ** 18);
assertEq(l2Governor.timelock(), address(timelock));
assertEq(l2Governor.quorum(0), 24_000_000 * 10 ** 18);
assertEq(address(l2Governor.token()), address(votingPower));
assertEq(l2Governor.owner(), initialOwner);

// assure that address(0) is in executors role
assertEq(timelock.hasRole(timelock.EXECUTOR_ROLE(), address(0)), true);

// Upgrade from L2Governor to L2GovernorPaused
L2GovernorPaused l2GovernorPausedImplementation = new L2GovernorPaused();
l2Governor.upgradeToAndCall(address(l2GovernorPausedImplementation), "");
assertEq(l2Governor.version(), "1.0.0-paused");
}

function test_Cancel_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.cancel(new address[](1), new uint256[](1), new bytes[](1), 0);
}

function test_CastVote_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.castVote(0, 0);
}

function test_CastVoteBySig_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.castVoteBySig(0, 0, address(0), "");
}

function test_CastVoteWithReason_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.castVoteWithReason(0, 0, "");
}

function test_CastVoteWithReasonAndParams_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.castVoteWithReasonAndParams(0, 0, "", "");
}

function test_CastVoteWithReasonAndParamsBySig_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.castVoteWithReasonAndParamsBySig(0, 0, address(0), "", "", "");
}

function test_Execute_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.execute(new address[](1), new uint256[](1), new bytes[](1), 0);
}

function test_Propose_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.propose(new address[](1), new uint256[](1), new bytes[](1), "");
}

function test_Queue_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.queue(new address[](1), new uint256[](1), new bytes[](1), "");
}

function test_Relay_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.relay(address(0), 0, "");
}

function test_SetProposalThreshold_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.setProposalThreshold(0);
}

function test_SetVotingDelay_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.setVotingDelay(0);
}

function test_SetVotingPeriod_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.setVotingPeriod(0);
}

function test_UpdateTimelock_Paused() public {
vm.expectRevert("L2GovernorPaused: Governor is paused");
l2Governor.updateTimelock(TimelockControllerUpgradeable(payable(address(0))));
}

function test_UpgradeToAndCall_CanUpgradeFromPausedContractToNewContract() public {
MockL2GovernorV2 mockL2GovernorV2Implementation = new MockL2GovernorV2();

// upgrade contract
l2Governor.upgradeToAndCall(address(mockL2GovernorV2Implementation), "");

// new version updated
assertEq(l2Governor.version(), "2.0.0");
}
}
Loading

0 comments on commit e0df7f0

Please sign in to comment.