Skip to content

Commit

Permalink
Add invalidate nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkeating committed Mar 19, 2024
1 parent bc442e0 commit f56c174
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions test/UniStaker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2628,8 +2628,7 @@ contract SetAdmin is UniStakerTest {
contract InvalidateNonce is UniStakerTest {
using stdStorage for StdStorage;

// Calll increments nonce
function testFuzz_SucessfullyInvalidateNonceForMsgSender(address _caller, uint256 _initialNonce)
function testFuzz_SucessfullyInvalidatesNonceForMsgSender(address _caller, uint256 _initialNonce)
public
{
vm.assume(_caller != address(0));
Expand All @@ -2648,8 +2647,7 @@ contract InvalidateNonce is UniStakerTest {
assertEq(currentNonce, _initialNonce + 1, "Current nonce is incorrect");
}

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

Expand All @@ -2660,11 +2658,32 @@ contract InvalidateNonce is UniStakerTest {

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

uint256 currentNonce = uniStaker.nonces(_nonceOwner);

assertEq(currentNonce, _initialNonce);
}

// It can be called multiple times
// It will invalidate StakeOnBehalf
// It will invalidate other stake on behalf methods
function testFuzz_NonceIncrementsWhenCalledMultipleTimes(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();

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

uint256 currentNonce = uniStaker.nonces(_caller);

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

}
}

contract UniStakerRewardsTest is UniStakerTest {
Expand Down

0 comments on commit f56c174

Please sign in to comment.