From cddc8cbe4b79d6f85f00534d85c106caf1763270 Mon Sep 17 00:00:00 2001 From: Ivan Feofanov Date: Thu, 3 Oct 2024 11:48:52 +0200 Subject: [PATCH 1/2] fix: get last exited validator index from the network to avoid real world validators exit impact on tests --- tests/acceptance/test_veb_negative.py | 16 ++++-- .../test_validator_exit_bus_happy_path.py | 55 +++++++++---------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/tests/acceptance/test_veb_negative.py b/tests/acceptance/test_veb_negative.py index cbbf60ba..773a4f3e 100644 --- a/tests/acceptance/test_veb_negative.py +++ b/tests/acceptance/test_veb_negative.py @@ -224,7 +224,10 @@ def test_handle_consensus_report_data_second_exit(contract, ref_slot): no_global_index = (module_id, no_id) = (1, 33) validator_id = 1 validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0] - validator = LidoValidator(validator_id, validator_key) + + # set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error + last_requested_validator_index = contract.getLastRequestedValidatorIndices(module_id, [no_id])[0] + validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key) contract_version = contract.getContractVersion() consensus_version = contract.getConsensusVersion() @@ -287,11 +290,16 @@ def test_handle_consensus_report_data_second_exit(contract, ref_slot): def test_handle_consensus_report_data_invalid_request_order(contract, ref_slot): - no_global_index = (_, no_id) = (1, 33) + module_id = 1 # CuratedModule + no_global_index = (_, no_id) = (module_id, 33) validator_id = 1 validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0] - validator = LidoValidator(validator_id, validator_key) - validator_2 = LidoValidator(2, contracts.node_operators_registry.getSigningKey(no_id, validator_id + 1)[0]) + validator_2_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id + 1)[0] + + # set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error + last_requested_validator_index = contract.getLastRequestedValidatorIndices(module_id, [no_id])[0] + validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key) + validator_2 = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_2_key) contract_version = contract.getContractVersion() consensus_version = contract.getConsensusVersion() diff --git a/tests/regression/test_validator_exit_bus_happy_path.py b/tests/regression/test_validator_exit_bus_happy_path.py index f761651b..81a303db 100644 --- a/tests/regression/test_validator_exit_bus_happy_path.py +++ b/tests/regression/test_validator_exit_bus_happy_path.py @@ -78,7 +78,12 @@ def test_send_validator_to_exit(helpers, web3): no_global_index = (module_id, no_id) = (1, 33) validator_id = 1 validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0] - validator = LidoValidator(validator_id, validator_key) + + # set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error + last_requested_validator_index = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices( + module_id, [no_id] + )[0] + validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key) ref_slot = _wait_for_next_ref_slot() report, report_hash = prepare_exit_bus_report([(no_global_index, validator)], ref_slot) @@ -88,9 +93,6 @@ def test_send_validator_to_exit(helpers, web3): total_requests_before = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed() last_processing_ref_slot_before = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot() processing_state_before = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState()) - last_requested_validator_index_before = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices( - module_id, [no_id] - ) tx = send_report_with_consensus(ref_slot, report, report_hash) @@ -110,7 +112,7 @@ def test_send_validator_to_exit(helpers, web3): { "stakingModuleId": module_id, "nodeOperatorId": no_id, - "validatorIndex": validator_id, + "validatorIndex": last_requested_validator_index + 1, "validatorPubkey": validator_key, "timestamp": web3.eth.get_block(web3.eth.block_number).timestamp, }, @@ -118,8 +120,7 @@ def test_send_validator_to_exit(helpers, web3): assert total_requests_after == total_requests_before + 1 - assert last_requested_validator_index_before == (-1,) - assert last_requested_validator_index_after == (validator_id,) + assert last_requested_validator_index_after == (last_requested_validator_index + 1,) assert last_processing_ref_slot_after != last_processing_ref_slot_before assert last_processing_ref_slot_after == ref_slot @@ -148,12 +149,22 @@ def test_send_multiple_validators_to_exit(helpers, web3, stranger): first_validator_id = 2 second_validator_id = 3 third_validator_id = 0 + first_validator_index = ( + contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(first_module_id, [first_no_id])[0] + 1 + ) + second_validator_index = ( + contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(second_module_id, [second_no_id])[0] + 1 + ) + third_validator_index = ( + contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(third_module_id, [third_no_id])[0] + 1 + ) + first_validator_key = contracts.node_operators_registry.getSigningKey(first_no_id, first_validator_id)[0] second_validator_key = contracts.node_operators_registry.getSigningKey(second_no_id, second_validator_id)[0] third_validator_key = contracts.simple_dvt.getSigningKey(third_no_id, third_validator_id)[0] - first_validator = LidoValidator(first_validator_id, first_validator_key) - second_validator = LidoValidator(second_validator_id, second_validator_key) - third_validator = LidoValidator(third_validator_id, third_validator_key) + first_validator = LidoValidator(index=first_validator_index, pubkey=first_validator_key) + second_validator = LidoValidator(index=second_validator_index, pubkey=second_validator_key) + third_validator = LidoValidator(index=third_validator_index, pubkey=third_validator_key) ref_slot = _wait_for_next_ref_slot() report, report_hash = prepare_exit_bus_report( @@ -170,15 +181,6 @@ def test_send_multiple_validators_to_exit(helpers, web3, stranger): total_requests_before = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed() last_processing_ref_slot_before = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot() processing_state_before = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState()) - first_last_requested_validator_index_before = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices( - first_module_id, [first_no_id] - ) - second_last_requested_validator_index_before = ( - contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(second_module_id, [second_no_id]) - ) - third_last_requested_validator_index_before = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices( - third_module_id, [third_no_id] - ) tx = send_report_with_consensus(ref_slot, report, report_hash) @@ -203,33 +205,30 @@ def test_send_multiple_validators_to_exit(helpers, web3, stranger): assert dict(events[0]) == { "stakingModuleId": first_module_id, "nodeOperatorId": first_no_id, - "validatorIndex": first_validator_id, + "validatorIndex": first_validator_index, "validatorPubkey": first_validator_key, "timestamp": web3.eth.get_block(web3.eth.block_number).timestamp, } assert dict(events[1]) == { "stakingModuleId": second_module_id, "nodeOperatorId": second_no_id, - "validatorIndex": second_validator_id, + "validatorIndex": second_validator_index, "validatorPubkey": second_validator_key, "timestamp": web3.eth.get_block(web3.eth.block_number).timestamp, } assert dict(events[2]) == { "stakingModuleId": third_module_id, "nodeOperatorId": third_no_id, - "validatorIndex": third_validator_id, + "validatorIndex": third_validator_index, "validatorPubkey": third_validator_key, "timestamp": web3.eth.get_block(web3.eth.block_number).timestamp, } assert total_requests_after == total_requests_before + 3 - assert first_last_requested_validator_index_before == (-1,) - assert second_last_requested_validator_index_before == (-1,) - assert third_last_requested_validator_index_before == (-1,) - assert first_last_requested_validator_index_after == (first_validator_id,) - assert second_last_requested_validator_index_after == (second_validator_id,) - assert third_last_requested_validator_index_after == (third_validator_id,) + assert first_last_requested_validator_index_after == (first_validator_index,) + assert second_last_requested_validator_index_after == (second_validator_index,) + assert third_last_requested_validator_index_after == (third_validator_index,) assert last_processing_ref_slot_after != last_processing_ref_slot_before assert last_processing_ref_slot_after == ref_slot From fd84ca8f5c5c6e4fdad1bfcfab0af2c0be0c9c4c Mon Sep 17 00:00:00 2001 From: skhomuti Date: Mon, 14 Oct 2024 15:56:01 +0500 Subject: [PATCH 2/2] fix for review fix zero balance on node operator reward address --- tests/acceptance/test_veb_negative.py | 29 +++++++------------ .../test_validator_exit_bus_happy_path.py | 27 ++++++----------- utils/test/simple_dvt_helpers.py | 7 ++++- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/tests/acceptance/test_veb_negative.py b/tests/acceptance/test_veb_negative.py index 773a4f3e..b96a53cf 100644 --- a/tests/acceptance/test_veb_negative.py +++ b/tests/acceptance/test_veb_negative.py @@ -221,13 +221,12 @@ def test_handle_consensus_report_data_wrong_module_id(contract, ref_slot): def test_handle_consensus_report_data_second_exit(contract, ref_slot): + unreachable_cl_validator_index = 100_000_000 no_global_index = (module_id, no_id) = (1, 33) - validator_id = 1 - validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0] + validator_key = contracts.node_operators_registry.getSigningKey(no_id, 1)[0] # set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error - last_requested_validator_index = contract.getLastRequestedValidatorIndices(module_id, [no_id])[0] - validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key) + validator = LidoValidator(index=unreachable_cl_validator_index, pubkey=validator_key) contract_version = contract.getContractVersion() consensus_version = contract.getConsensusVersion() @@ -251,10 +250,6 @@ def test_handle_consensus_report_data_second_exit(contract, ref_slot): contract.submitReportData(report, contract_version, {"from": submitter}) - last_requested_validator_index_before = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices( - module_id, [no_id] - ) - wait_to_next_available_report_time(contracts.hash_consensus_for_validators_exit_bus_oracle) ref_slot, _ = contracts.hash_consensus_for_validators_exit_bus_oracle.getCurrentFrame() @@ -281,8 +276,8 @@ def test_handle_consensus_report_data_second_exit(contract, ref_slot): ( module_id, no_id, - last_requested_validator_index_before[0], - last_requested_validator_index_before[0], + unreachable_cl_validator_index, + unreachable_cl_validator_index, ), ) ): @@ -290,16 +285,14 @@ def test_handle_consensus_report_data_second_exit(contract, ref_slot): def test_handle_consensus_report_data_invalid_request_order(contract, ref_slot): - module_id = 1 # CuratedModule - no_global_index = (_, no_id) = (module_id, 33) - validator_id = 1 - validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0] - validator_2_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id + 1)[0] + unreachable_cl_validator_index = 100_000_000 + no_global_index = (module_id, no_id) = (1, 33) # Curated module + validator_key = contracts.node_operators_registry.getSigningKey(no_id, 1)[0] + validator_2_key = contracts.node_operators_registry.getSigningKey(no_id, 2)[0] # set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error - last_requested_validator_index = contract.getLastRequestedValidatorIndices(module_id, [no_id])[0] - validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key) - validator_2 = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_2_key) + validator = LidoValidator(index=unreachable_cl_validator_index, pubkey=validator_key) + validator_2 = LidoValidator(index=unreachable_cl_validator_index + 1, pubkey=validator_2_key) contract_version = contract.getContractVersion() consensus_version = contract.getConsensusVersion() diff --git a/tests/regression/test_validator_exit_bus_happy_path.py b/tests/regression/test_validator_exit_bus_happy_path.py index 81a303db..c37af9c9 100644 --- a/tests/regression/test_validator_exit_bus_happy_path.py +++ b/tests/regression/test_validator_exit_bus_happy_path.py @@ -75,15 +75,11 @@ def test_send_zero_validators_to_exit(helpers): def test_send_validator_to_exit(helpers, web3): + unreachable_cl_validator_index = 100_000_000 no_global_index = (module_id, no_id) = (1, 33) - validator_id = 1 - validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0] + validator_key = contracts.node_operators_registry.getSigningKey(no_id, 1)[0] - # set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error - last_requested_validator_index = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices( - module_id, [no_id] - )[0] - validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key) + validator = LidoValidator(index=unreachable_cl_validator_index, pubkey=validator_key) ref_slot = _wait_for_next_ref_slot() report, report_hash = prepare_exit_bus_report([(no_global_index, validator)], ref_slot) @@ -112,7 +108,7 @@ def test_send_validator_to_exit(helpers, web3): { "stakingModuleId": module_id, "nodeOperatorId": no_id, - "validatorIndex": last_requested_validator_index + 1, + "validatorIndex": unreachable_cl_validator_index, "validatorPubkey": validator_key, "timestamp": web3.eth.get_block(web3.eth.block_number).timestamp, }, @@ -120,7 +116,7 @@ def test_send_validator_to_exit(helpers, web3): assert total_requests_after == total_requests_before + 1 - assert last_requested_validator_index_after == (last_requested_validator_index + 1,) + assert last_requested_validator_index_after == (unreachable_cl_validator_index,) assert last_processing_ref_slot_after != last_processing_ref_slot_before assert last_processing_ref_slot_after == ref_slot @@ -136,6 +132,7 @@ def test_send_multiple_validators_to_exit(helpers, web3, stranger): """ The same as test above but with multiple validators on different node operators and modules """ + unreachable_cl_validator_index = 100_000_000 # Fill SDVT simple_dvt_add_node_operators( contracts.simple_dvt, stranger, [("SDVT Operator", f"0xab{'1' * 38}", f"0xcd{'1' * 38}")] @@ -149,15 +146,9 @@ def test_send_multiple_validators_to_exit(helpers, web3, stranger): first_validator_id = 2 second_validator_id = 3 third_validator_id = 0 - first_validator_index = ( - contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(first_module_id, [first_no_id])[0] + 1 - ) - second_validator_index = ( - contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(second_module_id, [second_no_id])[0] + 1 - ) - third_validator_index = ( - contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(third_module_id, [third_no_id])[0] + 1 - ) + first_validator_index = unreachable_cl_validator_index + second_validator_index = unreachable_cl_validator_index + 1 + third_validator_index = unreachable_cl_validator_index + 2 first_validator_key = contracts.node_operators_registry.getSigningKey(first_no_id, first_validator_id)[0] second_validator_key = contracts.node_operators_registry.getSigningKey(second_no_id, second_validator_id)[0] diff --git a/utils/test/simple_dvt_helpers.py b/utils/test/simple_dvt_helpers.py index 3c8a99ce..b7c10225 100644 --- a/utils/test/simple_dvt_helpers.py +++ b/utils/test/simple_dvt_helpers.py @@ -1,4 +1,4 @@ -from brownie import chain, accounts, interface +from brownie import accounts, interface, web3 from utils.config import ( contracts, EASYTRACK_SIMPLE_DVT_TRUSTED_CALLER, @@ -130,6 +130,11 @@ def simple_dvt_add_keys(simple_dvt, node_operator_id, keys_count=1): unused_signing_keys_count_before = simple_dvt.getUnusedSigningKeyCount(node_operator_id) node_operator_before = simple_dvt.getNodeOperator(node_operator_id, False) + reward_address = node_operator_before["rewardAddress"] + if accounts.at(reward_address, force=True).balance() == 0: + web3.provider.make_request("evm_setAccountBalance", [reward_address, "0x152D02C7E14AF6800000"]) + web3.provider.make_request("hardhat_setBalance", [reward_address, "0x152D02C7E14AF6800000"]) + tx = simple_dvt.addSigningKeys( node_operator_id, batch_size,