mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-13 11:06:31 +00:00
Merge pull request #3457 from ethereum/more-deneb-tests
More deneb tests
This commit is contained in:
commit
aca1202eba
@ -33,7 +33,7 @@ def test_empty_block_transition_no_tx(spec, state):
|
|||||||
|
|
||||||
@with_bellatrix_and_later
|
@with_bellatrix_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_empty_block_transition_randomized_payload(spec, state):
|
def test_block_transition_randomized_payload(spec, state):
|
||||||
yield 'pre', state
|
yield 'pre', state
|
||||||
|
|
||||||
block = build_empty_block_for_next_slot(spec, state)
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
from eth2spec.test.helpers.state import (
|
from eth2spec.test.helpers.state import (
|
||||||
state_transition_and_sign_block,
|
state_transition_and_sign_block,
|
||||||
next_epoch_via_block,
|
next_epoch_via_block,
|
||||||
@ -15,6 +17,7 @@ from eth2spec.test.context import (
|
|||||||
)
|
)
|
||||||
from eth2spec.test.helpers.execution_payload import (
|
from eth2spec.test.helpers.execution_payload import (
|
||||||
compute_el_block_hash,
|
compute_el_block_hash,
|
||||||
|
get_random_tx,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.attestations import (
|
from eth2spec.test.helpers.attestations import (
|
||||||
get_valid_attestation,
|
get_valid_attestation,
|
||||||
@ -24,13 +27,25 @@ 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):
|
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
|
yield 'pre', state
|
||||||
|
|
||||||
block = build_empty_block_for_next_slot(spec, 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.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.data_gas_used = data_gas_used
|
||||||
block.body.execution_payload.excess_data_gas = excess_data_gas
|
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)
|
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
|
||||||
@ -56,18 +71,48 @@ def test_one_blob(spec, state):
|
|||||||
yield from run_block_with_blobs(spec, state, blob_count=1)
|
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
|
@with_deneb_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_max_blobs_per_block(spec, state):
|
def test_max_blobs_per_block(spec, state):
|
||||||
yield from run_block_with_blobs(spec, state, blob_count=spec.MAX_BLOBS_PER_BLOCK)
|
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
|
@with_deneb_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_invalid_exceed_max_blobs_per_block(spec, state):
|
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)
|
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])
|
@with_phases([DENEB])
|
||||||
@spec_configured_state_test({
|
@spec_configured_state_test({
|
||||||
'DENEB_FORK_EPOCH': 2,
|
'DENEB_FORK_EPOCH': 2,
|
||||||
|
@ -259,7 +259,7 @@ def build_randomized_execution_payload(spec, state, rng):
|
|||||||
|
|
||||||
num_transactions = rng.randint(0, 100)
|
num_transactions = rng.randint(0, 100)
|
||||||
execution_payload.transactions = [
|
execution_payload.transactions = [
|
||||||
spec.Transaction(get_random_bytes_list(rng, rng.randint(0, 1000)))
|
get_random_tx(rng)
|
||||||
for _ in range(num_transactions)
|
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
|
pre_state.latest_execution_payload_header = execution_payload_header
|
||||||
|
|
||||||
return pre_state
|
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 (
|
from eth2spec.test.helpers.execution_payload import (
|
||||||
compute_el_block_hash,
|
compute_el_block_hash,
|
||||||
|
build_randomized_execution_payload,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.multi_operations import (
|
from eth2spec.test.helpers.multi_operations import (
|
||||||
build_random_block_from_state_for_next_slot,
|
build_random_block_from_state_for_next_slot,
|
||||||
@ -216,14 +217,17 @@ def random_block_altair_with_cycling_sync_committee_participation(spec,
|
|||||||
return block
|
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)
|
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
|
return block
|
||||||
|
|
||||||
|
|
||||||
def random_block_capella(spec, state, signed_blocks, scenario_state, rng=Random(3456)):
|
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(
|
block.body.bls_to_execution_changes = get_random_bls_to_execution_changes(
|
||||||
spec,
|
spec,
|
||||||
state,
|
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)):
|
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]
|
# 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)
|
opaque_tx, _, blob_kzg_commitments, _ = get_sample_opaque_tx(
|
||||||
block.body.execution_payload.transactions = [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.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
|
||||||
block.body.blob_kzg_commitments = blob_kzg_commitments
|
block.body.blob_kzg_commitments = blob_kzg_commitments
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user