Skip to content

Commit

Permalink
Merge pull request #534 from lidofinance/fix/staking-router-compatibi…
Browse files Browse the repository at this point in the history
…lity

fix: staking reward v2 backward compatibility
  • Loading branch information
F4ever authored Oct 10, 2024
2 parents f3b33f8 + 6bcd63b commit 9383143
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/providers/execution/contracts/staking_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_staking_modules(self, block_identifier: BlockIdentifier = 'latest') -> l
logger.warning({'msg': 'Use StakingRouterV1.json abi (old one) to parse the response.'})
staking_router = self.w3.eth.contract(
address=self.address,
abi=self.load_abi(super().abi_path),
abi=self.load_abi(StakingRouterContractV1.abi_path),
decode_tuples=True,
)
response = staking_router.functions.getStakingModules().call(block_identifier=block_identifier)
Expand Down
11 changes: 10 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from src.providers.execution.contracts.lido_locator import LidoLocatorContract
from src.providers.execution.contracts.oracle_daemon_config import OracleDaemonConfigContract
from src.providers.execution.contracts.oracle_report_sanity_checker import OracleReportSanityCheckerContract
from src.providers.execution.contracts.staking_router import StakingRouterContractV1
from src.providers.execution.contracts.staking_router import StakingRouterContractV1, StakingRouterContractV2
from src.providers.execution.contracts.withdrawal_queue_nft import WithdrawalQueueNftContract


Expand Down Expand Up @@ -74,6 +74,15 @@ def staking_router_contract(web3_provider_integration, lido_locator_contract) ->
)


@pytest.fixture
def staking_router_contract_v2(web3_provider_integration, lido_locator_contract) -> StakingRouterContractV2:
return get_contract(
web3_provider_integration,
StakingRouterContractV2,
lido_locator_contract.staking_router(),
)


@pytest.fixture
def validators_exit_bus_oracle_contract(web3_provider_integration, lido_locator_contract) -> ExitBusOracleContract:
return get_contract(
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/contracts/test_staking_router.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import pytest

from src.web3py.extensions.lido_validators import StakingModule, NodeOperator
Expand Down Expand Up @@ -25,3 +27,36 @@ def test_staking_router(staking_router_contract, caplog):
],
caplog,
)


@pytest.mark.integration
def test_staking_router_v2(staking_router_contract_v2, caplog):
check_contract(
staking_router_contract_v2,
[
(
'get_all_node_operator_digests',
(StakingModuleFactory.build(id=1),),
lambda response: check_value_type(response, list)
and map(lambda sm: check_value_type(sm, NodeOperator), response),
),
],
caplog,
)


@pytest.mark.integration
def test_backward_compitability_staking_router_v2(staking_router_contract_v2, caplog):
caplog.set_level(logging.DEBUG)

# Block with old staking router
staking_modules = staking_router_contract_v2.get_staking_modules(20929216)

assert "{'msg': 'Use StakingRouterV1.json abi (old one) to parse the response.'}" in caplog.messages

log_with_call = list(filter(lambda log: 'Call ' in log or 'Build ' in log, caplog.messages))

assert 'Call `getContractVersion()`' in log_with_call[0]
assert 'Call `getStakingModules()`' in log_with_call[1]

assert len(staking_modules)

0 comments on commit 9383143

Please sign in to comment.