From 2e9db89709001301f393ea5ed31750714ecbb489 Mon Sep 17 00:00:00 2001 From: xavikh Date: Fri, 13 Dec 2024 14:48:17 +0100 Subject: [PATCH 1/3] Allow resets outside voting period --- src/voting/SimpleGaugeVoter.sol | 4 ++-- test/voting/GaugeVote.t.sol | 37 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/voting/SimpleGaugeVoter.sol b/src/voting/SimpleGaugeVoter.sol index a2aa905..7d1d8f3 100644 --- a/src/voting/SimpleGaugeVoter.sol +++ b/src/voting/SimpleGaugeVoter.sol @@ -81,7 +81,7 @@ contract SimpleGaugeVoter is } /*/////////////////////////////////////////////////////////////// - Voting + Voting //////////////////////////////////////////////////////////////*/ /// @notice extrememly simple for loop. We don't need reentrancy checks in this implementation @@ -181,7 +181,7 @@ contract SimpleGaugeVoter is voteData.lastVoted = block.timestamp; } - function reset(uint256 _tokenId) external nonReentrant whenNotPaused whenVotingActive { + function reset(uint256 _tokenId) external nonReentrant whenNotPaused { if (!IVotingEscrow(escrow).isApprovedOrOwner(msg.sender, _tokenId)) revert NotApprovedOrOwner(); if (!isVoting(_tokenId)) revert NotCurrentlyVoting(); diff --git a/test/voting/GaugeVote.t.sol b/test/voting/GaugeVote.t.sol index f5f225b..9698eb5 100644 --- a/test/voting/GaugeVote.t.sol +++ b/test/voting/GaugeVote.t.sol @@ -77,15 +77,44 @@ contract TestGaugeVote is GaugeVotingBase { vm.expectRevert(VotingInactive.selector); voter.vote(0, votes); - // try to reset - vm.expectRevert(VotingInactive.selector); - voter.reset(0); - // vote multiple vm.expectRevert(VotingInactive.selector); voter.voteMultiple(ids, votes); } + function testFuzz_canResetInDistributionPeriod() public { + // create the vote + votes.push(GaugeVote(1, gauge)); + + // vote + vm.startPrank(owner); + { + voter.vote(tokenId, votes); + } + vm.stopPrank(); + + // check the vote + assertEq(voter.isVoting(tokenId), true); + + // warp to the next epoch + vm.warp(block.timestamp + 1 weeks); + + vm.assume(!voter.votingActive()); + + // try to reset + vm.startPrank(owner); + { + voter.reset(tokenId); + } + vm.stopPrank(); + + assertEq(voter.isVoting(tokenId), false); + } + + //Check vp is 0 after reset + //Check gaugeVotes are same before and after reset, and are 0 after next voting period + // + // can't vote if you don't own the token function testCannotVoteIfYouDontOwnTheToken() public { // try to vote as this address (not the holder) From 997c9e718bfc396b2ba9b6a1663cd8c0313f89d6 Mon Sep 17 00:00:00 2001 From: xavikh Date: Fri, 13 Dec 2024 14:49:47 +0100 Subject: [PATCH 2/3] Fix comment --- test/voting/GaugeVote.t.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/voting/GaugeVote.t.sol b/test/voting/GaugeVote.t.sol index 9698eb5..61c4b33 100644 --- a/test/voting/GaugeVote.t.sol +++ b/test/voting/GaugeVote.t.sol @@ -96,9 +96,8 @@ contract TestGaugeVote is GaugeVotingBase { // check the vote assertEq(voter.isVoting(tokenId), true); - // warp to the next epoch + // warp to the next distribution period vm.warp(block.timestamp + 1 weeks); - vm.assume(!voter.votingActive()); // try to reset From 61cbba8e1dd183e660f36d6fe830aa5ce970fc46 Mon Sep 17 00:00:00 2001 From: xavikh Date: Fri, 13 Dec 2024 14:50:47 +0100 Subject: [PATCH 3/3] Cleanup comment --- test/voting/GaugeVote.t.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/voting/GaugeVote.t.sol b/test/voting/GaugeVote.t.sol index 61c4b33..aa51d0e 100644 --- a/test/voting/GaugeVote.t.sol +++ b/test/voting/GaugeVote.t.sol @@ -110,10 +110,6 @@ contract TestGaugeVote is GaugeVotingBase { assertEq(voter.isVoting(tokenId), false); } - //Check vp is 0 after reset - //Check gaugeVotes are same before and after reset, and are 0 after next voting period - // - // can't vote if you don't own the token function testCannotVoteIfYouDontOwnTheToken() public { // try to vote as this address (not the holder)