GovernorSuperQuorumGreaterThanQuorum.t.sol 3.2 KB

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