From 05a323e83a8b2a5c04725c9bcd83b6b53e61a2dc Mon Sep 17 00:00:00 2001 From: Katya Ryazantseva Date: Thu, 19 Dec 2024 18:42:30 +0100 Subject: [PATCH] fix random withdrawals --- .../test/helpers/execution_payload.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 403100c3b1..8b1e2bc553 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -8,10 +8,7 @@ from eth2spec.test.helpers.keys import privkeys from eth2spec.utils.ssz.ssz_impl import hash_tree_root from eth2spec.debug.random_value import get_random_bytes_list -from eth2spec.test.helpers.withdrawals import ( - get_expected_withdrawals, - get_random_withdrawal, -) +from eth2spec.test.helpers.withdrawals import get_expected_withdrawals from eth2spec.test.helpers.forks import ( is_post_capella, is_post_deneb, @@ -369,6 +366,7 @@ def build_empty_execution_payload(spec, state, randao_mix=None): def build_randomized_execution_payload(spec, state, rng): + from eth2spec.test.helpers.random import exit_random_validators execution_payload = build_empty_execution_payload(spec, state) execution_payload.fee_recipient = spec.ExecutionAddress(get_random_bytes_list(rng, 20)) execution_payload.state_root = spec.Bytes32(get_random_bytes_list(rng, 32)) @@ -390,12 +388,19 @@ def build_randomized_execution_payload(spec, state, rng): get_random_tx(rng) for _ in range(num_transactions) ] + if is_post_capella(spec): - num_withdrawals = rng.randint(0, spec.MAX_WITHDRAWALS_PER_PAYLOAD) - execution_payload.withdrawals = [ - get_random_withdrawal(spec, state, rng) - for _ in range(num_withdrawals) - ] + current_epoch = spec.get_current_epoch(state) + exit_random_validators( + spec, + state, + rng, + exit_epoch=current_epoch, + withdrawable_epoch=current_epoch, + from_epoch=current_epoch + ) + execution_payload.withdrawals = get_expected_withdrawals(spec, state) + if is_post_deneb(spec): execution_payload.blob_gas_used = rng.randint(0, int(10e10)) execution_payload.excess_blob_gas = rng.randint(0, int(10e10))