Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): fix fuzzing function to properly test whats suppoused to… #135

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions .gas-report
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
| Deployment Cost | Deployment Size | | | | |
| 2931383 | 14953 | | | | |
| Function Name | min | avg | median | max | # calls |
| EPOCH_SIZE | 307 | 307 | 307 | 307 | 816 |
| MAX_BOOST | 285 | 285 | 285 | 285 | 1 |
| EPOCH_SIZE | 307 | 307 | 307 | 307 | 1452 |
| MAX_BOOST | 285 | 285 | 285 | 285 | 637 |
| MAX_LOCKUP_PERIOD | 361 | 361 | 361 | 361 | 4 |
| MIN_LOCKUP_PERIOD | 287 | 287 | 287 | 287 | 12 |
| YEAR | 263 | 263 | 263 | 263 | 1 |
| accounts | 1597 | 1597 | 1597 | 1597 | 12050 |
| calculateMPToMint | 740 | 740 | 740 | 740 | 4 |
| YEAR | 263 | 263 | 263 | 263 | 637 |
| accounts | 1597 | 1597 | 1597 | 1597 | 144321 |
| calculateMPToMint | 740 | 740 | 740 | 740 | 1276 |
| currentEpoch | 406 | 1691 | 2406 | 2406 | 28 |
| epochEnd | 627 | 643 | 627 | 4627 | 480 |
| epochEnd | 627 | 627 | 627 | 4627 | 23603 |
| epochReward | 1403 | 2903 | 1403 | 5903 | 3 |
| executeAccount | 28897 | 95914 | 95004 | 171987 | 9611 |
| executeEpoch | 23436 | 170888 | 187183 | 204283 | 419 |
| isVault | 540 | 575 | 540 | 2540 | 7108 |
| executeAccount | 28897 | 76117 | 77904 | 171987 | 141882 |
| executeEpoch | 23436 | 146208 | 147383 | 204283 | 23542 |
| isVault | 540 | 927 | 540 | 2540 | 671 |
| lock | 23840 | 23840 | 23840 | 23840 | 1 |
| migrateTo | 23869 | 23875 | 23875 | 23881 | 2 |
| migration | 439 | 1439 | 1439 | 2439 | 4 |
| migrationInitialize | 24602 | 24602 | 24602 | 24602 | 1 |
| owner | 2432 | 2432 | 2432 | 2432 | 13 |
| pendingMPToBeMinted | 364 | 364 | 364 | 364 | 202 |
| pendingMPToBeMinted | 364 | 364 | 364 | 364 | 46448 |
| pendingReward | 364 | 1398 | 2364 | 2364 | 29 |
| previousManager | 275 | 275 | 275 | 275 | 13 |
| setVault | 46239 | 46239 | 46239 | 46239 | 125 |
| setVault | 46239 | 46239 | 46239 | 46239 | 130 |
| stake | 23983 | 23983 | 23983 | 23983 | 1 |
| stakeRewardEstimate | 436 | 2269 | 2436 | 2436 | 12 |
| stakedToken | 273 | 273 | 273 | 273 | 7124 |
| stakedToken | 273 | 273 | 273 | 273 | 687 |
| startMigration | 108037 | 108045 | 108049 | 108049 | 3 |
| totalSupply | 740 | 1921 | 2740 | 2740 | 22 |
| totalSupplyBalance | 385 | 1785 | 2385 | 2385 | 20 |
| totalSupplyMP | 385 | 510 | 385 | 2385 | 223 |
| totalSupplyMP | 385 | 385 | 385 | 2385 | 46469 |
| unstake | 23819 | 23819 | 23819 | 23819 | 1 |


Expand All @@ -40,7 +40,7 @@
| Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | |
| 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 |


Expand All @@ -52,8 +52,8 @@
| acceptMigration | 35258 | 35258 | 35258 | 35258 | 2 |
| leave | 35244 | 35244 | 35244 | 35244 | 1 |
| lock | 45192 | 73900 | 66395 | 158442 | 7 |
| owner | 362 | 362 | 362 | 362 | 7107 |
| stake | 27265 | 268924 | 267631 | 353862 | 7112 |
| owner | 362 | 362 | 362 | 362 | 670 |
| stake | 27265 | 283296 | 267703 | 353862 | 675 |
| stakedToken | 212 | 212 | 212 | 212 | 2 |
| unstake | 42163 | 92598 | 80285 | 207456 | 11 |

Expand All @@ -63,7 +63,7 @@
| Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | |
| 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 |
| stakeManager | 368 | 1868 | 2368 | 2368 | 4 |

Expand All @@ -73,8 +73,8 @@
| Deployment Cost | Deployment Size | | | | |
| 0 | 0 | | | | |
| Function Name | min | avg | median | max | # calls |
| approve | 46175 | 46198 | 46199 | 46211 | 7107 |
| balanceOf | 561 | 621 | 561 | 2561 | 20439 |
| approve | 46175 | 46237 | 46199 | 46367 | 670 |
| balanceOf | 561 | 2108 | 2561 | 2561 | 30693 |


| script/Deploy.s.sol:Deploy contract | | | | | |
Expand Down
4 changes: 2 additions & 2 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 7409934)
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1322723)
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1422611)
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_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 2501869)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 2501847)
VaultFactoryTest:testDeployment() (gas: 9774)
30 changes: 23 additions & 7 deletions test/StakeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -662,18 +662,34 @@ contract UserFlowsTest is StakeManagerTest {
assertEq(stakeManager.totalSupplyBalance(), 0);
}

function test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8 accountNum) public {
uint256 stakeAmount = 10_000_000;

function test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(
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++) {
uint256 thisAccStake = baseStakeAmount + (i * (10 ^ i * baseStakeAmount)); //changes the amount of stake of
// each account so we have mixed amounts of stake
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;

for (uint256 i = 0; i < epochsAmountToReachCap; i++) {
//tests up to epochs to reach MAX_BOOST + 10 epochs
for (uint256 i = 0; i < epochsAmountToReachCap + 10; i++) {
vm.warp(stakeManager.epochEnd());
stakeManager.executeEpoch();
uint256 pendingMPToBeMintedBefore = stakeManager.pendingMPToBeMinted();
Expand Down
Loading