Skip to content

Commit 9bf2f1c

Browse files
committed
fix test errors:
- unhandled stake share limit - too long csm queue - queue higher than target share of the module
1 parent a3cab05 commit 9bf2f1c

File tree

6 files changed

+54
-10
lines changed

6 files changed

+54
-10
lines changed

.github/actions/brownie_fork_tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ runs:
6969
shell: bash
7070
run: >
7171
poetry run
72-
brownie test -ra --network mainnet-fork
72+
brownie test -ra --network mainnet-fork --durations=20
7373
env:
7474
WEB3_INFURA_PROJECT_ID: ${{ inputs.infura }}
7575
ETHERSCAN_TOKEN: ${{ inputs.etherscan }}

tests/regression/test_accounting_oracle_extra_data_full_items.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from utils.config import MAX_ITEMS_PER_EXTRA_DATA_TRANSACTION, MAX_NODE_OPERATORS_PER_EXTRA_DATA_ITEM
1616
from utils.config import contracts
17+
from utils.test.staking_router_helpers import increase_staking_module_share
1718

1819
NEW_KEYS_PER_OPERATOR = 2
1920

@@ -234,6 +235,7 @@ def test_extra_data_most_expensive_report(extra_data_service):
234235
An estimate for 8 * 24 items:
235236
Gas used: 11850807 (39.50%)
236237
"""
238+
increase_staking_module_share(module_id=3, share_multiplier=2)
237239

238240
csm_operators_count = MAX_ITEMS_PER_EXTRA_DATA_TRANSACTION * MAX_NODE_OPERATORS_PER_EXTRA_DATA_ITEM
239241
# create or ensure there are max node operators with 1 depositable key

tests/regression/test_all_round_happy_path.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from utils.config import contracts
88
from utils.test.simple_dvt_helpers import fill_simple_dvt_ops_vetted_keys
99
from utils.balance import set_balance
10+
from utils.test.staking_router_helpers import set_staking_module_status, StakingModuleStatus
1011
from utils.test.tx_cost_helper import transaction_cost
1112

1213
def test_all_round_happy_path(accounts, stranger, steth_holder, eth_whale):
@@ -108,9 +109,15 @@ def test_all_round_happy_path(accounts, stranger, steth_holder, eth_whale):
108109

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

112+
# pausing csm due to very high amount of keys in the queue
113+
csm_module_id = 3
114+
set_staking_module_status(csm_module_id, StakingModuleStatus.Stopped)
115+
111116
deposit_tx_nor = contracts.lido.deposit(max_deposit, curated_module_id, "0x0", {"from": dsm})
112117
deposit_tx_sdvt = contracts.lido.deposit(max_deposit, simple_dvt_module_id, "0x0", {"from": dsm})
113118

119+
set_staking_module_status(csm_module_id, StakingModuleStatus.Active)
120+
114121
buffered_ether_after_deposit = contracts.lido.getBufferedEther()
115122

116123
deposited_event_nor = deposit_tx_nor.events["StakingRouterETHDeposited"]

tests/regression/test_csm.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from brownie import reverts, web3, ZERO_ADDRESS
3+
from brownie import reverts, web3, ZERO_ADDRESS, accounts
44

55
from utils.balance import set_balance_in_wei
66
from utils.config import (
@@ -17,11 +17,15 @@
1717
oracle_report, wait_to_next_available_report_time, prepare_csm_report,
1818
reach_consensus,
1919
)
20-
from utils.test.staking_router_helpers import set_staking_module_status, StakingModuleStatus
20+
from utils.test.staking_router_helpers import (
21+
set_staking_module_status, StakingModuleStatus,
22+
increase_staking_module_share,
23+
)
2124

2225
contracts: ContractsLazyLoader = contracts
2326

2427
CSM_MODULE_ID = 3
28+
MAX_DEPOSITS = 50
2529

2630

2731
@pytest.fixture(scope="module")
@@ -43,6 +47,7 @@ def fee_distributor():
4347
def fee_oracle():
4448
return contracts.cs_fee_oracle
4549

50+
4651
@pytest.fixture(scope="module")
4752
def early_adoption():
4853
return contracts.cs_early_adoption
@@ -63,12 +68,18 @@ def pause_modules():
6368
if module[0] != CSM_MODULE_ID:
6469
set_staking_module_status(module[0], StakingModuleStatus.Stopped)
6570

71+
@pytest.fixture
72+
def remove_stake_limit():
73+
contracts.lido.removeStakingLimit({"from": accounts.at(contracts.voting, force=True)})
74+
6675

6776
@pytest.fixture
68-
def deposits_to_csm(csm, pause_modules, node_operator):
77+
def deposits_to_csm(csm, pause_modules, node_operator, remove_stake_limit):
6978
(_, _, depositable) = csm.getStakingModuleSummary()
7079
fill_deposit_buffer(depositable)
71-
contracts.lido.deposit(depositable, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
80+
increase_staking_module_share(module_id=CSM_MODULE_ID, share_multiplier=2)
81+
for i in range(0, depositable, MAX_DEPOSITS):
82+
contracts.lido.deposit(MAX_DEPOSITS, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
7283

7384

7485
@pytest.fixture
@@ -150,12 +161,14 @@ def test_upload_keys_more_than_limit(csm, accounting, node_operator):
150161

151162

152163
@pytest.mark.usefixtures("pause_modules")
153-
def test_deposit(node_operator, csm):
164+
def test_deposit(node_operator, csm, remove_stake_limit):
154165
(_, _, depositable_validators_count) = csm.getStakingModuleSummary()
155166
deposits_count = depositable_validators_count
156167
fill_deposit_buffer(deposits_count)
168+
increase_staking_module_share(module_id=CSM_MODULE_ID, share_multiplier=2)
157169

158-
contracts.lido.deposit(deposits_count, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
170+
for i in range(0, deposits_count, MAX_DEPOSITS):
171+
contracts.lido.deposit(MAX_DEPOSITS, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
159172

160173
no = csm.getNodeOperator(node_operator)
161174
assert no["totalDepositedKeys"] == no["totalAddedKeys"]
@@ -238,7 +251,7 @@ def test_csm_report_stuck(csm, node_operator, extra_data_service):
238251

239252

240253
@pytest.mark.usefixtures("deposits_to_csm")
241-
def test_csm_get_staking_module_summary(csm, accounting, node_operator, extra_data_service):
254+
def test_csm_get_staking_module_summary(csm, accounting, node_operator, extra_data_service, remove_stake_limit):
242255
(exited_before, deposited_before, depositable_before) = contracts.staking_router.getStakingModuleSummary(CSM_MODULE_ID)
243256

244257
# Assure there are new exited keys
@@ -259,8 +272,11 @@ def test_csm_get_staking_module_summary(csm, accounting, node_operator, extra_da
259272
new_keys = 5
260273
new_depositable = new_keys - deposits_count
261274
csm_upload_keys(csm, accounting, node_operator, new_keys)
275+
increase_staking_module_share(module_id=CSM_MODULE_ID, share_multiplier=2)
276+
262277
fill_deposit_buffer(deposits_count)
263-
contracts.lido.deposit(deposits_count, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
278+
for i in range(0, deposits_count, MAX_DEPOSITS):
279+
contracts.lido.deposit(MAX_DEPOSITS, CSM_MODULE_ID, "0x", {"from": contracts.deposit_security_module})
264280

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

tests/regression/test_staking_module_happy_path.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from utils.config import contracts, STAKING_ROUTER, EASYTRACK_EVMSCRIPT_EXECUTOR
1515
from utils.test.node_operators_helpers import distribute_reward, node_operator_gindex
1616
from utils.test.simple_dvt_helpers import fill_simple_dvt_ops_keys
17-
17+
from utils.test.staking_router_helpers import set_staking_module_status, StakingModuleStatus
1818

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

151+
# pausing csm due to very high amount of keys in the queue
152+
csm_module_id = 3
153+
set_staking_module_status(csm_module_id, StakingModuleStatus.Stopped)
154+
151155
contracts.lido.submit(ZERO_ADDRESS, {"from": eth_whale, "amount": ETH(150_000)})
152156

153157
print("Reset staking limit for all OPs...")

utils/test/staking_router_helpers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,18 @@ class StakingModuleStatus(IntEnum):
99

1010
def set_staking_module_status(module_id, staking_module_status: StakingModuleStatus):
1111
contracts.staking_router.setStakingModuleStatus(module_id, staking_module_status, {"from": contracts.agent})
12+
13+
14+
def increase_staking_module_share(module_id, share_multiplier):
15+
module = contracts.staking_router.getStakingModule(module_id)
16+
17+
contracts.staking_router.updateStakingModule(
18+
module_id,
19+
module["stakeShareLimit"] * share_multiplier,
20+
module["priorityExitShareThreshold"] * share_multiplier,
21+
module["stakingModuleFee"],
22+
module["treasuryFee"],
23+
module["maxDepositsPerBlock"],
24+
module["minDepositBlockDistance"],
25+
{"from": contracts.agent},
26+
)

0 commit comments

Comments
 (0)