diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py index 75dfa0c9cf..6ac76ca596 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py @@ -33,7 +33,7 @@ def test_empty_block_transition_no_tx(spec, state): @with_bellatrix_and_later @spec_state_test -def test_empty_block_transition_randomized_payload(spec, state): +def test_block_transition_randomized_payload(spec, state): yield 'pre', state block = build_empty_block_for_next_slot(spec, state) diff --git a/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py index eecd7ad469..5c9cd6e2ca 100644 --- a/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py @@ -1,3 +1,5 @@ +import random + from eth2spec.test.helpers.state import ( state_transition_and_sign_block, next_epoch_via_block, @@ -15,6 +17,7 @@ ) from eth2spec.test.helpers.execution_payload import ( compute_el_block_hash, + get_random_tx, ) from eth2spec.test.helpers.attestations import ( get_valid_attestation, @@ -24,7 +27,8 @@ ) -def run_block_with_blobs(spec, state, blob_count, data_gas_used=1, excess_data_gas=1, valid=True, tx_count=1): +def run_block_with_blobs(spec, state, blob_count, tx_count=1, data_gas_used=1, excess_data_gas=1, + non_blob_tx_count=0, rng=random.Random(7777), valid=True): yield 'pre', state block = build_empty_block_for_next_slot(spec, state) @@ -35,6 +39,9 @@ def run_block_with_blobs(spec, state, blob_count, data_gas_used=1, excess_data_g txs.append(opaque_tx) blob_kzg_commitments += commits + for _ in range(non_blob_tx_count): + txs.append(get_random_tx(rng=rng)) + block.body.blob_kzg_commitments = blob_kzg_commitments block.body.execution_payload.transactions = txs block.body.execution_payload.data_gas_used = data_gas_used @@ -98,6 +105,12 @@ def test_invalid_exceed_max_blobs_per_block(spec, state): yield from run_block_with_blobs(spec, state, blob_count=spec.MAX_BLOBS_PER_BLOCK + 1, valid=False) +@with_deneb_and_later +@spec_state_test +def test_mix_blob_tx_and_non_blob_tx(spec, state): + yield from run_block_with_blobs(spec, state, blob_count=1, tx_count=1, non_blob_tx_count=1) + + @with_phases([DENEB]) @spec_configured_state_test({ 'DENEB_FORK_EPOCH': 2, diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 2f9c0e0a46..00f7a4bb7b 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -259,7 +259,7 @@ def build_randomized_execution_payload(spec, state, rng): num_transactions = rng.randint(0, 100) execution_payload.transactions = [ - spec.Transaction(get_random_bytes_list(rng, rng.randint(0, 1000))) + get_random_tx(rng) for _ in range(num_transactions) ] @@ -290,3 +290,7 @@ def build_state_with_execution_payload_header(spec, state, execution_payload_hea pre_state.latest_execution_payload_header = execution_payload_header return pre_state + + +def get_random_tx(rng): + return get_random_bytes_list(rng, rng.randint(0, 1000)) 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 c164515103..3255de87a6 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 eth2spec.test.helpers.execution_payload import ( compute_el_block_hash, + build_randomized_execution_payload, ) from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state_for_next_slot, @@ -216,14 +217,17 @@ def random_block_altair_with_cycling_sync_committee_participation(spec, return block -def random_block_bellatrix(spec, state, signed_blocks, scenario_state): +def random_block_bellatrix(spec, state, signed_blocks, scenario_state, rng=Random(3456)): block = random_block_altair_with_cycling_sync_committee_participation(spec, state, signed_blocks, scenario_state) - # TODO: return randomized execution payload + # build execution_payload at the next slot + state = state.copy() + next_slot(spec, state) + block.body.execution_payload = build_randomized_execution_payload(spec, state, rng=rng) return block def random_block_capella(spec, state, signed_blocks, scenario_state, rng=Random(3456)): - block = random_block_bellatrix(spec, state, signed_blocks, scenario_state) + block = random_block_bellatrix(spec, state, signed_blocks, scenario_state, rng=rng) block.body.bls_to_execution_changes = get_random_bls_to_execution_changes( spec, state, @@ -233,10 +237,11 @@ def random_block_capella(spec, state, signed_blocks, scenario_state, rng=Random( def random_block_deneb(spec, state, signed_blocks, scenario_state, rng=Random(3456)): - block = random_block_capella(spec, state, signed_blocks, scenario_state) + block = random_block_capella(spec, state, signed_blocks, scenario_state, rng=rng) # TODO: more commitments. blob_kzg_commitments: List[KZGCommitment, MAX_BLOBS_PER_BLOCK] - opaque_tx, _, blob_kzg_commitments, _ = get_sample_opaque_tx(spec, blob_count=1) - block.body.execution_payload.transactions = [opaque_tx] + opaque_tx, _, blob_kzg_commitments, _ = get_sample_opaque_tx( + spec, blob_count=rng.randint(0, spec.MAX_BLOBS_PER_BLOCK), rng=rng) + block.body.execution_payload.transactions.append(opaque_tx) block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload) block.body.blob_kzg_commitments = blob_kzg_commitments