test(StakeManager): honor lockup period when unstaking

This adds a test to check that the lockup period is considered when a
user tries to unstake their funds through their vault.
This commit is contained in:
r4bbit 2024-01-12 13:36:13 +01:00
parent 4e411f2b37
commit 300a296137
1 changed files with 25 additions and 0 deletions

View File

@ -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);
}
}