diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 44ed0ae89..c11bb5584 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -16,6 +16,7 @@ from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing from eth2spec.test.helpers.attestations import get_valid_attestation from eth2spec.test.helpers.deposits import build_deposit, deposit_from_context from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits +from eth2spec.test.helpers.bls_to_execution_changes import get_signed_address_change def run_slash_and_exit(spec, state, slash_index, exit_index, valid=True): @@ -126,13 +127,15 @@ def get_random_deposits(spec, state, rng, num_deposits=None): # First build deposit data leaves for i in range(num_deposits): index = len(state.validators) + i + withdrawal_pubkey = pubkeys[-1 - index] + withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(withdrawal_pubkey)[1:] _, root, deposit_data_leaves = build_deposit( spec, deposit_data_leaves, pubkeys[index], privkeys[index], spec.MAX_EFFECTIVE_BALANCE, - withdrawal_credentials=b'\x00' * 32, + withdrawal_credentials=withdrawal_credentials, signed=True, ) @@ -200,6 +203,20 @@ def get_random_sync_aggregate(spec, state, slot, block_root=None, fraction_parti ) +def get_random_bls_to_execution_changes(spec, state, rng=Random(2188), num_address_changes=0): + bls_indices = [ + index + for index, validator in enumerate(state.validators) + if validator.withdrawal_credentials[:1] == spec.BLS_WITHDRAWAL_PREFIX + ] + assert len(bls_indices) > 0 + + return [ + get_signed_address_change(spec, state, validator_index=validator_index) + for validator_index in rng.sample(bls_indices, min(num_address_changes, len(bls_indices))) + ] + + def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188), deposits=None): block = build_empty_block_for_next_slot(spec, state) proposer_slashings = get_random_proposer_slashings(spec, state, rng) diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index c66970ba7..5504a53d7 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -9,6 +9,7 @@ from typing import Callable from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state_for_next_slot, + get_random_bls_to_execution_changes, get_random_sync_aggregate, prepare_state_and_get_random_deposits, ) @@ -204,8 +205,13 @@ def random_block_bellatrix(spec, state, signed_blocks, scenario_state): return block -def random_block_capella(spec, state, signed_blocks, scenario_state): +def random_block_capella(spec, state, signed_blocks, scenario_state, rng=Random(3456)): block = random_block_bellatrix(spec, state, signed_blocks, scenario_state) + block.body.bls_to_execution_changes = get_random_bls_to_execution_changes( + spec, + state, + num_address_changes=rng.randint(1, spec.MAX_BLS_TO_EXECUTION_CHANGES) + ) return block