Skip to content

Commit

Permalink
fix test errors:
Browse files Browse the repository at this point in the history
- unhandled stake share limit
- too long csm queue
- queue higher than target share of the module
  • Loading branch information
skhomuti committed Feb 3, 2025
1 parent a3cab05 commit bba1ce9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
13 changes: 13 additions & 0 deletions tests/regression/test_accounting_oracle_extra_data_full_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ def test_extra_data_most_expensive_report(extra_data_service):
An estimate for 8 * 24 items:
Gas used: 11850807 (39.50%)
"""
csm_module_id = 3
module = contracts.staking_router.getStakingModule(csm_module_id)
# increase limits to allow new deposits
contracts.staking_router.updateStakingModule(
csm_module_id,
module["stakeShareLimit"] * 2,
module["priorityExitShareThreshold"] * 2,
module["stakingModuleFee"],
module["treasuryFee"],
module["maxDepositsPerBlock"],
module["minDepositBlockDistance"],
{"from": contracts.agent},
)

csm_operators_count = MAX_ITEMS_PER_EXTRA_DATA_TRANSACTION * MAX_NODE_OPERATORS_PER_EXTRA_DATA_ITEM
# create or ensure there are max node operators with 1 depositable key
Expand Down
7 changes: 7 additions & 0 deletions tests/regression/test_all_round_happy_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from utils.config import contracts
from utils.test.simple_dvt_helpers import fill_simple_dvt_ops_vetted_keys
from utils.balance import set_balance
from utils.test.staking_router_helpers import set_staking_module_status, StakingModuleStatus
from utils.test.tx_cost_helper import transaction_cost

def test_all_round_happy_path(accounts, stranger, steth_holder, eth_whale):
Expand Down Expand Up @@ -108,9 +109,15 @@ def test_all_round_happy_path(accounts, stranger, steth_holder, eth_whale):

assert contracts.lido.getDepositableEther() == buffered_ether_after_submit - withdrawal_unfinalized_steth

# pausing csm due to very high amount of keys in the queue
csm_module_id = 3
set_staking_module_status(csm_module_id, StakingModuleStatus.Stopped)

deposit_tx_nor = contracts.lido.deposit(max_deposit, curated_module_id, "0x0", {"from": dsm})
deposit_tx_sdvt = contracts.lido.deposit(max_deposit, simple_dvt_module_id, "0x0", {"from": dsm})

set_staking_module_status(csm_module_id, StakingModuleStatus.Active)

buffered_ether_after_deposit = contracts.lido.getBufferedEther()

deposited_event_nor = deposit_tx_nor.events["StakingRouterETHDeposited"]
Expand Down
23 changes: 16 additions & 7 deletions tests/regression/test_csm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from brownie import reverts, web3, ZERO_ADDRESS
from brownie import reverts, web3, ZERO_ADDRESS, accounts

from utils.balance import set_balance_in_wei
from utils.config import (
Expand All @@ -22,6 +22,7 @@
contracts: ContractsLazyLoader = contracts

CSM_MODULE_ID = 3
MAX_DEPOSITS = 50


@pytest.fixture(scope="module")
Expand All @@ -43,6 +44,7 @@ def fee_distributor():
def fee_oracle():
return contracts.cs_fee_oracle


@pytest.fixture(scope="module")
def early_adoption():
return contracts.cs_early_adoption
Expand All @@ -63,12 +65,17 @@ def pause_modules():
if module[0] != CSM_MODULE_ID:
set_staking_module_status(module[0], StakingModuleStatus.Stopped)

@pytest.fixture
def remove_stake_limit():
contracts.lido.removeStakingLimit({"from": accounts.at(contracts.voting, force=True)})


@pytest.fixture
def deposits_to_csm(csm, pause_modules, node_operator):
def deposits_to_csm(csm, pause_modules, node_operator, remove_stake_limit):
(_, _, depositable) = csm.getStakingModuleSummary()
fill_deposit_buffer(depositable)
contracts.lido.deposit(depositable, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
for i in range(0, depositable, MAX_DEPOSITS):
contracts.lido.deposit(MAX_DEPOSITS, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})


@pytest.fixture
Expand Down Expand Up @@ -150,12 +157,13 @@ def test_upload_keys_more_than_limit(csm, accounting, node_operator):


@pytest.mark.usefixtures("pause_modules")
def test_deposit(node_operator, csm):
def test_deposit(node_operator, csm, remove_stake_limit):
(_, _, depositable_validators_count) = csm.getStakingModuleSummary()
deposits_count = depositable_validators_count
fill_deposit_buffer(deposits_count)

contracts.lido.deposit(deposits_count, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
for i in range(0, deposits_count, MAX_DEPOSITS):
contracts.lido.deposit(MAX_DEPOSITS, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})

no = csm.getNodeOperator(node_operator)
assert no["totalDepositedKeys"] == no["totalAddedKeys"]
Expand Down Expand Up @@ -238,7 +246,7 @@ def test_csm_report_stuck(csm, node_operator, extra_data_service):


@pytest.mark.usefixtures("deposits_to_csm")
def test_csm_get_staking_module_summary(csm, accounting, node_operator, extra_data_service):
def test_csm_get_staking_module_summary(csm, accounting, node_operator, extra_data_service, remove_stake_limit):
(exited_before, deposited_before, depositable_before) = contracts.staking_router.getStakingModuleSummary(CSM_MODULE_ID)

# Assure there are new exited keys
Expand All @@ -260,7 +268,8 @@ def test_csm_get_staking_module_summary(csm, accounting, node_operator, extra_da
new_depositable = new_keys - deposits_count
csm_upload_keys(csm, accounting, node_operator, new_keys)
fill_deposit_buffer(deposits_count)
contracts.lido.deposit(deposits_count, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
for i in range(0, deposits_count, MAX_DEPOSITS):
contracts.lido.deposit(MAX_DEPOSITS, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})

(exited_after, deposited_after, depositable_after) = contracts.staking_router.getStakingModuleSummary(CSM_MODULE_ID)

Expand Down
6 changes: 5 additions & 1 deletion tests/regression/test_staking_module_happy_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from utils.config import contracts, STAKING_ROUTER, EASYTRACK_EVMSCRIPT_EXECUTOR
from utils.test.node_operators_helpers import distribute_reward, node_operator_gindex
from utils.test.simple_dvt_helpers import fill_simple_dvt_ops_keys

from utils.test.staking_router_helpers import set_staking_module_status, StakingModuleStatus

STAKING_ROUTER_ROLE = Web3.keccak(text="STAKING_ROUTER_ROLE")
STAKING_MODULE_MANAGE_ROLE = Web3.keccak(text="STAKING_MODULE_MANAGE_ROLE")
Expand Down Expand Up @@ -148,6 +148,10 @@ def module_happy_path(staking_module, extra_data_service, impersonated_voting, e
# remove staking limit to avoid STAKE_LIMIT error
contracts.lido.removeStakingLimit({"from": impersonated_voting})

# pausing csm due to very high amount of keys in the queue
csm_module_id = 3
set_staking_module_status(csm_module_id, StakingModuleStatus.Stopped)

contracts.lido.submit(ZERO_ADDRESS, {"from": eth_whale, "amount": ETH(150_000)})

print("Reset staking limit for all OPs...")
Expand Down

0 comments on commit bba1ce9

Please sign in to comment.