Skip to content

Commit

Permalink
Merge pull request #3457 from ethereum/more-deneb-tests
Browse files Browse the repository at this point in the history
More deneb tests
  • Loading branch information
hwwhww committed Jul 20, 2023
2 parents ff2840e + 0799799 commit aca1202
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 48 additions & 3 deletions tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

from eth2spec.test.helpers.state import (
state_transition_and_sign_block,
next_epoch_via_block,
Expand All @@ -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,
Expand All @@ -24,13 +27,25 @@
)


def run_block_with_blobs(spec, state, blob_count, data_gas_used=1, excess_data_gas=1, valid=True):
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)
opaque_tx, _, blob_kzg_commitments, _ = get_sample_opaque_tx(spec, blob_count=blob_count)
txs = []
blob_kzg_commitments = []
for _ in range(tx_count):
opaque_tx, _, commits, _ = get_sample_opaque_tx(spec, blob_count=blob_count)
txs.append(opaque_tx)
blob_kzg_commitments += commits

for _ in range(non_blob_tx_count):
txs.append(get_random_tx(rng))

rng.shuffle(txs)

block.body.blob_kzg_commitments = blob_kzg_commitments
block.body.execution_payload.transactions = [opaque_tx]
block.body.execution_payload.transactions = txs
block.body.execution_payload.data_gas_used = data_gas_used
block.body.execution_payload.excess_data_gas = excess_data_gas
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
Expand All @@ -56,18 +71,48 @@ def test_one_blob(spec, state):
yield from run_block_with_blobs(spec, state, blob_count=1)


@with_deneb_and_later
@spec_state_test
def test_one_blob_two_txs(spec, state):
yield from run_block_with_blobs(spec, state, blob_count=1, tx_count=2)


@with_deneb_and_later
@spec_state_test
def test_one_blob_max_txs(spec, state):
yield from run_block_with_blobs(spec, state, blob_count=1, tx_count=spec.MAX_BLOBS_PER_BLOCK)


@with_deneb_and_later
@spec_state_test
def test_invalid_one_blob_max_plus_one_txs(spec, state):
yield from run_block_with_blobs(spec, state, blob_count=1, tx_count=spec.MAX_BLOBS_PER_BLOCK + 1, valid=False)


@with_deneb_and_later
@spec_state_test
def test_max_blobs_per_block(spec, state):
yield from run_block_with_blobs(spec, state, blob_count=spec.MAX_BLOBS_PER_BLOCK)


@with_deneb_and_later
@spec_state_test
def test_invalid_max_blobs_per_block_two_txs(spec, state):
yield from run_block_with_blobs(spec, state, blob_count=spec.MAX_BLOBS_PER_BLOCK, tx_count=2, valid=False)


@with_deneb_and_later
@spec_state_test
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,
Expand Down
6 changes: 5 additions & 1 deletion tests/core/pyspec/eth2spec/test/helpers/execution_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]

Expand Down Expand Up @@ -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))
17 changes: 11 additions & 6 deletions tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down

0 comments on commit aca1202

Please sign in to comment.