From 3ed2b4685c5070bb3833a9dab27e91af4fe60792 Mon Sep 17 00:00:00 2001 From: David Laprade Date: Tue, 10 Dec 2024 15:54:19 -0500 Subject: [PATCH] Simulate the passage of time --- test/FlexVotingClient.invariants.t.sol | 17 +++++++++-------- test/handlers/FlexVotingClientHandler.sol | 8 ++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/test/FlexVotingClient.invariants.t.sol b/test/FlexVotingClient.invariants.t.sol index 9e44e50..b78308e 100644 --- a/test/FlexVotingClient.invariants.t.sol +++ b/test/FlexVotingClient.invariants.t.sol @@ -40,12 +40,13 @@ contract FlexVotingInvariantSetup is Test { // Proposal will underflow if we're on the zero block. if (block.number == 0) vm.roll(1); - bytes4[] memory selectors = new bytes4[](5); + bytes4[] memory selectors = new bytes4[](6); selectors[0] = FlexVotingClientHandler.deposit.selector; selectors[1] = FlexVotingClientHandler.propose.selector; selectors[2] = FlexVotingClientHandler.expressVote.selector; selectors[3] = FlexVotingClientHandler.castVote.selector; selectors[4] = FlexVotingClientHandler.withdraw.selector; + selectors[5] = FlexVotingClientHandler.roll.selector; targetSelector(FuzzSelector({addr: address(handler), selectors: selectors})); targetContract(address(handler)); @@ -53,13 +54,13 @@ contract FlexVotingInvariantSetup is Test { } contract FlexVotingInvariantTest is FlexVotingInvariantSetup { - // // We want to make sure that things like this cannot happen: - // // - user A deposits X - // // - user A expresses FOR on proposal P - // // - castVote is called for P, user A's votes are cast - // // - stuff we can't imagine happens... - // // - user A expresses again on proposal P - // // - castVote is called for P, user A gets more votes through + // We want to make sure that things like this cannot happen: + // - user A deposits X + // - user A expresses FOR on proposal P + // - castVote is called for P, user A's votes are cast + // - stuff we can't imagine happens... + // - user A expresses again on proposal P + // - castVote is called for P, user A gets more votes through function invariant_OneVotePerActorPerProposal() public view { handler.callSummary(); diff --git a/test/handlers/FlexVotingClientHandler.sol b/test/handlers/FlexVotingClientHandler.sol index b2ed156..d973141 100644 --- a/test/handlers/FlexVotingClientHandler.sol +++ b/test/handlers/FlexVotingClientHandler.sol @@ -179,6 +179,13 @@ contract FlexVotingClientHandler is Test { return actors.length(); } + // Simulate the passage of time, which materially changes governance behavior. + function roll(uint256 _seed) external countCall("roll") { + vm.assume(proposals.length() > 0); + uint256 _blocks = _bound(_seed, 1, governor.votingPeriod() / 10); + vm.roll(block.number + _blocks); + } + // TODO This always creates a new actor. Should it? function deposit(uint208 _amount) external @@ -341,6 +348,7 @@ contract FlexVotingClientHandler is Test { console2.log("expressVote:", calls["expressVote"].count); console2.log("castVote:", calls["castVote"].count); console2.log("propose:", calls["propose"].count); + console2.log("roll:", calls["roll"].count); console2.log("-------------------"); console2.log("actor count:", actors.length()); console2.log("voter count:", voters.length());