Skip to content

feat: added permissions for new actions and unit tests #1020

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

Merged
merged 8 commits into from
Apr 14, 2025

Conversation

tamtamchik
Copy link
Member

@tamtamchik tamtamchik commented Apr 8, 2025

This pull request includes several changes across multiple files to enhance the vault system's functionality and permissions management. The most important changes include adding new roles and permissions, updating functions for managing the staking vault, and refactoring existing code for clarity and consistency.

Enhancements to Permissions and Roles:

  • contracts/0.8.25/vaults/Permissions.sol: Added new roles including LIDO_VAULTHUB_AUTHORIZATION_ROLE, OSSIFY_ROLE, SET_DEPOSITOR_ROLE, and RESET_LOCKED_ROLE to manage various staking vault operations.

Updates to Staking Vault Management:

Code Refactoring and Consistency:

Utility Functions and Helper Methods:

  • lib/account.ts: Added a new function getRandomSigners to generate random signers with a specified balance for testing purposes.
  • lib/protocol/helpers/vaults.ts: Integrated the getRandomSigners function and expanded the VaultRoles type to include new roles.

These changes collectively enhance the functionality, security, and maintainability of the vault system by introducing new roles, improving permission management, and ensuring consistency across the codebase.

Copy link

github-actions bot commented Apr 8, 2025

badge

Hardhat Unit Tests Coverage Summary

Filename                                                                Stmts    Miss  Cover    Missing
--------------------------------------------------------------------  -------  ------  -------  ------------------------------------
contracts/0.4.24/Lido.sol                                                 205       5  97.56%   802-814, 963-964
contracts/0.4.24/StETH.sol                                                 79       0  100.00%
contracts/0.4.24/StETHPermit.sol                                           15       0  100.00%
contracts/0.4.24/lib/Packed64x4.sol                                         5       0  100.00%
contracts/0.4.24/lib/SigningKeys.sol                                       36       0  100.00%
contracts/0.4.24/lib/StakeLimitUtils.sol                                   37       0  100.00%
contracts/0.4.24/nos/NodeOperatorsRegistry.sol                            512       0  100.00%
contracts/0.4.24/oracle/LegacyOracle.sol                                   72       0  100.00%
contracts/0.4.24/utils/Pausable.sol                                         9       0  100.00%
contracts/0.4.24/utils/Versioned.sol                                        5       0  100.00%
contracts/0.6.12/WstETH.sol                                                17       0  100.00%
contracts/0.8.25/Accounting.sol                                            82       1  98.78%   321
contracts/0.8.25/interfaces/IDepositContract.sol                            0       0  100.00%
contracts/0.8.25/interfaces/ILido.sol                                       0       0  100.00%
contracts/0.8.25/interfaces/IOracleReportSanityChecker.sol                  0       0  100.00%
contracts/0.8.25/interfaces/IPostTokenRebaseReceiver.sol                    0       0  100.00%
contracts/0.8.25/interfaces/IStakingRouter.sol                              0       0  100.00%
contracts/0.8.25/interfaces/IWithdrawalQueue.sol                            0       0  100.00%
contracts/0.8.25/lib/BLS.sol                                               27       3  88.89%   273, 340, 367
contracts/0.8.25/lib/BeaconTypes.sol                                        0       0  100.00%
contracts/0.8.25/lib/GIndex.sol                                            33      18  45.45%   23, 35, 56, 64-71, 80, 87-102
contracts/0.8.25/lib/SSZ.sol                                               19       7  63.16%   55-157, 347
contracts/0.8.25/utils/AccessControlConfirmable.sol                        30       0  100.00%
contracts/0.8.25/utils/PausableUntilWithRoles.sol                           3       0  100.00%
contracts/0.8.25/vaults/Dashboard.sol                                     109       2  98.17%   439, 552
contracts/0.8.25/vaults/Delegation.sol                                     47       0  100.00%
contracts/0.8.25/vaults/Permissions.sol                                    44       5  88.64%   328-331, 363
contracts/0.8.25/vaults/PinnedBeaconProxy.sol                               5       0  100.00%
contracts/0.8.25/vaults/StakingVault.sol                                  163       2  98.77%   666-667
contracts/0.8.25/vaults/VaultFactory.sol                                   63       0  100.00%
contracts/0.8.25/vaults/VaultHub.sol                                      178      20  88.76%   272, 274, 372, 379, 413-447, 539-540
contracts/0.8.25/vaults/interfaces/IPredepositGuarantee.sol                 0       0  100.00%
contracts/0.8.25/vaults/interfaces/IStakingVault.sol                        0       0  100.00%
contracts/0.8.25/vaults/lib/PinnedBeaconUtils.sol                           6       0  100.00%
contracts/0.8.25/vaults/predeposit_guarantee/CLProofVerifier.sol           11       0  100.00%
contracts/0.8.25/vaults/predeposit_guarantee/PredepositGuarantee.sol      150       0  100.00%
contracts/0.8.4/WithdrawalsManagerProxy.sol                                61       0  100.00%
contracts/0.8.9/BeaconChainDepositor.sol                                   21       2  90.48%   48, 51
contracts/0.8.9/Burner.sol                                                 72       0  100.00%
contracts/0.8.9/DepositSecurityModule.sol                                 128       0  100.00%
contracts/0.8.9/EIP712StETH.sol                                            16       0  100.00%
contracts/0.8.9/LidoExecutionLayerRewardsVault.sol                         16       0  100.00%
contracts/0.8.9/LidoLocator.sol                                            22       0  100.00%
contracts/0.8.9/OracleDaemonConfig.sol                                     28       0  100.00%
contracts/0.8.9/StakingRouter.sol                                         316       0  100.00%
contracts/0.8.9/WithdrawalQueue.sol                                        88       0  100.00%
contracts/0.8.9/WithdrawalQueueBase.sol                                   146       0  100.00%
contracts/0.8.9/WithdrawalQueueERC721.sol                                  89       0  100.00%
contracts/0.8.9/WithdrawalVault.sol                                        21       0  100.00%
contracts/0.8.9/lib/Math.sol                                                4       0  100.00%
contracts/0.8.9/lib/PositiveTokenRebaseLimiter.sol                         22       0  100.00%
contracts/0.8.9/lib/UnstructuredRefStorage.sol                              2       0  100.00%
contracts/0.8.9/oracle/AccountingOracle.sol                               190       2  98.95%   154-155
contracts/0.8.9/oracle/BaseOracle.sol                                      89       1  98.88%   397
contracts/0.8.9/oracle/HashConsensus.sol                                  263       1  99.62%   1005
contracts/0.8.9/oracle/ValidatorsExitBusOracle.sol                         91       2  97.80%   138, 315
contracts/0.8.9/proxy/OssifiableProxy.sol                                  17       0  100.00%
contracts/0.8.9/sanity_checks/OracleReportSanityChecker.sol               217       1  99.54%   856
contracts/0.8.9/utils/DummyEmptyContract.sol                                0       0  100.00%
contracts/0.8.9/utils/PausableUntil.sol                                    31       0  100.00%
contracts/0.8.9/utils/Versioned.sol                                        11       0  100.00%
contracts/0.8.9/utils/access/AccessControl.sol                             23       0  100.00%
contracts/0.8.9/utils/access/AccessControlEnumerable.sol                    9       0  100.00%
contracts/common/utils/PausableUntil.sol                                   29       0  100.00%
contracts/testnets/sepolia/SepoliaDepositAdapter.sol                       21      21  0.00%    49-100
TOTAL                                                                    4005      93  97.68%

Diff against master

Filename                                                                Stmts    Miss  Cover
--------------------------------------------------------------------  -------  ------  --------
contracts/0.4.24/Lido.sol                                                  -7      +5  -2.44%
contracts/0.4.24/StETH.sol                                                 +7       0  +100.00%
contracts/0.8.25/Accounting.sol                                           +82      +1  +98.78%
contracts/0.8.25/interfaces/IDepositContract.sol                            0       0  +100.00%
contracts/0.8.25/interfaces/ILido.sol                                       0       0  +100.00%
contracts/0.8.25/interfaces/IOracleReportSanityChecker.sol                  0       0  +100.00%
contracts/0.8.25/interfaces/IPostTokenRebaseReceiver.sol                    0       0  +100.00%
contracts/0.8.25/interfaces/IStakingRouter.sol                              0       0  +100.00%
contracts/0.8.25/interfaces/IWithdrawalQueue.sol                            0       0  +100.00%
contracts/0.8.25/lib/BLS.sol                                              +27      +3  +88.89%
contracts/0.8.25/lib/BeaconTypes.sol                                        0       0  +100.00%
contracts/0.8.25/lib/GIndex.sol                                           +33     +18  +45.45%
contracts/0.8.25/lib/SSZ.sol                                              +19      +7  +63.16%
contracts/0.8.25/utils/AccessControlConfirmable.sol                       +30       0  +100.00%
contracts/0.8.25/utils/PausableUntilWithRoles.sol                          +3       0  +100.00%
contracts/0.8.25/vaults/Dashboard.sol                                    +109      +2  +98.17%
contracts/0.8.25/vaults/Delegation.sol                                    +47       0  +100.00%
contracts/0.8.25/vaults/Permissions.sol                                   +44      +5  +88.64%
contracts/0.8.25/vaults/PinnedBeaconProxy.sol                              +5       0  +100.00%
contracts/0.8.25/vaults/StakingVault.sol                                 +163      +2  +98.77%
contracts/0.8.25/vaults/VaultFactory.sol                                  +63       0  +100.00%
contracts/0.8.25/vaults/VaultHub.sol                                     +178     +20  +88.76%
contracts/0.8.25/vaults/interfaces/IPredepositGuarantee.sol                 0       0  +100.00%
contracts/0.8.25/vaults/interfaces/IStakingVault.sol                        0       0  +100.00%
contracts/0.8.25/vaults/lib/PinnedBeaconUtils.sol                          +6       0  +100.00%
contracts/0.8.25/vaults/predeposit_guarantee/CLProofVerifier.sol          +11       0  +100.00%
contracts/0.8.25/vaults/predeposit_guarantee/PredepositGuarantee.sol     +150       0  +100.00%
contracts/0.8.9/Burner.sol                                                 +1       0  +100.00%
contracts/0.8.9/LidoLocator.sol                                            +4       0  +100.00%
contracts/0.8.9/sanity_checks/OracleReportSanityChecker.sol               -15      +1  -0.46%
contracts/common/utils/PausableUntil.sol                                  +29       0  +100.00%
TOTAL                                                                    +989     +64  -1.36%

Results for commit: e9288d6

Minimum allowed coverage is 90%

♻️ This comment has been updated with latest results

@tamtamchik tamtamchik requested a review from Copilot April 8, 2025 19:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 17 out of 28 changed files in this pull request and generated no comments.

Files not reviewed (11)
  • contracts/0.8.25/vaults/Dashboard.sol: Language not supported
  • contracts/0.8.25/vaults/Permissions.sol: Language not supported
  • contracts/0.8.25/vaults/VaultFactory.sol: Language not supported
  • contracts/0.8.25/vaults/interfaces/IStakingVault.sol: Language not supported
  • test/0.4.24/contracts/LidoExecutionLayerRewardsVault__MockForLidoAccounting.sol: Language not supported
  • test/0.4.24/contracts/WithdrawalVault__MockForLidoAccounting.sol: Language not supported
  • test/0.8.25/vaults/contracts/StakingVault__HarnessForTestUpgrade.sol: Language not supported
  • test/0.8.25/vaults/dashboard/contracts/PredepositGuarantee__MockForDashboard.sol: Language not supported
  • test/0.8.25/vaults/permissions/contracts/Permissions__Harness.sol: Language not supported
  • test/0.8.25/vaults/permissions/contracts/PredepositGuarantee__MockPermissions.sol: Language not supported
  • test/0.8.25/vaults/permissions/contracts/VaultFactory__MockPermissions.sol: Language not supported
Comments suppressed due to low confidence (3)

test/0.8.25/vaults/permissions/permissions.test.ts:110

  • Using getRandomSigners to obtain signers can introduce non-determinism in tests; consider using fixed or pre-configured signers to ensure predictable outcomes.
] = await getRandomSigners(20);

lib/protocol/helpers/index.ts:17

  • The removal of the getRandomSigners export from this module requires a corresponding documentation update to inform consumers of its new location in lib/account.ts.
export { getRandomSigners } from "./get-random-signers";

lib/protocol/helpers/get-random-signers.ts:1

  • Ensure that no modules or tests retain stale import paths for getRandomSigners that referenced this file; all such references should now point to lib/account.ts.
Entire file removed

@tamtamchik tamtamchik requested a review from Copilot April 8, 2025 21:34
@tamtamchik tamtamchik marked this pull request as ready for review April 8, 2025 21:34
@tamtamchik tamtamchik requested a review from a team as a code owner April 8, 2025 21:34
@tamtamchik tamtamchik added solidity issues/tasks related to smart contract code tests When it comes to testing the code labels Apr 8, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 22 out of 36 changed files in this pull request and generated no comments.

Files not reviewed (14)
  • contracts/0.8.25/vaults/Dashboard.sol: Language not supported
  • contracts/0.8.25/vaults/Permissions.sol: Language not supported
  • contracts/0.8.25/vaults/StakingVault.sol: Language not supported
  • contracts/0.8.25/vaults/VaultFactory.sol: Language not supported
  • contracts/0.8.25/vaults/VaultHub.sol: Language not supported
  • contracts/0.8.25/vaults/interfaces/IStakingVault.sol: Language not supported
  • contracts/0.8.25/vaults/lib/PinnedBeaconUtils.sol: Language not supported
  • test/0.4.24/contracts/LidoExecutionLayerRewardsVault__MockForLidoAccounting.sol: Language not supported
  • test/0.4.24/contracts/WithdrawalVault__MockForLidoAccounting.sol: Language not supported
  • test/0.8.25/vaults/contracts/StakingVault__HarnessForTestUpgrade.sol: Language not supported
  • test/0.8.25/vaults/dashboard/contracts/ERC721__MockForDashboard.sol: Language not supported
  • test/0.8.25/vaults/dashboard/contracts/PredepositGuarantee__MockForDashboard.sol: Language not supported
  • test/0.8.25/vaults/dashboard/contracts/VaultFactory__MockForDashboard.sol: Language not supported
  • test/0.8.25/vaults/dashboard/contracts/VaultHub__MockForDashboard.sol: Language not supported
Comments suppressed due to low confidence (2)

lib/protocol/helpers/vaults.ts:68

  • Increasing the number of signers from 13 to 20 may cause unintended side effects if downstream logic expects a smaller set. Please verify that all parts of the system using these roles are compatible with the new count.
const defaultRoles = await getRandomSigners(20);

test/0.4.24/lido/lido.accounting.test.ts:153

  • The helper function 'args' is used to spread parameters for collectRewardsAndProcessWithdrawals, but its definition isn’t visible in the diff. Please ensure 'args' is defined and returns the expected parameters for all test scenarios.
await expect(lido.collectRewardsAndProcessWithdrawals(...args({ elRewardsToWithdraw })))

@TheDZhon
Copy link
Contributor

Waiting for #1011 to be merged in? 🤔

@tamtamchik
Copy link
Member Author

@TheDZhon or maybe merge into #1011

# Conflicts:
#	contracts/0.8.25/vaults/Dashboard.sol
#	contracts/0.8.25/vaults/Permissions.sol
#	contracts/0.8.25/vaults/VaultFactory.sol
#	contracts/0.8.25/vaults/interfaces/IStakingVault.sol
#	lib/protocol/helpers/index.ts
#	lib/protocol/helpers/vaults.ts
#	test/0.8.25/vaults/delegation/delegation.test.ts
#	test/0.8.25/vaults/staking-vault/stakingVault.test.ts
#	test/0.8.25/vaults/vaultFactory.test.ts
#	test/0.8.25/vaults/vaulthub/vaulthub.detach.test.ts
#	test/0.8.9/accounting.handleOracleReport.test.ts
#	test/integration/vaults/happy-path.integration.ts
#	test/integration/vaults/roles.integration.ts
*/
bytes32 public constant ASSET_RECOVERY_ROLE = keccak256("vaults.Permissions.AssetRecovery");
bytes32 public constant LIDO_VAULTHUB_AUTHORIZATION_ROLE =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bytes32 public constant LIDO_VAULTHUB_AUTHORIZATION_ROLE =
bytes32 public constant LIDO_VAULTHUB_AUTHORIZE_ROLE =

Copy link
Member Author

Choose a reason for hiding this comment

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

Or even AUTHORIZE_LIDO_VAULTHUB_ROLE?

Copy link
Contributor

@failingtwice failingtwice left a comment

Choose a reason for hiding this comment

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

LGTM

@tamtamchik tamtamchik merged commit a9c7b2a into feat/vaults Apr 14, 2025
8 of 9 checks passed
@tamtamchik tamtamchik deleted the feat/unit-tests branch April 14, 2025 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solidity issues/tasks related to smart contract code tests When it comes to testing the code vaults
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants