GovernorSuperQuorumGreaterThanQuorum.t.sol 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {Test} from "forge-std/Test.sol";
  4. import {GovernorVotesSuperQuorumFractionMock} from "../../../contracts/mocks/governance/GovernorVotesSuperQuorumFractionMock.sol";
  5. import {GovernorVotesQuorumFraction} from "../../../contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
  6. import {GovernorVotesSuperQuorumFraction} from "../../../contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol";
  7. import {GovernorSettings} from "../../../contracts/governance/extensions/GovernorSettings.sol";
  8. import {GovernorVotes} from "../../../contracts/governance/extensions/GovernorVotes.sol";
  9. import {Governor} from "../../../contracts/governance/Governor.sol";
  10. import {IVotes} from "../../../contracts/governance/utils/IVotes.sol";
  11. import {ERC20VotesExtendedTimestampMock} from "../../../contracts/mocks/token/ERC20VotesAdditionalCheckpointsMock.sol";
  12. import {EIP712} from "../../../contracts/utils/cryptography/EIP712.sol";
  13. import {ERC20} from "../../../contracts/token/ERC20/ERC20.sol";
  14. contract TokenMock is ERC20VotesExtendedTimestampMock {
  15. constructor() ERC20("Mock Token", "MTK") EIP712("Mock Token", "1") {}
  16. }
  17. /**
  18. * Main responsibility: expose the functions that are relevant to the simulation
  19. */
  20. contract GovernorHandler is GovernorVotesSuperQuorumFractionMock {
  21. constructor(
  22. string memory name_,
  23. uint48 votingDelay_,
  24. uint32 votingPeriod_,
  25. uint256 proposalThreshold_,
  26. IVotes token_,
  27. uint256 quorumNumerator_,
  28. uint256 superQuorumNumerator_
  29. )
  30. Governor(name_)
  31. GovernorSettings(votingDelay_, votingPeriod_, proposalThreshold_)
  32. GovernorVotes(token_)
  33. GovernorVotesQuorumFraction(quorumNumerator_)
  34. GovernorVotesSuperQuorumFraction(superQuorumNumerator_)
  35. {}
  36. // solhint-disable-next-line func-name-mixedcase
  37. function $_updateSuperQuorumNumerator(uint256 newSuperQuorumNumerator) public {
  38. _updateSuperQuorumNumerator(newSuperQuorumNumerator);
  39. }
  40. // solhint-disable-next-line func-name-mixedcase
  41. function $_updateQuorumNumerator(uint256 newQuorumNumerator) public {
  42. _updateQuorumNumerator(newQuorumNumerator);
  43. }
  44. }
  45. contract GovernorSuperQuorumGreaterThanQuorum is Test {
  46. GovernorHandler private _governorHandler;
  47. function setUp() external {
  48. _governorHandler = new GovernorHandler(
  49. "GovernorName",
  50. 0, // votingDelay
  51. 1e4, // votingPeriod
  52. 0, // proposalThreshold
  53. new TokenMock(), // token
  54. 10, // quorumNumerator
  55. 50 // superQuorumNumerator
  56. );
  57. // limit the fuzzer scope
  58. bytes4[] memory selectors = new bytes4[](2);
  59. selectors[0] = GovernorHandler.$_updateSuperQuorumNumerator.selector;
  60. selectors[1] = GovernorHandler.$_updateQuorumNumerator.selector;
  61. targetContract(address(_governorHandler));
  62. targetSelector(FuzzSelector(address(_governorHandler), selectors));
  63. }
  64. // solhint-disable-next-line func-name-mixedcase
  65. function invariant_superQuorumGreaterThanQuorum() external view {
  66. assertGe(_governorHandler.superQuorumNumerator(), _governorHandler.quorumNumerator());
  67. }
  68. }