mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-02 13:53:27 +00:00
a few more bellatrix tests (#2962)
* Do not overload index with WithdrawalIndex and ValidatorIndex * a few more bellatrix tests * use function from other PR * fix tests * Update tests/core/pyspec/eth2spec/test/bellatrix/transition/test_transition.py Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com> * refactor to reuse bellatrix transitio ntests for all transitions Co-authored-by: Potuz <potuz@prysmaticlabs.com> Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
This commit is contained in:
parent
c04f221fad
commit
ccc40e1982
@ -3,6 +3,9 @@ from eth2spec.test.context import (
|
|||||||
ForkMeta,
|
ForkMeta,
|
||||||
with_fork_metas,
|
with_fork_metas,
|
||||||
)
|
)
|
||||||
|
from eth2spec.test.helpers.random import (
|
||||||
|
randomize_state,
|
||||||
|
)
|
||||||
from eth2spec.test.helpers.constants import (
|
from eth2spec.test.helpers.constants import (
|
||||||
ALL_PRE_POST_FORKS,
|
ALL_PRE_POST_FORKS,
|
||||||
)
|
)
|
||||||
@ -17,9 +20,31 @@ from eth2spec.test.helpers.fork_transition import (
|
|||||||
skip_slots,
|
skip_slots,
|
||||||
state_transition_across_slots,
|
state_transition_across_slots,
|
||||||
transition_to_next_epoch_and_append_blocks,
|
transition_to_next_epoch_and_append_blocks,
|
||||||
|
transition_until_fork,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS])
|
||||||
|
def test_simple_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
||||||
|
transition_until_fork(spec, state, fork_epoch)
|
||||||
|
|
||||||
|
# check pre state
|
||||||
|
assert spec.get_current_epoch(state) < fork_epoch
|
||||||
|
|
||||||
|
yield "pre", state
|
||||||
|
|
||||||
|
# irregular state transition to handle fork:
|
||||||
|
blocks = []
|
||||||
|
state, block = do_fork(state, spec, post_spec, fork_epoch)
|
||||||
|
blocks.append(post_tag(block))
|
||||||
|
|
||||||
|
# continue regular state transition with new spec into next epoch
|
||||||
|
transition_to_next_epoch_and_append_blocks(post_spec, state, post_tag, blocks, only_last_block=True)
|
||||||
|
|
||||||
|
yield "blocks", blocks
|
||||||
|
yield "post", state
|
||||||
|
|
||||||
|
|
||||||
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS])
|
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS])
|
||||||
def test_normal_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
def test_normal_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
||||||
"""
|
"""
|
||||||
@ -56,6 +81,37 @@ def test_normal_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag
|
|||||||
yield "post", state
|
yield "post", state
|
||||||
|
|
||||||
|
|
||||||
|
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=8) for pre, post in ALL_PRE_POST_FORKS])
|
||||||
|
def test_transition_randomized_state(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
||||||
|
randomize_state(spec, state)
|
||||||
|
|
||||||
|
transition_until_fork(spec, state, fork_epoch)
|
||||||
|
|
||||||
|
# check pre state
|
||||||
|
assert spec.get_current_epoch(state) < fork_epoch
|
||||||
|
|
||||||
|
yield "pre", state
|
||||||
|
|
||||||
|
# irregular state transition to handle fork:
|
||||||
|
blocks = []
|
||||||
|
# since there are slashed validators, set with_block=False here
|
||||||
|
state, _ = do_fork(state, spec, post_spec, fork_epoch, with_block=False)
|
||||||
|
slashed_indices = [index for index, validator in enumerate(state.validators) if validator.slashed]
|
||||||
|
|
||||||
|
# continue regular state transition with new spec into next epoch
|
||||||
|
transition_to_next_epoch_and_append_blocks(
|
||||||
|
post_spec,
|
||||||
|
state,
|
||||||
|
post_tag,
|
||||||
|
blocks,
|
||||||
|
only_last_block=True,
|
||||||
|
ignoring_proposers=slashed_indices,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield "blocks", blocks
|
||||||
|
yield "post", state
|
||||||
|
|
||||||
|
|
||||||
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS])
|
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS])
|
||||||
def test_transition_missing_first_post_block(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
def test_transition_missing_first_post_block(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
||||||
"""
|
"""
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from random import Random
|
from random import Random
|
||||||
|
|
||||||
from eth2spec.debug.random_value import get_random_bytes_list
|
|
||||||
from eth2spec.test.helpers.execution_payload import (
|
from eth2spec.test.helpers.execution_payload import (
|
||||||
build_empty_execution_payload,
|
build_empty_execution_payload,
|
||||||
|
build_randomized_execution_payload,
|
||||||
get_execution_payload_header,
|
get_execution_payload_header,
|
||||||
build_state_with_incomplete_transition,
|
build_state_with_incomplete_transition,
|
||||||
build_state_with_complete_transition,
|
build_state_with_complete_transition,
|
||||||
@ -307,33 +307,6 @@ def test_zero_length_transaction_regular_payload(spec, state):
|
|||||||
yield from run_zero_length_transaction_test(spec, state)
|
yield from run_zero_length_transaction_test(spec, state)
|
||||||
|
|
||||||
|
|
||||||
def build_randomized_execution_payload(spec, state, rng):
|
|
||||||
execution_payload = build_empty_execution_payload(spec, state)
|
|
||||||
execution_payload.fee_recipient = spec.ExecutionAddress(get_random_bytes_list(rng, 20))
|
|
||||||
execution_payload.state_root = spec.Bytes32(get_random_bytes_list(rng, 32))
|
|
||||||
execution_payload.receipts_root = spec.Bytes32(get_random_bytes_list(rng, 32))
|
|
||||||
execution_payload.logs_bloom = spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](
|
|
||||||
get_random_bytes_list(rng, spec.BYTES_PER_LOGS_BLOOM)
|
|
||||||
)
|
|
||||||
execution_payload.block_number = rng.randint(0, 10e10)
|
|
||||||
execution_payload.gas_limit = rng.randint(0, 10e10)
|
|
||||||
execution_payload.gas_used = rng.randint(0, 10e10)
|
|
||||||
extra_data_length = rng.randint(0, spec.MAX_EXTRA_DATA_BYTES)
|
|
||||||
execution_payload.extra_data = spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](
|
|
||||||
get_random_bytes_list(rng, extra_data_length)
|
|
||||||
)
|
|
||||||
execution_payload.base_fee_per_gas = rng.randint(0, 2**256 - 1)
|
|
||||||
execution_payload.block_hash = spec.Hash32(get_random_bytes_list(rng, 32))
|
|
||||||
|
|
||||||
num_transactions = rng.randint(0, 100)
|
|
||||||
execution_payload.transactions = [
|
|
||||||
spec.Transaction(get_random_bytes_list(rng, rng.randint(0, 1000)))
|
|
||||||
for _ in range(num_transactions)
|
|
||||||
]
|
|
||||||
|
|
||||||
return execution_payload
|
|
||||||
|
|
||||||
|
|
||||||
def run_randomized_non_validated_execution_fields_test(spec, state, execution_valid=True, rng=Random(5555)):
|
def run_randomized_non_validated_execution_fields_test(spec, state, execution_valid=True, rng=Random(5555)):
|
||||||
next_slot(spec, state)
|
next_slot(spec, state)
|
||||||
execution_payload = build_randomized_execution_payload(spec, state, rng)
|
execution_payload = build_randomized_execution_payload(spec, state, rng)
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
|
from random 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_slot,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.block import (
|
from eth2spec.test.helpers.block import (
|
||||||
build_empty_block_for_next_slot
|
build_empty_block_for_next_slot
|
||||||
)
|
)
|
||||||
|
from eth2spec.test.helpers.execution_payload import (
|
||||||
|
build_randomized_execution_payload
|
||||||
|
)
|
||||||
from eth2spec.test.context import (
|
from eth2spec.test.context import (
|
||||||
with_bellatrix_and_later, spec_state_test
|
with_bellatrix_and_later, spec_state_test
|
||||||
)
|
)
|
||||||
@ -22,7 +27,21 @@ def test_empty_block_transition_no_tx(spec, state):
|
|||||||
yield 'blocks', [signed_block]
|
yield 'blocks', [signed_block]
|
||||||
yield 'post', state
|
yield 'post', state
|
||||||
|
|
||||||
# TODO: tests with EVM, mock or replacement?
|
|
||||||
|
@with_bellatrix_and_later
|
||||||
|
@spec_state_test
|
||||||
|
def test_empty_block_transition_randomized_payload(spec, state):
|
||||||
|
yield 'pre', state
|
||||||
|
|
||||||
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
|
next_slot_state = state.copy()
|
||||||
|
next_slot(spec, next_slot_state)
|
||||||
|
block.body.execution_payload = build_randomized_execution_payload(spec, next_slot_state, rng=Random(34433))
|
||||||
|
|
||||||
|
signed_block = state_transition_and_sign_block(spec, state, block)
|
||||||
|
|
||||||
|
yield 'blocks', [signed_block]
|
||||||
|
yield 'post', state
|
||||||
|
|
||||||
|
|
||||||
@with_bellatrix_and_later
|
@with_bellatrix_and_later
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
from eth2spec.test.context import (
|
|
||||||
ForkMeta,
|
|
||||||
with_fork_metas,
|
|
||||||
)
|
|
||||||
from eth2spec.test.helpers.constants import (
|
|
||||||
AFTER_BELLATRIX_PRE_POST_FORKS,
|
|
||||||
)
|
|
||||||
from eth2spec.test.helpers.fork_transition import (
|
|
||||||
do_fork,
|
|
||||||
transition_to_next_epoch_and_append_blocks,
|
|
||||||
transition_until_fork,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@with_fork_metas([
|
|
||||||
ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in AFTER_BELLATRIX_PRE_POST_FORKS
|
|
||||||
])
|
|
||||||
def test_sample_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
|
||||||
transition_until_fork(spec, state, fork_epoch)
|
|
||||||
|
|
||||||
# check pre state
|
|
||||||
assert spec.get_current_epoch(state) < fork_epoch
|
|
||||||
|
|
||||||
yield "pre", state
|
|
||||||
|
|
||||||
# irregular state transition to handle fork:
|
|
||||||
blocks = []
|
|
||||||
state, block = do_fork(state, spec, post_spec, fork_epoch)
|
|
||||||
blocks.append(post_tag(block))
|
|
||||||
|
|
||||||
# continue regular state transition with new spec into next epoch
|
|
||||||
transition_to_next_epoch_and_append_blocks(post_spec, state, post_tag, blocks, only_last_block=True)
|
|
||||||
|
|
||||||
yield "blocks", blocks
|
|
||||||
yield "post", state
|
|
@ -1,3 +1,4 @@
|
|||||||
|
from eth2spec.debug.random_value import get_random_bytes_list
|
||||||
from eth2spec.test.context import is_post_capella
|
from eth2spec.test.context import is_post_capella
|
||||||
|
|
||||||
|
|
||||||
@ -38,6 +39,33 @@ def build_empty_execution_payload(spec, state, randao_mix=None):
|
|||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|
||||||
|
def build_randomized_execution_payload(spec, state, rng):
|
||||||
|
execution_payload = build_empty_execution_payload(spec, state)
|
||||||
|
execution_payload.fee_recipient = spec.ExecutionAddress(get_random_bytes_list(rng, 20))
|
||||||
|
execution_payload.state_root = spec.Bytes32(get_random_bytes_list(rng, 32))
|
||||||
|
execution_payload.receipts_root = spec.Bytes32(get_random_bytes_list(rng, 32))
|
||||||
|
execution_payload.logs_bloom = spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](
|
||||||
|
get_random_bytes_list(rng, spec.BYTES_PER_LOGS_BLOOM)
|
||||||
|
)
|
||||||
|
execution_payload.block_number = rng.randint(0, 10e10)
|
||||||
|
execution_payload.gas_limit = rng.randint(0, 10e10)
|
||||||
|
execution_payload.gas_used = rng.randint(0, 10e10)
|
||||||
|
extra_data_length = rng.randint(0, spec.MAX_EXTRA_DATA_BYTES)
|
||||||
|
execution_payload.extra_data = spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](
|
||||||
|
get_random_bytes_list(rng, extra_data_length)
|
||||||
|
)
|
||||||
|
execution_payload.base_fee_per_gas = rng.randint(0, 2**256 - 1)
|
||||||
|
execution_payload.block_hash = spec.Hash32(get_random_bytes_list(rng, 32))
|
||||||
|
|
||||||
|
num_transactions = rng.randint(0, 100)
|
||||||
|
execution_payload.transactions = [
|
||||||
|
spec.Transaction(get_random_bytes_list(rng, rng.randint(0, 1000)))
|
||||||
|
for _ in range(num_transactions)
|
||||||
|
]
|
||||||
|
|
||||||
|
return execution_payload
|
||||||
|
|
||||||
|
|
||||||
def get_execution_payload_header(spec, execution_payload):
|
def get_execution_payload_header(spec, execution_payload):
|
||||||
payload_header = spec.ExecutionPayloadHeader(
|
payload_header = spec.ExecutionPayloadHeader(
|
||||||
parent_hash=execution_payload.parent_hash,
|
parent_hash=execution_payload.parent_hash,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user