Skip to content

Commit

Permalink
test(StakeManager): honor lockup period when unstaking
Browse files Browse the repository at this point in the history
This adds a test to check that the lockup period is considered when a
user tries to unstake their funds through their vault.
  • Loading branch information
0x-r4bbit committed Jan 12, 2024
1 parent 7cb8591 commit fb00fc1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/StakeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,29 @@ contract UserFlowsTest is StakeManagerTest {
assertEq(ERC20(stakeToken).balanceOf(address(user2Vault)), 0);
assertEq(stakeManager.stakeSupply(), 0);
}

function test_StakeWithLockUpTimeLocksStake() public {
// ensure users have funds
deal(stakeToken, testUser, 1000);

StakeVault userVault = _createTestVault(testUser);

vm.startPrank(testUser);
// approve user vault to spend user tokens
ERC20(stakeToken).approve(address(userVault), 100);

// stake with lockup time of 12 weeks
userVault.stake(100, 12 weeks);

// unstaking should fail as lockup time isn't over yet
vm.expectRevert(StakeManager.StakeManager__FundsLocked.selector);
userVault.unstake(100);

// fast forward 12 weeks
skip(12 weeks + 1);

userVault.unstake(100);
assertEq(ERC20(stakeToken).balanceOf(address(userVault)), 0);
assertEq(stakeManager.stakeSupply(), 0);
}
}

0 comments on commit fb00fc1

Please sign in to comment.