Skip to content

Commit

Permalink
test(StakeManager): add test to catch bug in minting more bonus MPs w…
Browse files Browse the repository at this point in the history
…hen stake with lock
  • Loading branch information
3esmit committed Sep 12, 2024
1 parent b19182a commit cdae2b1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
12 changes: 7 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
"solidity.packageDefaultDependenciesDirectory": "lib",
"editor.formatOnSave": true,
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
},
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
"editor.defaultFormatter": "JuanBlanco.solidity"
},
"npm.exclude": "**/lib/**",
"solidity.formatter": "forge"
"solidity.formatter": "forge",
"solidity.remappings": [],
"solidity.compileUsingRemoteVersion": "0.8.20"
}
32 changes: 32 additions & 0 deletions test/StakeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,38 @@ contract StakeTest is StakeManagerTest {
stakeManager.stake(100, 1);
}

function test_StakeWithLockBonusMP() public {
uint256 stakeAmount = 10_000;
uint256 lockTime = stakeManager.MIN_LOCKUP_PERIOD();

StakeVault userVault = _createStakingAccount(testUser, stakeAmount, 0, stakeAmount);

(, uint256 balance, uint256 bonusMP, uint256 totalMP,,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after stake");
assertEq(bonusMP, stakeAmount, "bonusMP of user vault should be equal to stake amount after stake if no lock");
assertEq(totalMP, bonusMP, "totalMP of user vault should be equal to bonusMP after stake if no epochs passed");

vm.prank(testUser);
userVault.lock(lockTime);
uint256 estimatedBonusMp = stakeAmount + stakeManager.calculateMPToMint(stakeAmount, lockTime);

(, balance, bonusMP, totalMP,,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after lock");
assertEq(bonusMP, estimatedBonusMp, "bonusMP of user vault should be equal to estimated bonusMP after lock");
assertEq(totalMP, bonusMP, "totalMP of user vault should be equal to bonusMP after lock if no epochs passed");

StakeVault userVault2 = _createStakingAccount(testUser, stakeAmount, lockTime, stakeAmount);

(, balance, bonusMP, totalMP,,,,) = stakeManager.accounts(address(userVault2));
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after stake locked");
assertEq(
bonusMP, estimatedBonusMp, "bonusMP of user vault should be equal to estimated bonusMP after stake locked"
);
assertEq(
totalMP, bonusMP, "totalMP of user vault should be equal to bonusMP after stake locked if no epochs passed"
);
}

function test_RevertWhen_InvalidLockupPeriod() public {
// ensure user has funds
deal(stakeToken, testUser, 1000);
Expand Down

0 comments on commit cdae2b1

Please sign in to comment.