Skip to content

Commit

Permalink
Merge pull request #3555 from ethereum/random-blob_kzg_commitment_mer…
Browse files Browse the repository at this point in the history
…kle_proof

Add randomized block `blob_kzg_commitment_merkle_proof` cases
  • Loading branch information
djrtwo authored Nov 30, 2023
2 parents 8fa1f8e + 6a460ae commit 113c58f
Showing 1 changed file with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
import random

from eth2spec.test.context import (
spec_state_test,
with_deneb_and_later,
with_test_suite_name,
)
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,
)
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)
Expand All @@ -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)

0 comments on commit 113c58f

Please sign in to comment.