Skip to content

Commit 0c58dfe

Browse files
3esmit0x-r4bbit
authored andcommitted
test(StakeManager): add test to catch bug in minting more bonus MPs when stake with lock
1 parent 8683376 commit 0c58dfe

File tree

3 files changed

+66
-34
lines changed

3 files changed

+66
-34
lines changed

.gas-report

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
| contracts/StakeManager.sol:StakeManager contract | | | | | |
22
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
33
| Deployment Cost | Deployment Size | | | | |
4-
| 2930759 | 14950 | | | | |
4+
| 2914993 | 14877 | | | | |
55
| Function Name | min | avg | median | max | # calls |
66
| EPOCH_SIZE | 307 | 307 | 307 | 307 | 816 |
77
| MAX_BOOST | 285 | 285 | 285 | 285 | 1 |
88
| MAX_LOCKUP_PERIOD | 361 | 361 | 361 | 361 | 4 |
99
| MIN_LOCKUP_PERIOD | 287 | 287 | 287 | 287 | 11 |
1010
| YEAR | 263 | 263 | 263 | 263 | 1 |
11-
| accounts | 1597 | 1597 | 1597 | 1597 | 22879 |
11+
| accounts | 1597 | 1597 | 1597 | 1597 | 25030 |
1212
| calculateMPToMint | 740 | 740 | 740 | 740 | 3 |
1313
| currentEpoch | 406 | 1691 | 2406 | 2406 | 28 |
1414
| epochEnd | 627 | 639 | 627 | 4627 | 635 |
1515
| epochReward | 1403 | 2903 | 1403 | 5903 | 3 |
16-
| executeAccount | 28897 | 95329 | 95004 | 171987 | 20443 |
16+
| executeAccount | 28897 | 95308 | 95073 | 169064 | 22594 |
1717
| executeEpoch | 23436 | 169158 | 164483 | 204283 | 574 |
18-
| isVault | 540 | 571 | 540 | 2540 | 17938 |
18+
| isVault | 540 | 567 | 540 | 2540 | 20089 |
1919
| lock | 23840 | 23840 | 23840 | 23840 | 1 |
2020
| migrateTo | 23869 | 23875 | 23875 | 23881 | 2 |
2121
| migration | 439 | 1439 | 1439 | 2439 | 4 |
@@ -27,7 +27,7 @@
2727
| setVault | 46239 | 46239 | 46239 | 46239 | 279 |
2828
| stake | 23983 | 23983 | 23983 | 23983 | 1 |
2929
| stakeRewardEstimate | 436 | 2269 | 2436 | 2436 | 12 |
30-
| stakedToken | 273 | 273 | 273 | 273 | 17954 |
30+
| stakedToken | 273 | 273 | 273 | 273 | 20105 |
3131
| startMigration | 108037 | 108045 | 108049 | 108049 | 3 |
3232
| totalSupply | 740 | 1921 | 2740 | 2740 | 22 |
3333
| totalSupplyBalance | 385 | 1785 | 2385 | 2385 | 20 |
@@ -51,19 +51,19 @@
5151
| Function Name | min | avg | median | max | # calls |
5252
| acceptMigration | 35258 | 35258 | 35258 | 35258 | 2 |
5353
| leave | 35244 | 35244 | 35244 | 35244 | 1 |
54-
| lock | 45192 | 75153 | 66395 | 158442 | 6 |
55-
| owner | 362 | 362 | 362 | 362 | 17937 |
56-
| stake | 27265 | 268868 | 267622 | 353853 | 17942 |
54+
| lock | 45387 | 74829 | 66590 | 155519 | 6 |
55+
| owner | 362 | 362 | 362 | 362 | 20088 |
56+
| stake | 27265 | 268735 | 267622 | 353853 | 20093 |
5757
| stakedToken | 212 | 212 | 212 | 212 | 2 |
58-
| unstake | 42163 | 92598 | 80285 | 207456 | 11 |
58+
| unstake | 42163 | 92145 | 80441 | 204532 | 11 |
5959

6060

6161
| contracts/VaultFactory.sol:VaultFactory contract | | | | | |
6262
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
6363
| Deployment Cost | Deployment Size | | | | |
6464
| 0 | 0 | | | | |
6565
| Function Name | min | avg | median | max | # calls |
66-
| createVault | 696531 | 696531 | 696531 | 696531 | 17941 |
66+
| createVault | 696531 | 696531 | 696531 | 696531 | 20092 |
6767
| setStakeManager | 23710 | 26669 | 26076 | 30222 | 3 |
6868
| stakeManager | 368 | 1868 | 2368 | 2368 | 4 |
6969

@@ -73,24 +73,24 @@
7373
| Deployment Cost | Deployment Size | | | | |
7474
| 0 | 0 | | | | |
7575
| Function Name | min | avg | median | max | # calls |
76-
| approve | 46175 | 46198 | 46199 | 46211 | 17937 |
77-
| balanceOf | 561 | 604 | 561 | 2561 | 42408 |
76+
| approve | 46175 | 46198 | 46199 | 46211 | 20088 |
77+
| balanceOf | 561 | 600 | 561 | 2561 | 46710 |
7878

7979

8080
| script/Deploy.s.sol:Deploy contract | | | | | |
8181
|-------------------------------------|-----------------|---------|---------|---------|---------|
8282
| Deployment Cost | Deployment Size | | | | |
83-
| 6531749 | 31447 | | | | |
83+
| 6515986 | 31374 | | | | |
8484
| Function Name | min | avg | median | max | # calls |
85-
| run | 5752036 | 5752036 | 5752036 | 5752036 | 55 |
85+
| run | 5737391 | 5737391 | 5737391 | 5737391 | 55 |
8686

8787

8888
| script/DeployMigrationStakeManager.s.sol:DeployMigrationStakeManager contract | | | | | |
8989
|-------------------------------------------------------------------------------|-----------------|---------|---------|---------|---------|
9090
| Deployment Cost | Deployment Size | | | | |
91-
| 3695191 | 18215 | | | | |
91+
| 3679431 | 18142 | | | | |
9292
| Function Name | min | avg | median | max | # calls |
93-
| run | 2737706 | 2737706 | 2737706 | 2737706 | 9 |
93+
| run | 2723061 | 2723061 | 2723061 | 2723061 | 9 |
9494

9595

9696
| script/DeploymentConfig.s.sol:DeploymentConfig contract | | | | | |
@@ -113,9 +113,9 @@
113113
| test/script/DeployBroken.s.sol:DeployBroken contract | | | | | |
114114
|------------------------------------------------------|-----------------|---------|---------|---------|---------|
115115
| Deployment Cost | Deployment Size | | | | |
116-
| 5216467 | 25245 | | | | |
116+
| 5200705 | 25172 | | | | |
117117
| Function Name | min | avg | median | max | # calls |
118-
| run | 4591858 | 4591858 | 4591858 | 4591858 | 1 |
118+
| run | 4577212 | 4577212 | 4577212 | 4577212 | 1 |
119119

120120

121121

.gas-snapshot

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
CreateVaultTest:testDeployment() (gas: 9774)
22
CreateVaultTest:test_createVault() (gas: 692936)
33
ExecuteAccountTest:testDeployment() (gas: 28742)
4-
ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1318319)
5-
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3861100)
4+
ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1338316)
5+
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3857142)
66
ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1154374)
7-
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 110701418)
7+
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 110607467)
88
ExecuteEpochTest:testDeployment() (gas: 28720)
99
ExecuteEpochTest:testNewDeployment() (gas: 30815)
1010
ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 94810)
@@ -15,17 +15,17 @@ LeaveTest:testDeployment() (gas: 28720)
1515
LeaveTest:test_RevertWhen_NoPendingMigration() (gas: 1154630)
1616
LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
1717
LockTest:testDeployment() (gas: 28720)
18-
LockTest:test_NewLockupPeriod() (gas: 1143188)
19-
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1134805)
20-
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1229668)
18+
LockTest:test_NewLockupPeriod() (gas: 1143383)
19+
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1135000)
20+
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1231009)
2121
LockTest:test_RevertWhen_SenderIsNotVault() (gas: 10630)
22-
LockTest:test_ShouldIncreaseBonusMP() (gas: 1123288)
23-
LockTest:test_UpdateLockupPeriod() (gas: 1260001)
22+
LockTest:test_ShouldIncreaseBonusMP() (gas: 1123483)
23+
LockTest:test_UpdateLockupPeriod() (gas: 1280388)
2424
MigrateTest:testDeployment() (gas: 28720)
2525
MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1152269)
2626
MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
2727
MigrationInitializeTest:testDeployment() (gas: 28720)
28-
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5505750)
28+
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5476473)
2929
MigrationStakeManagerTest:testDeployment() (gas: 28720)
3030
MigrationStakeManagerTest:testNewDeployment() (gas: 30859)
3131
MigrationStakeManagerTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 105686)
@@ -40,17 +40,17 @@ StakeTest:test_RevertWhen_RestakeWithLock() (gas: 1159410)
4040
StakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10651)
4141
StakeTest:test_RevertWhen_StakeIsTooLow() (gas: 745253)
4242
StakeTest:test_RevertWhen_StakeTokenTransferFails() (gas: 175040)
43-
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1028816)
43+
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1029011)
4444
StakedTokenTest:testStakeToken() (gas: 7616)
4545
UnstakeTest:testDeployment() (gas: 28742)
4646
UnstakeTest:test_RevertWhen_AmountMoreThanBalance() (gas: 1132884)
4747
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1158036)
4848
UnstakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10653)
49-
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 5535322)
50-
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1026296)
51-
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1113944)
49+
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 5497028)
50+
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1026491)
51+
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1115090)
5252
UserFlowsTest:testDeployment() (gas: 28720)
53-
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 1001, μ: 71659756, ~: 33868170)
54-
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1114832)
55-
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1950349)
53+
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 1001, μ: 71037060, ~: 31077253)
54+
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1115978)
55+
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1950739)
5656
VaultFactoryTest:testDeployment() (gas: 9774)

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)