From 6a460aeba1338a5753c8e357236bbed78ed379cc Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 30 Nov 2023 23:06:27 +0800 Subject: [PATCH] Add randomized block cases --- .../merkle_proof/test_single_merkle_proof.py | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/deneb/merkle_proof/test_single_merkle_proof.py b/tests/core/pyspec/eth2spec/test/deneb/merkle_proof/test_single_merkle_proof.py index 75bcacc7fc..8ec6a1d927 100644 --- a/tests/core/pyspec/eth2spec/test/deneb/merkle_proof/test_single_merkle_proof.py +++ b/tests/core/pyspec/eth2spec/test/deneb/merkle_proof/test_single_merkle_proof.py @@ -1,3 +1,5 @@ +import random + from eth2spec.test.context import ( spec_state_test, with_deneb_and_later, @@ -5,7 +7,7 @@ ) from eth2spec.test.helpers.block import ( build_empty_block_for_next_slot, - sign_block + sign_block, ) from eth2spec.test.helpers.execution_payload import ( compute_el_block_hash, @@ -13,14 +15,25 @@ from eth2spec.test.helpers.sharding import ( get_sample_opaque_tx, ) +from eth2spec.debug.random_value import ( + RandomizationMode, + get_random_ssz_object, +) -@with_test_suite_name("BeaconBlockBody") -@with_deneb_and_later -@spec_state_test -def test_blob_kzg_commitment_merkle_proof(spec, state): +def _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=None): opaque_tx, blobs, blob_kzg_commitments, proofs = get_sample_opaque_tx(spec, blob_count=1) - block = build_empty_block_for_next_slot(spec, state) + if rng is None: + block = build_empty_block_for_next_slot(spec, state) + else: + block = get_random_ssz_object( + rng, + spec.BeaconBlock, + max_bytes_length=2000, + max_list_length=2000, + mode=RandomizationMode, + chaos=True, + ) block.body.blob_kzg_commitments = blob_kzg_commitments block.body.execution_payload.transactions = [opaque_tx] block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload) @@ -44,3 +57,34 @@ def test_blob_kzg_commitment_merkle_proof(spec, state): index=spec.get_subtree_index(gindex), root=blob_sidecar.signed_block_header.message.body_root, ) + + +@with_test_suite_name("BeaconBlockBody") +@with_deneb_and_later +@spec_state_test +def test_blob_kzg_commitment_merkle_proof__basic(spec, state): + yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state) + + +@with_test_suite_name("BeaconBlockBody") +@with_deneb_and_later +@spec_state_test +def test_blob_kzg_commitment_merkle_proof__random_block_1(spec, state): + rng = random.Random(1111) + yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=rng) + + +@with_test_suite_name("BeaconBlockBody") +@with_deneb_and_later +@spec_state_test +def test_blob_kzg_commitment_merkle_proof__random_block_2(spec, state): + rng = random.Random(2222) + yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=rng) + + +@with_test_suite_name("BeaconBlockBody") +@with_deneb_and_later +@spec_state_test +def test_blob_kzg_commitment_merkle_proof__random_block_3(spec, state): + rng = random.Random(3333) + yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=rng)