Skip to content

Commit

Permalink
chore: solhint and slither
Browse files Browse the repository at this point in the history
  • Loading branch information
baroooo committed Oct 4, 2023
1 parent 0dc6df4 commit e1bd8a3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion contracts/governance/MentoGovernor.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
// solhint-disable max-line-length
// solhint-disable func-name-mixedcase

import { GovernorUpgradeable, IGovernorUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/governance/GovernorUpgradeable.sol";
import { GovernorSettingsUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/governance/extensions/GovernorSettingsUpgradeable.sol";
Expand Down Expand Up @@ -29,6 +28,7 @@ contract MentoGovernor is
* @param veToken The escrowed Mento Token used for voting.
* @param timelockController The timelock controller used by the governor.
*/
// solhint-disable-next-line func-name-mixedcase
function __MentoGovernor_init(IVotesUpgradeable veToken, TimelockControllerUpgradeable timelockController)
external
initializer
Expand Down
6 changes: 3 additions & 3 deletions contracts/governance/TimelockController.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
// solhint-disable max-line-length
// solhint-disable func-name-mixedcase

// solhint-disable-next-line max-line-length
import { TimelockControllerUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/governance/TimelockControllerUpgradeable.sol";

/**
Expand All @@ -16,10 +15,11 @@ contract TimelockController is TimelockControllerUpgradeable {
* @notice Initializes the TimelockController with the provided parameters.
* @param minDelay The minimum delay before a proposal can be executed.
* @param proposers List of addresses that are allowed to queue and cancel operations.
* @param executors List of addresses that are allowed to execute proposals. address(0) can be used to allow any account.
* @param executors List of addresses that are allowed to execute proposals. 0 can be used to allow any account.
* @param admin The admin address that will be used to set the proposer role and then will be renounced.
* @param canceller The community multisig that will have the rights to cancel awaiting proposals.
*/
// solhint-disable-next-line func-name-mixedcase
function __MentoTimelockController_init(
uint256 minDelay,
address[] memory proposers,
Expand Down
2 changes: 1 addition & 1 deletion slither.db.json

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions test/governance/MentoGovernor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ contract MentoGovernorTest is TestSetup {
MockOwnable public mockOwnable;
MockVeMento public mockVeMento;

uint256 private _votingDelay;
uint256 private _votingPeriod;
uint256 private _threshold;
uint256 public votingDelay;
uint256 public votingPeriod;
uint256 public threshold;

address public communityMultisig = makeAddr("communityMultisig");

Expand Down Expand Up @@ -49,15 +49,15 @@ contract MentoGovernorTest is TestSetup {

vm.stopPrank();

_votingDelay = mentoGovernor.votingDelay();
_votingPeriod = mentoGovernor.votingPeriod();
_threshold = mentoGovernor.proposalThreshold();
votingDelay = mentoGovernor.votingDelay();
votingPeriod = mentoGovernor.votingPeriod();
threshold = mentoGovernor.proposalThreshold();
}

function test_init_shouldSetStateCorrectly() public {
assertEq(_votingDelay, BLOCKS_DAY);
assertEq(_votingPeriod, BLOCKS_WEEK);
assertEq(_threshold, 1_000e18);
assertEq(votingDelay, BLOCKS_DAY);
assertEq(votingPeriod, BLOCKS_WEEK);
assertEq(threshold, 1_000e18);
assertEq(timelockController.getMinDelay(), 1 days);
}

Expand All @@ -79,7 +79,7 @@ contract MentoGovernorTest is TestSetup {
vm.expectRevert("Governor: proposer votes below proposal threshold");
_proposeCallProtectedFunction();

mockVeMento.mint(alice, _threshold - 1e18);
mockVeMento.mint(alice, threshold - 1e18);
vm.expectRevert("Governor: proposer votes below proposal threshold");
_proposeCallProtectedFunction();

Expand All @@ -91,7 +91,7 @@ contract MentoGovernorTest is TestSetup {
}

function test_propose_whenProposerAboveThreshold_shouldCreateProposal() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);

vm.prank(alice);
(
Expand All @@ -108,7 +108,7 @@ contract MentoGovernorTest is TestSetup {
}

function test_castVote_whenInVotingDelay_shouldRevert() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);

vm.prank(alice);
(uint256 proposalId, , , , ) = _proposeCallProtectedFunction();
Expand All @@ -119,11 +119,11 @@ contract MentoGovernorTest is TestSetup {
}

function test_castVote_whenVotingPeriodEnds_shouldRevert() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
vm.prank(alice);
(uint256 proposalId, , , , ) = _proposeCallProtectedFunction();

vm.roll(block.number + _votingDelay + _votingPeriod + 1);
vm.roll(block.number + votingDelay + votingPeriod + 1);

assertEq(uint256(mentoGovernor.state(proposalId)), 3); // defeated

Expand All @@ -133,49 +133,49 @@ contract MentoGovernorTest is TestSetup {
}

function test_castVote_whenNotEnoughForVotes_shouldDefeatProposal() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 1_001e18);

vm.prank(alice);
(uint256 proposalId, , , , ) = _proposeCallProtectedFunction();

vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);

vm.prank(bob);
mentoGovernor.castVote(proposalId, 1);
vm.prank(charlie);
mentoGovernor.castVote(proposalId, 0);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
assertEq(uint256(mentoGovernor.state(proposalId)), 3); // defeated
}

function test_castVote_whenNoQuorum_shouldDefeatProposal() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 100e18);

vm.prank(alice);
(uint256 proposalId, , , , ) = _proposeCallProtectedFunction();

vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);

vm.prank(bob);
mentoGovernor.castVote(proposalId, 1);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
assertEq(uint256(mentoGovernor.state(proposalId)), 3); // defeated
}

function test_castVote_whenEnoughQuorumAndForVotes_shouldSucceedProposal() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 2_000e18);

vm.prank(alice);
(uint256 proposalId, , , , ) = _proposeCallProtectedFunction();

vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);

assertEq(uint256(mentoGovernor.state(proposalId)), 1); // active

Expand All @@ -184,12 +184,12 @@ contract MentoGovernorTest is TestSetup {
vm.prank(charlie);
mentoGovernor.castVote(proposalId, 1);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
assertEq(uint256(mentoGovernor.state(proposalId)), 4); // succeeded
}

function test_queueAndExecute_whenNotCorrectState_shouldRevert() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 2_000e18);

Expand All @@ -209,7 +209,7 @@ contract MentoGovernorTest is TestSetup {
mentoGovernor.execute(targets, values, calldatas, keccak256(bytes(description)));

// keeping block.ts and block.number in sync
vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);
vm.warp(block.timestamp + 1 days);

vm.expectRevert("Governor: proposal not successful");
Expand All @@ -230,7 +230,7 @@ contract MentoGovernorTest is TestSetup {
vm.expectRevert("Governor: proposal not successful");
mentoGovernor.execute(targets, values, calldatas, keccak256(bytes(description)));

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
vm.warp(block.timestamp + 7 days);

vm.expectRevert("Governor: proposal not successful");
Expand All @@ -241,7 +241,7 @@ contract MentoGovernorTest is TestSetup {
}

function test_execute_whenTimelocked_shouldRevert() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 2_000e18);

Expand All @@ -255,7 +255,7 @@ contract MentoGovernorTest is TestSetup {
) = _proposeCallProtectedFunction();

// keeping block.ts and block.number in sync
vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);
vm.warp(block.timestamp + 1 days);

vm.prank(bob);
Expand All @@ -264,7 +264,7 @@ contract MentoGovernorTest is TestSetup {
vm.prank(charlie);
mentoGovernor.castVote(proposalId, 1);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
vm.warp(block.timestamp + 7 days);

mentoGovernor.queue(targets, values, calldatas, keccak256(bytes(description)));
Expand All @@ -274,7 +274,7 @@ contract MentoGovernorTest is TestSetup {
}

function test_execute_shouldExecuteProposal_whenTimelockExpires() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 2_000e18);

Expand All @@ -288,7 +288,7 @@ contract MentoGovernorTest is TestSetup {
) = _proposeCallProtectedFunction();

// keeping block.ts and block.number in sync
vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);
vm.warp(block.timestamp + 1 days);

vm.prank(bob);
Expand All @@ -297,7 +297,7 @@ contract MentoGovernorTest is TestSetup {
vm.prank(charlie);
mentoGovernor.castVote(proposalId, 1);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
vm.warp(block.timestamp + 7 days);

mentoGovernor.queue(targets, values, calldatas, keccak256(bytes(description)));
Expand All @@ -313,7 +313,7 @@ contract MentoGovernorTest is TestSetup {
}

function test_queueAndexecute_whenRetried_shouldRevert() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 2_000e18);

Expand All @@ -327,7 +327,7 @@ contract MentoGovernorTest is TestSetup {
) = _proposeCallProtectedFunction();

// keeping block.ts and block.number in sync
vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);
vm.warp(block.timestamp + 1 days);

vm.prank(bob);
Expand All @@ -336,7 +336,7 @@ contract MentoGovernorTest is TestSetup {
vm.prank(charlie);
mentoGovernor.castVote(proposalId, 1);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
vm.warp(block.timestamp + 7 days);

mentoGovernor.queue(targets, values, calldatas, keccak256(bytes(description)));
Expand All @@ -358,7 +358,7 @@ contract MentoGovernorTest is TestSetup {
}

function test_cancel_whenCalledByCanceller_shouldBlockQueuedProposal() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 2_000e18);

Expand All @@ -374,7 +374,7 @@ contract MentoGovernorTest is TestSetup {
bytes32 tlId = timelockController.hashOperationBatch(targets, values, calldatas, 0, keccak256(bytes(description)));

// keeping block.ts and block.number in sync
vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);
vm.warp(block.timestamp + 1 days);

vm.prank(bob);
Expand All @@ -383,7 +383,7 @@ contract MentoGovernorTest is TestSetup {
vm.prank(charlie);
mentoGovernor.castVote(proposalId, 1);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
vm.warp(block.timestamp + 7 days);

mentoGovernor.queue(targets, values, calldatas, keccak256(bytes(description)));
Expand All @@ -403,7 +403,7 @@ contract MentoGovernorTest is TestSetup {
}

function test_cancel_whenCalledBeforeQueue_shouldRevert() public {
mockVeMento.mint(alice, _threshold);
mockVeMento.mint(alice, threshold);
mockVeMento.mint(bob, 1_000e18);
mockVeMento.mint(charlie, 2_000e18);

Expand All @@ -423,7 +423,7 @@ contract MentoGovernorTest is TestSetup {
timelockController.cancel(tlId);

// keeping block.ts and block.number in sync
vm.roll(block.number + _votingDelay + 1);
vm.roll(block.number + votingDelay + 1);
vm.warp(block.timestamp + 1 days);

vm.prank(communityMultisig);
Expand All @@ -440,7 +440,7 @@ contract MentoGovernorTest is TestSetup {
vm.expectRevert("TimelockController: operation cannot be cancelled");
timelockController.cancel(tlId);

vm.roll(block.number + _votingPeriod);
vm.roll(block.number + votingPeriod);
vm.warp(block.timestamp + 7 days);

vm.prank(communityMultisig);
Expand Down

0 comments on commit e1bd8a3

Please sign in to comment.