Skip to content

Commit 113c58f

Browse files
authored
Merge pull request #3555 from ethereum/random-blob_kzg_commitment_merkle_proof
Add randomized block `blob_kzg_commitment_merkle_proof` cases
2 parents 8fa1f8e + 6a460ae commit 113c58f

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

tests/core/pyspec/eth2spec/test/deneb/merkle_proof/test_single_merkle_proof.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1+
import random
2+
13
from eth2spec.test.context import (
24
spec_state_test,
35
with_deneb_and_later,
46
with_test_suite_name,
57
)
68
from eth2spec.test.helpers.block import (
79
build_empty_block_for_next_slot,
8-
sign_block
10+
sign_block,
911
)
1012
from eth2spec.test.helpers.execution_payload import (
1113
compute_el_block_hash,
1214
)
1315
from eth2spec.test.helpers.sharding import (
1416
get_sample_opaque_tx,
1517
)
18+
from eth2spec.debug.random_value import (
19+
RandomizationMode,
20+
get_random_ssz_object,
21+
)
1622

1723

18-
@with_test_suite_name("BeaconBlockBody")
19-
@with_deneb_and_later
20-
@spec_state_test
21-
def test_blob_kzg_commitment_merkle_proof(spec, state):
24+
def _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=None):
2225
opaque_tx, blobs, blob_kzg_commitments, proofs = get_sample_opaque_tx(spec, blob_count=1)
23-
block = build_empty_block_for_next_slot(spec, state)
26+
if rng is None:
27+
block = build_empty_block_for_next_slot(spec, state)
28+
else:
29+
block = get_random_ssz_object(
30+
rng,
31+
spec.BeaconBlock,
32+
max_bytes_length=2000,
33+
max_list_length=2000,
34+
mode=RandomizationMode,
35+
chaos=True,
36+
)
2437
block.body.blob_kzg_commitments = blob_kzg_commitments
2538
block.body.execution_payload.transactions = [opaque_tx]
2639
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):
4457
index=spec.get_subtree_index(gindex),
4558
root=blob_sidecar.signed_block_header.message.body_root,
4659
)
60+
61+
62+
@with_test_suite_name("BeaconBlockBody")
63+
@with_deneb_and_later
64+
@spec_state_test
65+
def test_blob_kzg_commitment_merkle_proof__basic(spec, state):
66+
yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state)
67+
68+
69+
@with_test_suite_name("BeaconBlockBody")
70+
@with_deneb_and_later
71+
@spec_state_test
72+
def test_blob_kzg_commitment_merkle_proof__random_block_1(spec, state):
73+
rng = random.Random(1111)
74+
yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=rng)
75+
76+
77+
@with_test_suite_name("BeaconBlockBody")
78+
@with_deneb_and_later
79+
@spec_state_test
80+
def test_blob_kzg_commitment_merkle_proof__random_block_2(spec, state):
81+
rng = random.Random(2222)
82+
yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=rng)
83+
84+
85+
@with_test_suite_name("BeaconBlockBody")
86+
@with_deneb_and_later
87+
@spec_state_test
88+
def test_blob_kzg_commitment_merkle_proof__random_block_3(spec, state):
89+
rng = random.Random(3333)
90+
yield from _run_blob_kzg_commitment_merkle_proof_test(spec, state, rng=rng)

0 commit comments

Comments
 (0)