test(StakeManager): add test to catch bug in minting more bonus MPs when stake with lock

This commit is contained in:
Ricardo Guilherme Schmidt 2024-09-12 02:09:45 -03:00 committed by r4bbit
parent 8683376160
commit 0c58dfe241
3 changed files with 66 additions and 34 deletions

View File

@ -1,21 +1,21 @@
| contracts/StakeManager.sol:StakeManager contract | | | | | |
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 2930759 | 14950 | | | | |
| 2914993 | 14877 | | | | |
| Function Name | min | avg | median | max | # calls |
| EPOCH_SIZE | 307 | 307 | 307 | 307 | 816 |
| MAX_BOOST | 285 | 285 | 285 | 285 | 1 |
| MAX_LOCKUP_PERIOD | 361 | 361 | 361 | 361 | 4 |
| MIN_LOCKUP_PERIOD | 287 | 287 | 287 | 287 | 11 |
| YEAR | 263 | 263 | 263 | 263 | 1 |
| accounts | 1597 | 1597 | 1597 | 1597 | 22879 |
| accounts | 1597 | 1597 | 1597 | 1597 | 25030 |
| calculateMPToMint | 740 | 740 | 740 | 740 | 3 |
| currentEpoch | 406 | 1691 | 2406 | 2406 | 28 |
| epochEnd | 627 | 639 | 627 | 4627 | 635 |
| epochReward | 1403 | 2903 | 1403 | 5903 | 3 |
| executeAccount | 28897 | 95329 | 95004 | 171987 | 20443 |
| executeAccount | 28897 | 95308 | 95073 | 169064 | 22594 |
| executeEpoch | 23436 | 169158 | 164483 | 204283 | 574 |
| isVault | 540 | 571 | 540 | 2540 | 17938 |
| isVault | 540 | 567 | 540 | 2540 | 20089 |
| lock | 23840 | 23840 | 23840 | 23840 | 1 |
| migrateTo | 23869 | 23875 | 23875 | 23881 | 2 |
| migration | 439 | 1439 | 1439 | 2439 | 4 |
@ -27,7 +27,7 @@
| setVault | 46239 | 46239 | 46239 | 46239 | 279 |
| stake | 23983 | 23983 | 23983 | 23983 | 1 |
| stakeRewardEstimate | 436 | 2269 | 2436 | 2436 | 12 |
| stakedToken | 273 | 273 | 273 | 273 | 17954 |
| stakedToken | 273 | 273 | 273 | 273 | 20105 |
| startMigration | 108037 | 108045 | 108049 | 108049 | 3 |
| totalSupply | 740 | 1921 | 2740 | 2740 | 22 |
| totalSupplyBalance | 385 | 1785 | 2385 | 2385 | 20 |
@ -51,11 +51,11 @@
| Function Name | min | avg | median | max | # calls |
| acceptMigration | 35258 | 35258 | 35258 | 35258 | 2 |
| leave | 35244 | 35244 | 35244 | 35244 | 1 |
| lock | 45192 | 75153 | 66395 | 158442 | 6 |
| owner | 362 | 362 | 362 | 362 | 17937 |
| stake | 27265 | 268868 | 267622 | 353853 | 17942 |
| lock | 45387 | 74829 | 66590 | 155519 | 6 |
| owner | 362 | 362 | 362 | 362 | 20088 |
| stake | 27265 | 268735 | 267622 | 353853 | 20093 |
| stakedToken | 212 | 212 | 212 | 212 | 2 |
| unstake | 42163 | 92598 | 80285 | 207456 | 11 |
| unstake | 42163 | 92145 | 80441 | 204532 | 11 |
| contracts/VaultFactory.sol:VaultFactory contract | | | | | |
@ -63,7 +63,7 @@
| Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | |
| Function Name | min | avg | median | max | # calls |
| createVault | 696531 | 696531 | 696531 | 696531 | 17941 |
| createVault | 696531 | 696531 | 696531 | 696531 | 20092 |
| setStakeManager | 23710 | 26669 | 26076 | 30222 | 3 |
| stakeManager | 368 | 1868 | 2368 | 2368 | 4 |
@ -73,24 +73,24 @@
| Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | |
| Function Name | min | avg | median | max | # calls |
| approve | 46175 | 46198 | 46199 | 46211 | 17937 |
| balanceOf | 561 | 604 | 561 | 2561 | 42408 |
| approve | 46175 | 46198 | 46199 | 46211 | 20088 |
| balanceOf | 561 | 600 | 561 | 2561 | 46710 |
| script/Deploy.s.sol:Deploy contract | | | | | |
|-------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 6531749 | 31447 | | | | |
| 6515986 | 31374 | | | | |
| Function Name | min | avg | median | max | # calls |
| run | 5752036 | 5752036 | 5752036 | 5752036 | 55 |
| run | 5737391 | 5737391 | 5737391 | 5737391 | 55 |
| script/DeployMigrationStakeManager.s.sol:DeployMigrationStakeManager contract | | | | | |
|-------------------------------------------------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 3695191 | 18215 | | | | |
| 3679431 | 18142 | | | | |
| Function Name | min | avg | median | max | # calls |
| run | 2737706 | 2737706 | 2737706 | 2737706 | 9 |
| run | 2723061 | 2723061 | 2723061 | 2723061 | 9 |
| script/DeploymentConfig.s.sol:DeploymentConfig contract | | | | | |
@ -113,9 +113,9 @@
| test/script/DeployBroken.s.sol:DeployBroken contract | | | | | |
|------------------------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 5216467 | 25245 | | | | |
| 5200705 | 25172 | | | | |
| Function Name | min | avg | median | max | # calls |
| run | 4591858 | 4591858 | 4591858 | 4591858 | 1 |
| run | 4577212 | 4577212 | 4577212 | 4577212 | 1 |

View File

@ -1,10 +1,10 @@
CreateVaultTest:testDeployment() (gas: 9774)
CreateVaultTest:test_createVault() (gas: 692936)
ExecuteAccountTest:testDeployment() (gas: 28742)
ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1318319)
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3861100)
ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1338316)
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3857142)
ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1154374)
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 110701418)
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 110607467)
ExecuteEpochTest:testDeployment() (gas: 28720)
ExecuteEpochTest:testNewDeployment() (gas: 30815)
ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 94810)
@ -15,17 +15,17 @@ LeaveTest:testDeployment() (gas: 28720)
LeaveTest:test_RevertWhen_NoPendingMigration() (gas: 1154630)
LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
LockTest:testDeployment() (gas: 28720)
LockTest:test_NewLockupPeriod() (gas: 1143188)
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1134805)
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1229668)
LockTest:test_NewLockupPeriod() (gas: 1143383)
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1135000)
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1231009)
LockTest:test_RevertWhen_SenderIsNotVault() (gas: 10630)
LockTest:test_ShouldIncreaseBonusMP() (gas: 1123288)
LockTest:test_UpdateLockupPeriod() (gas: 1260001)
LockTest:test_ShouldIncreaseBonusMP() (gas: 1123483)
LockTest:test_UpdateLockupPeriod() (gas: 1280388)
MigrateTest:testDeployment() (gas: 28720)
MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1152269)
MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
MigrationInitializeTest:testDeployment() (gas: 28720)
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5505750)
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5476473)
MigrationStakeManagerTest:testDeployment() (gas: 28720)
MigrationStakeManagerTest:testNewDeployment() (gas: 30859)
MigrationStakeManagerTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 105686)
@ -40,17 +40,17 @@ StakeTest:test_RevertWhen_RestakeWithLock() (gas: 1159410)
StakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10651)
StakeTest:test_RevertWhen_StakeIsTooLow() (gas: 745253)
StakeTest:test_RevertWhen_StakeTokenTransferFails() (gas: 175040)
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1028816)
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1029011)
StakedTokenTest:testStakeToken() (gas: 7616)
UnstakeTest:testDeployment() (gas: 28742)
UnstakeTest:test_RevertWhen_AmountMoreThanBalance() (gas: 1132884)
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1158036)
UnstakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10653)
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 5535322)
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1026296)
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1113944)
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 5497028)
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1026491)
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1115090)
UserFlowsTest:testDeployment() (gas: 28720)
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 1001, μ: 71659756, ~: 33868170)
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1114832)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1950349)
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 1001, μ: 71037060, ~: 31077253)
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1115978)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1950739)
VaultFactoryTest:testDeployment() (gas: 9774)

View File

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