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

test: vaults fuzzing #918

Draft
wants to merge 20 commits into
base: feat/vaults
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"typecheck": "tsc --noEmit",
"prepare": "husky",
"abis:extract": "hardhat abis:extract",
"verify:deployed": "hardhat verify:deployed"
"verify:deployed": "hardhat verify:deployed",
"test:fuzzShateRate": "forge test --match-path \"test/0.8.25/ShareRate.t.sol\"",
"test:fuzzOracleReport": "forge test --match-path \"test/0.8.25/Accounting.t.sol\""
},
"lint-staged": {
"./**/*.ts": [
Expand Down
30 changes: 30 additions & 0 deletions test/0.4.24/contracts/SecondOpinionOracle__Mock.sol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to put it into test/0.8.25/contracts and rename it like SecondOpinionOracle__MockForAccountingFuzzing

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
// for testing purposes only

pragma solidity 0.8.9;

contract SecondOpinionOracle__Mock {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that we need that mock. We can harness OracleReportSanityChecker and just return true on _askSecondOpinion.

bool private success;
uint256 private clBalanceGwei;
uint256 private withdrawalVaultBalanceWei;
uint256 private totalDepositedValidators;
uint256 private totalExitedValidators;

function getReport(uint256 refSlot) external view returns (bool, uint256, uint256, uint256, uint256) {
return (success, clBalanceGwei, withdrawalVaultBalanceWei, totalDepositedValidators, totalExitedValidators);
}

function mock__setReportValues(
bool _success,
uint256 _clBalanceGwei,
uint256 _withdrawalVaultBalanceWei,
uint256 _totalDepositedValidators,
uint256 _totalExitedValidators
) external {
success = _success;
clBalanceGwei = _clBalanceGwei;
withdrawalVaultBalanceWei = _withdrawalVaultBalanceWei;
totalDepositedValidators = _totalDepositedValidators;
totalExitedValidators = _totalExitedValidators;
}
}
81 changes: 81 additions & 0 deletions test/0.4.24/contracts/StakingRouter__MockForLidoAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

pragma solidity 0.8.9;

import {StakingRouter} from "contracts/0.8.9/StakingRouter.sol";

contract StakingRouter__MockForLidoAccounting {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that this file is being used in the accounting unit tests. It would be better to clone the file and rename it to StakingRouter__MockForLidoAccountingFuzzing to clarify its purpose. Separating the mocks will simplify mock management and ensure that they do not interfere with other tests.

event Mock__MintedRewardsReported();
event Mock__MintedTotalShares(uint256 indexed _totalShares);

address[] private recipients__mocked;
uint256[] private stakingModuleIds__mocked;
Expand Down Expand Up @@ -32,6 +35,13 @@ contract StakingRouter__MockForLidoAccounting {

function reportRewardsMinted(uint256[] calldata _stakingModuleIds, uint256[] calldata _totalShares) external {
emit Mock__MintedRewardsReported();

uint256 totalShares = 0;
for (uint256 i = 0; i < _totalShares.length; i++) {
totalShares += _totalShares[i];
}

emit Mock__MintedTotalShares(totalShares);
}

function mock__getStakingRewardsDistribution(
Expand All @@ -47,4 +57,75 @@ contract StakingRouter__MockForLidoAccounting {
totalFee__mocked = _totalFee;
precisionPoint__mocked = _precisionPoints;
}

function getStakingModuleIds() public view returns (uint256[] memory) {
return stakingModuleIds__mocked;
}

function getRecipients() public view returns (address[] memory) {
return recipients__mocked;
}

function getStakingModule(uint256 _stakingModuleId) public view returns (StakingRouter.StakingModule memory) {
if (_stakingModuleId >= 4) {
revert("Staking module does not exist");
}

if (_stakingModuleId == 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that production values are used? And if possible to add a proof link. Otherwise no one will guess why the numbers are like they are here.

return
StakingRouter.StakingModule({
id: 1,
stakingModuleAddress: 0x55032650b14df07b85bF18A3a3eC8E0Af2e028d5,
stakingModuleFee: 500,
treasuryFee: 500,
stakeShareLimit: 10000,
status: 0,
name: "curated-onchain-v1",
lastDepositAt: 1732694279,
lastDepositBlock: 21277744,
exitedValidatorsCount: 88207,
priorityExitShareThreshold: 10000,
maxDepositsPerBlock: 150,
minDepositBlockDistance: 25
});
}

if (_stakingModuleId == 2) {
return
StakingRouter.StakingModule({
id: 2,
stakingModuleAddress: 0xaE7B191A31f627b4eB1d4DaC64eaB9976995b433,
stakingModuleFee: 800,
treasuryFee: 200,
stakeShareLimit: 400,
status: 0,
name: "SimpleDVT",
lastDepositAt: 1735217831,
lastDepositBlock: 21486781,
exitedValidatorsCount: 5,
priorityExitShareThreshold: 444,
maxDepositsPerBlock: 150,
minDepositBlockDistance: 25
});
}

if (_stakingModuleId == 3) {
return
StakingRouter.StakingModule({
id: 3,
stakingModuleAddress: 0xdA7dE2ECdDfccC6c3AF10108Db212ACBBf9EA83F,
stakingModuleFee: 600,
treasuryFee: 400,
stakeShareLimit: 100,
status: 0,
name: "Community Staking",
lastDepositAt: 1735217387,
lastDepositBlock: 21486745,
exitedValidatorsCount: 104,
priorityExitShareThreshold: 125,
maxDepositsPerBlock: 30,
minDepositBlockDistance: 25
});
}
}
}
Loading
Loading