Skip to content

Commit

Permalink
WIP nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkeating committed Mar 15, 2024
1 parent 489f4d6 commit bb885eb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/UniStaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
emit RewardNotified(_amount, msg.sender);
}

function invalidateNonce() external {
_useNonce(msg.sender);
}

/// @notice Internal method which finds the existing surrogate contract—or deploys a new one if
/// none exists—for a given delegatee.
/// @param _delegatee Account for which a surrogate is sought.
Expand Down
44 changes: 44 additions & 0 deletions test/UniStaker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,50 @@ contract SetAdmin is UniStakerTest {
}
}

contract InvalidateNonce is UniStakerTest {
using stdStorage for StdStorage;

// Calll increments nonce
function testFuzz_SucessfullyInvalidateNonceForMsgSender(address _caller, uint256 _initialNonce) public {
vm.assume(_caller != address(0));
vm.assume(_initialNonce != type(uint256).max);

// Set nonces in storage assert incremented by one
stdstore
.target(address(uniStaker))
.sig("nonces(address)")
.with_key(_caller)
.checked_write(_initialNonce);

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

uint256 currentNonce = uniStaker.nonces(_caller);

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

// Outside nonce owner cannot updateNonce
function testFuzz_NeedName(address _caller, address _nonceOwner, uint256 _initialNonce) public {
vm.assume(_caller != address(0));
vm.assume(_initialNonce != type(uint256).max);

// Set nonces in storage assert incremented by one
stdstore
.target(address(uniStaker))
.sig("nonces(address)")
.with_key(_nonceOwner)
.checked_write(_initialNonce);

vm.prank(_caller);
uniStaker.invalidateNonce();
}

// It can be called multiple times
// It will invalidate StakeOnBehalf
// It will invalidate other stake on behalf methods
}

contract UniStakerRewardsTest is UniStakerTest {
// Helper methods for dumping contract state related to rewards calculation for debugging
function __dumpDebugGlobalRewards() public view {
Expand Down

0 comments on commit bb885eb

Please sign in to comment.