Skip to content

Commit

Permalink
Revert if the state is not pending
Browse files Browse the repository at this point in the history
  • Loading branch information
garyghayrat committed Jun 24, 2024
1 parent 06eaa4f commit 2f3350f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/L2ArbitrumGovernorV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ contract L2ArbitrumGovernorV2 is
OwnableUpgradeable
{
error NotProposer(address proposer);
error ProposalNotPending(GovernorUpgradeable.ProposalState state);
/// @notice address for which votes will not be counted toward quorum
/// @dev A portion of the Arbitrum tokens will be held by entities (eg the treasury) that
/// are not eligible to vote. However, even if their voting/delegation is restricted their
Expand Down Expand Up @@ -148,6 +149,10 @@ contract L2ArbitrumGovernorV2 is
if (msg.sender != _proposer) {
revert NotProposer(_proposer);
}
uint256 _proposalId = hashProposal(targets, values, calldatas, descriptionHash);
if (state(_proposalId) != ProposalState.Pending) {
revert ProposalNotPending(state(_proposalId));
}
return GovernorUpgradeable.cancel(targets, values, calldatas, descriptionHash);
}

Expand Down
38 changes: 37 additions & 1 deletion test/L2ArbitrumGovernorV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ abstract contract Propose is L2ArbitrumGovernorV2Test {
abstract contract Cancel is L2ArbitrumGovernorV2Test {
event ProposalCanceled(uint256 proposalId);

function testFuzz_CancelProposalAfterSucceedingButBeforeQueuing(uint256 _actorSeed) public virtual {
error NotProposer(address proposer);
error ProposalNotPending(IGovernor.ProposalState state);

function testFuzz_CancelProposalWhenPending(uint256 _actorSeed) public virtual {
address[] memory targets = new address[](1);
uint256[] memory values = new uint256[](1);
bytes[] memory calldatas = new bytes[](1);
Expand All @@ -258,6 +261,39 @@ abstract contract Cancel is L2ArbitrumGovernorV2Test {
governor.cancel(targets, values, calldatas, keccak256(bytes(description)));
assertEq(uint256(governor.state(proposalId)), uint256(IGovernor.ProposalState.Canceled));
}

function testFuzz_RevertIf_NotProposer(uint256 _actorSeed, address _actor) public {
address _proposer = _getMajorDelegate(_actorSeed);
vm.assume(_actor != _proposer && _actor != PROXY_ADMIN_CONTRACT);
address[] memory targets = new address[](1);
uint256[] memory values = new uint256[](1);
bytes[] memory calldatas = new bytes[](1);
string memory description = "Test";

vm.prank(_proposer);
governor.propose(targets, values, calldatas, description);

vm.prank(address(_actor));
vm.expectRevert(abi.encodeWithSelector(NotProposer.selector, _proposer));
governor.cancel(targets, values, calldatas, keccak256(bytes(description)));
}

function testFuzz_RevertIf_ProposalIsActive(uint256 _actorSeed) public {
address[] memory targets = new address[](1);
uint256[] memory values = new uint256[](1);
bytes[] memory calldatas = new bytes[](1);
string memory description = "Test";
address _actor = _getMajorDelegate(_actorSeed);

vm.prank(_actor);
uint256 proposalId = governor.propose(targets, values, calldatas, description);
vm.roll(vm.getBlockNumber() + governor.votingDelay() + 1);

vm.prank(_actor);
vm.expectRevert(abi.encodeWithSelector(ProposalNotPending.selector, IGovernor.ProposalState.Active));
governor.cancel(targets, values, calldatas, keccak256(bytes(description)));
assertEq(uint256(governor.state(proposalId)), uint256(IGovernor.ProposalState.Active));
}
}

// ----------------------------------------------------------------------------------------------------------------- //
Expand Down

0 comments on commit 2f3350f

Please sign in to comment.