Skip to content

Commit

Permalink
testFuzz_RevertIf_StakeIsStillLocked
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 27, 2024
1 parent 989a1d4 commit d33800b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,25 @@ contract Staking is ERC20VotesUpgradeable, Ownable2StepUpgradeable {
}

// Checks below only apply if keyper is still a keyper
// if keyper is not a keyper anymore, anyone can unstake, lock period is
// if keyper is not a keyper anymore, anyone can unstake for them, lock period is
// ignored and minStake is not enforced
if (keypers[keyper]) {
// Only the keyper can unstake
require(msg.sender == keyper, OnlyKeyper());

// If the lock period is less than the global lock period, the stake
// must be locked for the lock period
if (lockPeriod < keyperStake.lockPeriod) {
require(
keyperStake.timestamp + lockPeriod <= block.timestamp,
block.timestamp > keyperStake.timestamp + lockPeriod,
StakeIsStillLocked()
);
} else {
// If the global lock period is greater than the stake lock period,
// the stake must be locked for the stake lock period
require(
keyperStake.timestamp + keyperStake.lockPeriod <=
block.timestamp,
block.timestamp >
keyperStake.timestamp + keyperStake.lockPeriod,
StakeIsStillLocked()
);
}
Expand Down
8 changes: 4 additions & 4 deletions test/Staking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,13 @@ contract Unstake is StakingTest {
_mintGovToken(_depositor, _amount);
_setKeyper(_depositor, true);

uint256 stakeIndex = _stake(_depositor, _amount);
uint256 stakeId = _stake(_depositor, _amount);

_jumpAhead(_jump);

vm.prank(_depositor);
vm.expectRevert(Staking.StakeIsStillLocked.selector);
staking.unstake(_depositor, stakeIndex, 0);
staking.unstake(_depositor, stakeId, 0);
}

function testFuzz_RevertIf_StakeIsStillLockedAfterLockPeriodChangedToLessThanCurrent(
Expand All @@ -1147,15 +1147,15 @@ contract Unstake is StakingTest {
uint256 _jump
) public {
_amount = _boundToRealisticStake(_amount);
_jump = bound(_jump, vm.getBlockTimestamp(), LOCK_PERIOD);
_jump = bound(_jump, vm.getBlockTimestamp(), LOCK_PERIOD - 1);

_mintGovToken(_depositor, _amount);
_setKeyper(_depositor, true);

uint256 stakeIndex = _stake(_depositor, _amount);

staking.setLockPeriod(_jump);
_jumpAhead(_jump - 1);
_jumpAhead(_jump);

vm.prank(_depositor);
vm.expectRevert(Staking.StakeIsStillLocked.selector);
Expand Down

0 comments on commit d33800b

Please sign in to comment.