diff --git a/src/providers/execution/contracts/staking_router.py b/src/providers/execution/contracts/staking_router.py index 1f8d33582..8d0508708 100644 --- a/src/providers/execution/contracts/staking_router.py +++ b/src/providers/execution/contracts/staking_router.py @@ -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) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index a9bcb1a33..f912a64b0 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -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 @@ -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( diff --git a/tests/integration/contracts/test_staking_router.py b/tests/integration/contracts/test_staking_router.py index e55f653f9..86f813db1 100644 --- a/tests/integration/contracts/test_staking_router.py +++ b/tests/integration/contracts/test_staking_router.py @@ -1,3 +1,5 @@ +import logging + import pytest from src.web3py.extensions.lido_validators import StakingModule, NodeOperator @@ -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)