Skip to content

Commit cdae2b1

Browse files
committed
test(StakeManager): add test to catch bug in minting more bonus MPs when stake with lock
1 parent b19182a commit cdae2b1

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

.vscode/settings.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2+
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
3+
"solidity.packageDefaultDependenciesDirectory": "lib",
4+
"editor.formatOnSave": true,
25
"[solidity]": {
3-
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
4-
},
5-
"[toml]": {
6-
"editor.defaultFormatter": "tamasfe.even-better-toml"
6+
"editor.defaultFormatter": "JuanBlanco.solidity"
77
},
88
"npm.exclude": "**/lib/**",
9-
"solidity.formatter": "forge"
9+
"solidity.formatter": "forge",
10+
"solidity.remappings": [],
11+
"solidity.compileUsingRemoteVersion": "0.8.20"
1012
}

test/StakeManager.t.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@ contract StakeTest is StakeManagerTest {
8787
stakeManager.stake(100, 1);
8888
}
8989

90+
function test_StakeWithLockBonusMP() public {
91+
uint256 stakeAmount = 10_000;
92+
uint256 lockTime = stakeManager.MIN_LOCKUP_PERIOD();
93+
94+
StakeVault userVault = _createStakingAccount(testUser, stakeAmount, 0, stakeAmount);
95+
96+
(, uint256 balance, uint256 bonusMP, uint256 totalMP,,,,) = stakeManager.accounts(address(userVault));
97+
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after stake");
98+
assertEq(bonusMP, stakeAmount, "bonusMP of user vault should be equal to stake amount after stake if no lock");
99+
assertEq(totalMP, bonusMP, "totalMP of user vault should be equal to bonusMP after stake if no epochs passed");
100+
101+
vm.prank(testUser);
102+
userVault.lock(lockTime);
103+
uint256 estimatedBonusMp = stakeAmount + stakeManager.calculateMPToMint(stakeAmount, lockTime);
104+
105+
(, balance, bonusMP, totalMP,,,,) = stakeManager.accounts(address(userVault));
106+
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after lock");
107+
assertEq(bonusMP, estimatedBonusMp, "bonusMP of user vault should be equal to estimated bonusMP after lock");
108+
assertEq(totalMP, bonusMP, "totalMP of user vault should be equal to bonusMP after lock if no epochs passed");
109+
110+
StakeVault userVault2 = _createStakingAccount(testUser, stakeAmount, lockTime, stakeAmount);
111+
112+
(, balance, bonusMP, totalMP,,,,) = stakeManager.accounts(address(userVault2));
113+
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after stake locked");
114+
assertEq(
115+
bonusMP, estimatedBonusMp, "bonusMP of user vault should be equal to estimated bonusMP after stake locked"
116+
);
117+
assertEq(
118+
totalMP, bonusMP, "totalMP of user vault should be equal to bonusMP after stake locked if no epochs passed"
119+
);
120+
}
121+
90122
function test_RevertWhen_InvalidLockupPeriod() public {
91123
// ensure user has funds
92124
deal(stakeToken, testUser, 1000);

0 commit comments

Comments
 (0)