Skip to content

Commit

Permalink
Assemble the v1 Governor w/ constructor test
Browse files Browse the repository at this point in the history
  • Loading branch information
apbendi committed Nov 8, 2023
1 parent 1c60924 commit ccee29c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 9 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
optimizer = true
optimizer_runs = 10_000_000
remappings = [
"@openzeppelin/contracts/=lib/flexible-voting/lib/openzeppelin-contracts/contracts",
"@openzeppelin/=lib/flexible-voting/lib/openzeppelin-contracts/contracts",
"flexible-voting/=lib/flexible-voting/src",
]
solc_version = "0.8.22"
Expand Down
119 changes: 118 additions & 1 deletion src/GuineaPigGovernor.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,121 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

contract GuineaPigGovernor {}
import {
Governor, GovernorCountingFractional
} from "flexible-voting/GovernorCountingFractional.sol";
import {IGovernor} from "@openzeppelin/contracts/governance/IGovernor.sol";
import {GovernorVotes} from "@openzeppelin/governance/extensions/GovernorVotes.sol";
import {GovernorTimelockControl} from
"@openzeppelin/governance/extensions/GovernorTimelockControl.sol";
import {GovernorSettings} from "@openzeppelin/governance/extensions/GovernorSettings.sol";
import {IVotes} from "@openzeppelin/governance/utils/IVotes.sol";
// TODO: convert to interface?
import {TimelockController} from "@openzeppelin/governance/TimelockController.sol";

contract GuineaPigGovernor is
GovernorCountingFractional,
GovernorVotes,
GovernorTimelockControl,
GovernorSettings
{
/// @notice Human readable name of this Governor.
string private constant GOVERNOR_NAME = "Guinea Pig DAO Governor v1";

constructor(
IVotes _token,
uint256 _initialVotingDelay,
uint256 _initialVotingPeriod,
uint256 _initialProposalThreshold,
TimelockController _timelock
)
GovernorVotes(_token)
GovernorSettings(_initialVotingDelay, _initialVotingPeriod, _initialProposalThreshold)
GovernorTimelockControl(_timelock)
Governor(GOVERNOR_NAME)
{}

/// @dev We override this function to resolve ambiguity between inherited contracts.
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(Governor, GovernorTimelockControl)
returns (bool)
{
return GovernorTimelockControl.supportsInterface(interfaceId);
}

/// @dev We override this function to resolve ambiguity between inherited contracts.
function castVoteWithReasonAndParamsBySig(
uint256 proposalId,
uint8 support,
string calldata reason,
bytes memory params,
uint8 v,
bytes32 r,
bytes32 s
) public override(Governor, GovernorCountingFractional, IGovernor) returns (uint256) {
return GovernorCountingFractional.castVoteWithReasonAndParamsBySig(
proposalId, support, reason, params, v, r, s
);
}

/// @dev We override this function to resolve ambiguity between inherited contracts.
function proposalThreshold()
public
view
virtual
override(Governor, GovernorSettings)
returns (uint256)
{
return GovernorSettings.proposalThreshold();
}

/// @dev We override this function to resolve ambiguity between inherited contracts.
function state(uint256 proposalId)
public
view
virtual
override(Governor, GovernorTimelockControl)
returns (ProposalState)
{
return GovernorTimelockControl.state(proposalId);
}

function quorum(uint256) public pure override returns (uint256) {
return 1; // TODO: determine quorum rules
}

/// @dev We override this function to resolve ambiguity between inherited contracts.
function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override(Governor, GovernorTimelockControl) {
return GovernorTimelockControl._execute(proposalId, targets, values, calldatas, descriptionHash);
}

/// @dev We override this function to resolve ambiguity between inherited contracts.
function _executor()
internal
view
virtual
override(Governor, GovernorTimelockControl)
returns (address)
{
return GovernorTimelockControl._executor();
}

/// @dev We override this function to resolve ambiguity between inherited contracts.
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override(Governor, GovernorTimelockControl) returns (uint256) {
return GovernorTimelockControl._cancel(targets, values, calldatas, descriptionHash);
}
}
6 changes: 1 addition & 5 deletions src/GuineaPigToken.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import {
ERC20Votes,
ERC20Permit,
ERC20
} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
import {ERC20Votes, ERC20Permit, ERC20} from "@openzeppelin/token/ERC20/extensions/ERC20Votes.sol";

import {AccessControlEnumerable} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol";

Expand Down
25 changes: 23 additions & 2 deletions test/GuineaPigGovernor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@
pragma solidity 0.8.22;

import {Test, console2} from "forge-std/Test.sol";
import {GuineaPigGovernor, IVotes, TimelockController} from "src/GuineaPigGovernor.sol";

contract GuineaPigGovernorTest is Test {
function setUp() public {}
GuineaPigGovernor governor;

IVotes token = IVotes(address(0x01b));
TimelockController timelock = TimelockController(payable(address(0x01c)));

uint256 INITIAL_VOTING_DELAY = 50;
uint256 INITIAL_VOTING_PERIOD = 7200;
uint256 INITIAL_PROPOSAL_THRESHOLD = 100_000e18;

function setUp() public {
governor =
new GuineaPigGovernor(token, INITIAL_VOTING_DELAY, INITIAL_VOTING_PERIOD, INITIAL_PROPOSAL_THRESHOLD, timelock);
}
}

contract Deployment is GuineaPigGovernorTest {}
contract Constructor is GuineaPigGovernorTest {
function test_ConstructorArgumentsSetCorrectly() public {
assertEq(governor.votingDelay(), INITIAL_VOTING_DELAY);
assertEq(governor.votingPeriod(), INITIAL_VOTING_PERIOD);
assertEq(governor.proposalThreshold(), INITIAL_PROPOSAL_THRESHOLD);
assertEq(governor.timelock(), address(timelock));
assertEq(address(governor.token()), address(token));
}
}

0 comments on commit ccee29c

Please sign in to comment.