Skip to content

Commit

Permalink
N03 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
wildmolasses authored Jul 1, 2024
1 parent 826e0d4 commit f21bc39
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/VotesPartialDelegationUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ abstract contract VotesPartialDelegationUpgradeable is
_delegate(_delegator, _partialDelegations);
}

/**
* @dev Allows an address to increment their nonce and therefore invalidate any pending signed
* actions.
*/
function invalidateNonce() external {
_useNonce(msg.sender);
}

/**
* @dev Delegate `_delegator`'s voting units to delegates specified in `_newDelegations`.
* Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
Expand Down
35 changes: 35 additions & 0 deletions test/ERC20VotesPartialDelegationUpgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,41 @@ contract DelegatePartiallyOnBehalf is PartialDelegationTest {
}
}

contract InvalidateNonce is PartialDelegationTest {
using stdStorage for StdStorage;

function testFuzz_SucessfullyIncrementsTheNonceOfTheSender(address _caller, uint256 _initialNonce) public {
vm.assume(_caller != address(0));
vm.assume(_initialNonce != type(uint256).max);

stdstore.target(address(tokenProxy)).sig("nonces(address)").with_key(_caller).checked_write(_initialNonce);

vm.prank(_caller);
tokenProxy.invalidateNonce();

uint256 currentNonce = tokenProxy.nonces(_caller);

assertEq(currentNonce, _initialNonce + 1, "Current nonce is incorrect");
}

function testFuzz_IncreasesTheNonceByTwoWhenCalledTwice(address _caller, uint256 _initialNonce) public {
vm.assume(_caller != address(0));
_initialNonce = bound(_initialNonce, 0, type(uint256).max - 2);

stdstore.target(address(tokenProxy)).sig("nonces(address)").with_key(_caller).checked_write(_initialNonce);

vm.prank(_caller);
tokenProxy.invalidateNonce();

vm.prank(_caller);
tokenProxy.invalidateNonce();

uint256 currentNonce = tokenProxy.nonces(_caller);

assertEq(currentNonce, _initialNonce + 2, "Current nonce is incorrect");
}
}

contract Transfer is PartialDelegationTest {
function testFuzz_MovesVotesFromOneDelegateeSetToAnother(
address _from,
Expand Down

0 comments on commit f21bc39

Please sign in to comment.