Skip to content

Commit

Permalink
GovernorExtendedVoting testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Nov 16, 2021
1 parent ff0d213 commit 7b64140
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 86 deletions.
54 changes: 54 additions & 0 deletions contracts/mocks/GovernorExtendedVotingMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./GovernorMock.sol";
import "../governance/extensions/GovernorExtendedVoting.sol";

contract GovernorExtendedVotingMock is GovernorMock, GovernorExtendedVoting {
uint256 private _quorum;

constructor(
string memory name_,
ERC20Votes token_,
uint256 votingDelay_,
uint256 votingPeriod_,
uint256 quorum_,
uint64 votingDelayExtention_
)
GovernorMock(name_, token_, votingDelay_, votingPeriod_, 0)
GovernorExtendedVoting(votingDelayExtention_)
{
_quorum = quorum_;
}

function quorum(uint256) public view virtual override returns (uint256) {
return _quorum;
}

function proposalDeadline(uint256 proposalId) public view virtual override(Governor, GovernorExtendedVoting) returns (uint256) {
return super.proposalDeadline(proposalId);
}

function proposalThreshold() public view virtual override(Governor, GovernorMock) returns (uint256) {
return super.proposalThreshold();
}

function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual override(Governor, GovernorMock) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}

function _castVote(
uint256 proposalId,
address account,
uint8 support,
string memory reason
) internal virtual override(Governor, GovernorExtendedVoting) returns (uint256) {
return super._castVote(proposalId, account, support, reason);
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/GovernorMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract GovernorMock is
return super.getVotes(account, blockNumber);
}

function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
function proposalThreshold() public view virtual override(Governor, GovernorSettings) returns (uint256) {
return super.proposalThreshold();
}

Expand Down
46 changes: 4 additions & 42 deletions contracts/mocks/GovernorTimelockCompoundMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

pragma solidity ^0.8.0;

import "./GovernorMock.sol";
import "../governance/extensions/GovernorTimelockCompound.sol";
import "../governance/extensions/GovernorSettings.sol";
import "../governance/extensions/GovernorCountingSimple.sol";
import "../governance/extensions/GovernorVotesQuorumFraction.sol";

contract GovernorTimelockCompoundMock is
GovernorSettings,
GovernorTimelockCompound,
GovernorVotesQuorumFraction,
GovernorCountingSimple
{
contract GovernorTimelockCompoundMock is GovernorMock, GovernorTimelockCompound {
constructor(
string memory name_,
ERC20Votes token_,
Expand All @@ -21,11 +14,8 @@ contract GovernorTimelockCompoundMock is
ICompoundTimelock timelock_,
uint256 quorumNumerator_
)
Governor(name_)
GovernorMock(name_, token_, votingDelay_, votingPeriod_, quorumNumerator_)
GovernorTimelockCompound(timelock_)
GovernorSettings(votingDelay_, votingPeriod_, 0)
GovernorVotes(token_)
GovernorVotesQuorumFraction(quorumNumerator_)
{}

function supportsInterface(bytes4 interfaceId)
Expand All @@ -38,24 +28,6 @@ contract GovernorTimelockCompoundMock is
return super.supportsInterface(interfaceId);
}

function quorum(uint256 blockNumber)
public
view
override(IGovernor, GovernorVotesQuorumFraction)
returns (uint256)
{
return super.quorum(blockNumber);
}

function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 salt
) public returns (uint256 proposalId) {
return _cancel(targets, values, calldatas, salt);
}

/**
* Overriding nightmare
*/
Expand All @@ -69,7 +41,7 @@ contract GovernorTimelockCompoundMock is
return super.state(proposalId);
}

function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
function proposalThreshold() public view override(Governor, GovernorMock) returns (uint256) {
return super.proposalThreshold();
}

Expand All @@ -92,16 +64,6 @@ contract GovernorTimelockCompoundMock is
return super._cancel(targets, values, calldatas, salt);
}

function getVotes(address account, uint256 blockNumber)
public
view
virtual
override(IGovernor, GovernorVotes)
returns (uint256)
{
return super.getVotes(account, blockNumber);
}

function _executor() internal view virtual override(Governor, GovernorTimelockCompound) returns (address) {
return super._executor();
}
Expand Down
46 changes: 4 additions & 42 deletions contracts/mocks/GovernorTimelockControlMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

pragma solidity ^0.8.0;

import "./GovernorMock.sol";
import "../governance/extensions/GovernorTimelockControl.sol";
import "../governance/extensions/GovernorSettings.sol";
import "../governance/extensions/GovernorCountingSimple.sol";
import "../governance/extensions/GovernorVotesQuorumFraction.sol";

contract GovernorTimelockControlMock is
GovernorSettings,
GovernorTimelockControl,
GovernorVotesQuorumFraction,
GovernorCountingSimple
{
contract GovernorTimelockControlMock is GovernorMock, GovernorTimelockControl {
constructor(
string memory name_,
ERC20Votes token_,
Expand All @@ -21,11 +14,8 @@ contract GovernorTimelockControlMock is
TimelockController timelock_,
uint256 quorumNumerator_
)
Governor(name_)
GovernorMock(name_, token_, votingDelay_, votingPeriod_, quorumNumerator_)
GovernorTimelockControl(timelock_)
GovernorSettings(votingDelay_, votingPeriod_, 0)
GovernorVotes(token_)
GovernorVotesQuorumFraction(quorumNumerator_)
{}

function supportsInterface(bytes4 interfaceId)
Expand All @@ -38,24 +28,6 @@ contract GovernorTimelockControlMock is
return super.supportsInterface(interfaceId);
}

function quorum(uint256 blockNumber)
public
view
override(IGovernor, GovernorVotesQuorumFraction)
returns (uint256)
{
return super.quorum(blockNumber);
}

function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public returns (uint256 proposalId) {
return _cancel(targets, values, calldatas, descriptionHash);
}

/**
* Overriding nightmare
*/
Expand All @@ -69,7 +41,7 @@ contract GovernorTimelockControlMock is
return super.state(proposalId);
}

function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
function proposalThreshold() public view override(Governor, GovernorMock) returns (uint256) {
return super.proposalThreshold();
}

Expand All @@ -92,16 +64,6 @@ contract GovernorTimelockControlMock is
return super._cancel(targets, values, calldatas, descriptionHash);
}

function getVotes(address account, uint256 blockNumber)
public
view
virtual
override(IGovernor, GovernorVotes)
returns (uint256)
{
return super.getVotes(account, blockNumber);
}

function _executor() internal view virtual override(Governor, GovernorTimelockControl) returns (address) {
return super._executor();
}
Expand Down
2 changes: 1 addition & 1 deletion test/governance/GovernorWorkflow.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function runGovernorWorkflow () {
// vote
if (tryGet(this.settings, 'voters')) {
this.receipts.castVote = [];
for (const voter of this.settings.voters) {
for (const voter of this.settings.voters.filter(({ support }) => !!support)) {
if (!voter.signature) {
this.receipts.castVote.push(
await getReceiptOrRevert(
Expand Down
Loading

0 comments on commit 7b64140

Please sign in to comment.