Skip to content

Commit

Permalink
Simulate the passage of time
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlaprade committed Dec 10, 2024
1 parent a03cc50 commit 3ed2b46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test/FlexVotingClient.invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,27 @@ 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));
}
}

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();

Expand Down
8 changes: 8 additions & 0 deletions test/handlers/FlexVotingClientHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 3ed2b46

Please sign in to comment.