diff --git a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py index e3ebcae7e..39626ee05 100644 --- a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py +++ b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py @@ -124,7 +124,7 @@ def test_basic_withdrawal_request_with_full_partial_withdrawal_queue(spec, state ) -# Invalid tests +# Tests that should fail @with_electra_and_later @@ -237,6 +237,31 @@ def test_activation_epoch_less_than_shard_committee_period(spec, state): ) +@with_electra_and_later +@spec_state_test +def test_unknown_pubkey(spec, state): + rng = random.Random(1344) + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + current_epoch = spec.get_current_epoch(state) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) + address = b"\x22" * 20 + pubkey = spec.BLSPubkey(b"\x23" * 48) + set_eth1_withdrawal_credential_with_balance( + spec, state, validator_index, address=address + ) + withdrawal_request = spec.WithdrawalRequest( + source_address=address, + validator_pubkey=pubkey, + amount=spec.FULL_EXIT_REQUEST_AMOUNT, + ) + + yield from run_withdrawal_request_processing( + spec, state, withdrawal_request, success=False + ) + + # Partial withdrawals tests @with_electra_and_later @@ -896,10 +921,6 @@ def run_withdrawal_request_processing( If ``valid == False``, run expecting ``AssertionError`` If ``success == False``, it doesn't initiate exit successfully """ - validator_index = get_validator_index_by_pubkey( - state, withdrawal_request.validator_pubkey - ) - yield "pre", state yield "withdrawal_request", withdrawal_request @@ -912,14 +933,7 @@ def run_withdrawal_request_processing( yield "post", None return - pre_exit_epoch = state.validators[validator_index].exit_epoch - pre_pending_partial_withdrawals = state.pending_partial_withdrawals.copy() - pre_balance = state.balances[validator_index] - pre_effective_balance = state.validators[validator_index].effective_balance pre_state = state.copy() - expected_amount_to_withdraw = compute_amount_to_withdraw( - spec, state, validator_index, withdrawal_request.amount - ) spec.process_withdrawal_request( state, withdrawal_request @@ -931,6 +945,13 @@ def run_withdrawal_request_processing( # No-op assert pre_state == state else: + validator_index = get_validator_index_by_pubkey( + state, withdrawal_request.validator_pubkey + ) + pre_exit_epoch = pre_state.validators[validator_index].exit_epoch + pre_pending_partial_withdrawals = pre_state.pending_partial_withdrawals.copy() + pre_balance = pre_state.balances[validator_index] + pre_effective_balance = pre_state.validators[validator_index].effective_balance assert state.balances[validator_index] == pre_balance assert ( state.validators[validator_index].effective_balance == pre_effective_balance @@ -943,6 +964,9 @@ def run_withdrawal_request_processing( assert state.pending_partial_withdrawals == pre_pending_partial_withdrawals # Partial withdrawal request else: + expected_amount_to_withdraw = compute_amount_to_withdraw( + spec, pre_state, validator_index, withdrawal_request.amount + ) assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH expected_withdrawable_epoch = ( state.earliest_exit_epoch