chore(test): fix fuzzing function to properly test whats suppoused to and make it deterministic in amount of calls

This commit is contained in:
Ricardo Guilherme Schmidt 2024-09-25 08:22:16 -03:00
parent 85b88fa757
commit 28305cd550
No known key found for this signature in database
GPG Key ID: 54B4454CC123AD17
3 changed files with 44 additions and 28 deletions

View File

@ -3,35 +3,35 @@
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 2931383 | 14953 | | | | | | 2931383 | 14953 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| EPOCH_SIZE | 307 | 307 | 307 | 307 | 816 | | EPOCH_SIZE | 307 | 307 | 307 | 307 | 1452 |
| MAX_BOOST | 285 | 285 | 285 | 285 | 1 | | MAX_BOOST | 285 | 285 | 285 | 285 | 637 |
| MAX_LOCKUP_PERIOD | 361 | 361 | 361 | 361 | 4 | | MAX_LOCKUP_PERIOD | 361 | 361 | 361 | 361 | 4 |
| MIN_LOCKUP_PERIOD | 287 | 287 | 287 | 287 | 12 | | MIN_LOCKUP_PERIOD | 287 | 287 | 287 | 287 | 12 |
| YEAR | 263 | 263 | 263 | 263 | 1 | | YEAR | 263 | 263 | 263 | 263 | 637 |
| accounts | 1597 | 1597 | 1597 | 1597 | 12050 | | accounts | 1597 | 1597 | 1597 | 1597 | 144321 |
| calculateMPToMint | 740 | 740 | 740 | 740 | 4 | | calculateMPToMint | 740 | 740 | 740 | 740 | 1276 |
| currentEpoch | 406 | 1691 | 2406 | 2406 | 28 | | currentEpoch | 406 | 1691 | 2406 | 2406 | 28 |
| epochEnd | 627 | 643 | 627 | 4627 | 480 | | epochEnd | 627 | 627 | 627 | 4627 | 23603 |
| epochReward | 1403 | 2903 | 1403 | 5903 | 3 | | epochReward | 1403 | 2903 | 1403 | 5903 | 3 |
| executeAccount | 28897 | 95914 | 95004 | 171987 | 9611 | | executeAccount | 28897 | 76117 | 77904 | 171987 | 141882 |
| executeEpoch | 23436 | 170888 | 187183 | 204283 | 419 | | executeEpoch | 23436 | 146208 | 147383 | 204283 | 23542 |
| isVault | 540 | 575 | 540 | 2540 | 7108 | | isVault | 540 | 927 | 540 | 2540 | 671 |
| lock | 23840 | 23840 | 23840 | 23840 | 1 | | lock | 23840 | 23840 | 23840 | 23840 | 1 |
| migrateTo | 23869 | 23875 | 23875 | 23881 | 2 | | migrateTo | 23869 | 23875 | 23875 | 23881 | 2 |
| migration | 439 | 1439 | 1439 | 2439 | 4 | | migration | 439 | 1439 | 1439 | 2439 | 4 |
| migrationInitialize | 24602 | 24602 | 24602 | 24602 | 1 | | migrationInitialize | 24602 | 24602 | 24602 | 24602 | 1 |
| owner | 2432 | 2432 | 2432 | 2432 | 13 | | owner | 2432 | 2432 | 2432 | 2432 | 13 |
| pendingMPToBeMinted | 364 | 364 | 364 | 364 | 202 | | pendingMPToBeMinted | 364 | 364 | 364 | 364 | 46448 |
| pendingReward | 364 | 1398 | 2364 | 2364 | 29 | | pendingReward | 364 | 1398 | 2364 | 2364 | 29 |
| previousManager | 275 | 275 | 275 | 275 | 13 | | previousManager | 275 | 275 | 275 | 275 | 13 |
| setVault | 46239 | 46239 | 46239 | 46239 | 125 | | setVault | 46239 | 46239 | 46239 | 46239 | 130 |
| stake | 23983 | 23983 | 23983 | 23983 | 1 | | stake | 23983 | 23983 | 23983 | 23983 | 1 |
| stakeRewardEstimate | 436 | 2269 | 2436 | 2436 | 12 | | stakeRewardEstimate | 436 | 2269 | 2436 | 2436 | 12 |
| stakedToken | 273 | 273 | 273 | 273 | 7124 | | stakedToken | 273 | 273 | 273 | 273 | 687 |
| startMigration | 108037 | 108045 | 108049 | 108049 | 3 | | startMigration | 108037 | 108045 | 108049 | 108049 | 3 |
| totalSupply | 740 | 1921 | 2740 | 2740 | 22 | | totalSupply | 740 | 1921 | 2740 | 2740 | 22 |
| totalSupplyBalance | 385 | 1785 | 2385 | 2385 | 20 | | totalSupplyBalance | 385 | 1785 | 2385 | 2385 | 20 |
| totalSupplyMP | 385 | 510 | 385 | 2385 | 223 | | totalSupplyMP | 385 | 385 | 385 | 2385 | 46469 |
| unstake | 23819 | 23819 | 23819 | 23819 | 1 | | unstake | 23819 | 23819 | 23819 | 23819 | 1 |
@ -40,7 +40,7 @@
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | | | 0 | 0 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| getExpiredMP | 2427 | 2427 | 2427 | 2427 | 475 | | getExpiredMP | 2427 | 2427 | 2427 | 2427 | 23598 |
| transferOwnership | 28533 | 28533 | 28533 | 28533 | 1 | | transferOwnership | 28533 | 28533 | 28533 | 28533 | 1 |
@ -52,8 +52,8 @@
| acceptMigration | 35258 | 35258 | 35258 | 35258 | 2 | | acceptMigration | 35258 | 35258 | 35258 | 35258 | 2 |
| leave | 35244 | 35244 | 35244 | 35244 | 1 | | leave | 35244 | 35244 | 35244 | 35244 | 1 |
| lock | 45192 | 73900 | 66395 | 158442 | 7 | | lock | 45192 | 73900 | 66395 | 158442 | 7 |
| owner | 362 | 362 | 362 | 362 | 7107 | | owner | 362 | 362 | 362 | 362 | 670 |
| stake | 27265 | 268924 | 267631 | 353862 | 7112 | | stake | 27265 | 283296 | 267703 | 353862 | 675 |
| stakedToken | 212 | 212 | 212 | 212 | 2 | | stakedToken | 212 | 212 | 212 | 212 | 2 |
| unstake | 42163 | 92598 | 80285 | 207456 | 11 | | unstake | 42163 | 92598 | 80285 | 207456 | 11 |
@ -63,7 +63,7 @@
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | | | 0 | 0 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| createVault | 696531 | 696531 | 696531 | 696531 | 7111 | | createVault | 696531 | 696531 | 696531 | 696531 | 674 |
| setStakeManager | 23710 | 26669 | 26076 | 30222 | 3 | | setStakeManager | 23710 | 26669 | 26076 | 30222 | 3 |
| stakeManager | 368 | 1868 | 2368 | 2368 | 4 | | stakeManager | 368 | 1868 | 2368 | 2368 | 4 |
@ -73,8 +73,8 @@
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | | | 0 | 0 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| approve | 46175 | 46198 | 46199 | 46211 | 7107 | | approve | 46175 | 46237 | 46199 | 46367 | 670 |
| balanceOf | 561 | 621 | 561 | 2561 | 20439 | | balanceOf | 561 | 2108 | 2561 | 2561 | 30693 |
| script/Deploy.s.sol:Deploy contract | | | | | | | script/Deploy.s.sol:Deploy contract | | | | | |

View File

@ -51,7 +51,7 @@ UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 7409934)
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1322723) UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1322723)
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1422611) UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1422611)
UserFlowsTest:testDeployment() (gas: 28720) UserFlowsTest:testDeployment() (gas: 28720)
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 101, μ: 80806306, ~: 32532337) UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8,uint128) (runs: 106, μ: 141088719, ~: 140458057)
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1465703) UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1465703)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 2501869) UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 2501847)
VaultFactoryTest:testDeployment() (gas: 9774) VaultFactoryTest:testDeployment() (gas: 9774)

View File

@ -662,18 +662,34 @@ contract UserFlowsTest is StakeManagerTest {
assertEq(stakeManager.totalSupplyBalance(), 0); assertEq(stakeManager.totalSupplyBalance(), 0);
} }
function test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8 accountNum) public { function test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(
uint256 stakeAmount = 10_000_000; uint8 randomStakeMultiplier,
uint128 randomStakeAddition
)
public
{
uint8 accountNum = 5;
uint256 minimumPossibleStake = 53; //less than this the stake per epoch of the account would be 0
uint256 baseStakeAmount =
(minimumPossibleStake * (uint256(randomStakeMultiplier) + 1)) + uint256(randomStakeAddition);
uint256 epochsAmountToReachCap = 0;
for (uint256 i = 0; i <= accountNum; i++) { for (uint256 i = 0; i <= accountNum; i++) {
uint256 thisAccStake = baseStakeAmount + (i * (10 ^ i * baseStakeAmount)); //changes the amount of stake of
// each account so we have mixed amounts of stake
userVaults.push( userVaults.push(
_createStakingAccount(makeAddr(string(abi.encode(keccak256(abi.encode(accountNum))))), stakeAmount, 0) _createStakingAccount(makeAddr(string(abi.encode(keccak256(abi.encode(accountNum))))), thisAccStake, 0)
); );
uint256 thisAccReachCapIn = stakeManager.calculateMPToMint(
thisAccStake, stakeManager.MAX_BOOST() * stakeManager.YEAR()
) / stakeManager.calculateMPToMint(thisAccStake, stakeManager.EPOCH_SIZE());
if (thisAccReachCapIn > epochsAmountToReachCap) {
epochsAmountToReachCap = thisAccReachCapIn; //uses the amount to reach cap from the account that takes
// longer to reach cap
}
} }
uint256 epochsAmountToReachCap = 1; //tests up to epochs to reach MAX_BOOST + 10 epochs
for (uint256 i = 0; i < epochsAmountToReachCap + 10; i++) {
for (uint256 i = 0; i < epochsAmountToReachCap; i++) {
vm.warp(stakeManager.epochEnd()); vm.warp(stakeManager.epochEnd());
stakeManager.executeEpoch(); stakeManager.executeEpoch();
uint256 pendingMPToBeMintedBefore = stakeManager.pendingMPToBeMinted(); uint256 pendingMPToBeMintedBefore = stakeManager.pendingMPToBeMinted();