mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 15:38:55 +00:00
Use build_randomized_execution_payload
in random tests. Add mixed txs tests.
This commit is contained in:
parent
51e60c19d6
commit
350fa16020
@ -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)
|
||||
|
@ -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.context import (
|
||||
)
|
||||
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 @@ from eth2spec.test.helpers.sharding import (
|
||||
)
|
||||
|
||||
|
||||
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,
|
||||
|
@ -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))
|
||||
|
@ -9,6 +9,7 @@ from typing import Callable
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user