Skip to content

Commit 778a32a

Browse files
committed
Add missing withdrawal requests tests
1 parent da3b23a commit 778a32a

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_basic_withdrawal_request_with_full_partial_withdrawal_queue(spec, state
124124
)
125125

126126

127-
# Invalid tests
127+
# Tests that should fail
128128

129129

130130
@with_electra_and_later
@@ -237,6 +237,31 @@ def test_activation_epoch_less_than_shard_committee_period(spec, state):
237237
)
238238

239239

240+
@with_electra_and_later
241+
@spec_state_test
242+
def test_unknown_pubkey(spec, state):
243+
rng = random.Random(1344)
244+
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
245+
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
246+
247+
current_epoch = spec.get_current_epoch(state)
248+
validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch))
249+
address = b"\x22" * 20
250+
pubkey = spec.BLSPubkey(b"\x23" * 48)
251+
set_eth1_withdrawal_credential_with_balance(
252+
spec, state, validator_index, address=address
253+
)
254+
withdrawal_request = spec.WithdrawalRequest(
255+
source_address=address,
256+
validator_pubkey=pubkey,
257+
amount=spec.FULL_EXIT_REQUEST_AMOUNT,
258+
)
259+
260+
yield from run_withdrawal_request_processing(
261+
spec, state, withdrawal_request, success=False
262+
)
263+
264+
240265
# Partial withdrawals tests
241266

242267
@with_electra_and_later
@@ -896,10 +921,6 @@ def run_withdrawal_request_processing(
896921
If ``valid == False``, run expecting ``AssertionError``
897922
If ``success == False``, it doesn't initiate exit successfully
898923
"""
899-
validator_index = get_validator_index_by_pubkey(
900-
state, withdrawal_request.validator_pubkey
901-
)
902-
903924
yield "pre", state
904925
yield "withdrawal_request", withdrawal_request
905926

@@ -912,14 +933,7 @@ def run_withdrawal_request_processing(
912933
yield "post", None
913934
return
914935

915-
pre_exit_epoch = state.validators[validator_index].exit_epoch
916-
pre_pending_partial_withdrawals = state.pending_partial_withdrawals.copy()
917-
pre_balance = state.balances[validator_index]
918-
pre_effective_balance = state.validators[validator_index].effective_balance
919936
pre_state = state.copy()
920-
expected_amount_to_withdraw = compute_amount_to_withdraw(
921-
spec, state, validator_index, withdrawal_request.amount
922-
)
923937

924938
spec.process_withdrawal_request(
925939
state, withdrawal_request
@@ -931,6 +945,13 @@ def run_withdrawal_request_processing(
931945
# No-op
932946
assert pre_state == state
933947
else:
948+
validator_index = get_validator_index_by_pubkey(
949+
state, withdrawal_request.validator_pubkey
950+
)
951+
pre_exit_epoch = pre_state.validators[validator_index].exit_epoch
952+
pre_pending_partial_withdrawals = pre_state.pending_partial_withdrawals.copy()
953+
pre_balance = pre_state.balances[validator_index]
954+
pre_effective_balance = pre_state.validators[validator_index].effective_balance
934955
assert state.balances[validator_index] == pre_balance
935956
assert (
936957
state.validators[validator_index].effective_balance == pre_effective_balance
@@ -943,6 +964,9 @@ def run_withdrawal_request_processing(
943964
assert state.pending_partial_withdrawals == pre_pending_partial_withdrawals
944965
# Partial withdrawal request
945966
else:
967+
expected_amount_to_withdraw = compute_amount_to_withdraw(
968+
spec, pre_state, validator_index, withdrawal_request.amount
969+
)
946970
assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH
947971
expected_withdrawable_epoch = (
948972
state.earliest_exit_epoch

0 commit comments

Comments
 (0)