Merge pull request #3464 from ethereum/att-transtion
Move and rework `include_attestation_from_previous_fork_with_new_range` test to a `transition` test
This commit is contained in:
commit
fba7b8e92d
|
@ -2,26 +2,18 @@ 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,
|
|
||||||
transition_to,
|
|
||||||
)
|
)
|
||||||
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.context import (
|
from eth2spec.test.context import (
|
||||||
DENEB,
|
|
||||||
spec_state_test,
|
spec_state_test,
|
||||||
spec_configured_state_test,
|
|
||||||
with_deneb_and_later,
|
with_deneb_and_later,
|
||||||
with_phases,
|
|
||||||
)
|
)
|
||||||
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,
|
get_random_tx,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.attestations import (
|
|
||||||
get_valid_attestation,
|
|
||||||
)
|
|
||||||
from eth2spec.test.helpers.sharding import (
|
from eth2spec.test.helpers.sharding import (
|
||||||
get_sample_opaque_tx,
|
get_sample_opaque_tx,
|
||||||
)
|
)
|
||||||
|
@ -111,35 +103,3 @@ def test_invalid_exceed_max_blobs_per_block(spec, state):
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_mix_blob_tx_and_non_blob_tx(spec, state):
|
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)
|
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,
|
|
||||||
})
|
|
||||||
def test_include_attestation_from_previous_fork_with_new_range(spec, state):
|
|
||||||
# Transition to the epoch prior to the fork epoch
|
|
||||||
next_epoch_via_block(spec, state)
|
|
||||||
|
|
||||||
# Generate an attestation for slot 0 of this epoch
|
|
||||||
attestation = get_valid_attestation(spec, state, signed=True)
|
|
||||||
|
|
||||||
# Transition to second to last slot in `DENEB_FORK_EPOCH`
|
|
||||||
next_epoch_via_block(spec, state)
|
|
||||||
current_epoch = spec.get_current_epoch(state)
|
|
||||||
assert current_epoch == spec.config.DENEB_FORK_EPOCH
|
|
||||||
penultimate_slot = spec.compute_start_slot_at_epoch(current_epoch + 1) - 2
|
|
||||||
transition_to(spec, state, penultimate_slot)
|
|
||||||
|
|
||||||
# Ensure the new state is in the increased EIP-7045 slot inclusion range
|
|
||||||
assert penultimate_slot - attestation.data.slot > spec.SLOTS_PER_EPOCH
|
|
||||||
|
|
||||||
block = build_empty_block_for_next_slot(spec, state)
|
|
||||||
block.body.attestations.append(attestation)
|
|
||||||
|
|
||||||
yield 'pre', state
|
|
||||||
|
|
||||||
signed_block = state_transition_and_sign_block(spec, state, block)
|
|
||||||
|
|
||||||
yield 'blocks', [signed_block]
|
|
||||||
yield 'post', state
|
|
||||||
|
|
|
@ -3,12 +3,25 @@ from eth2spec.test.context import (
|
||||||
always_bls,
|
always_bls,
|
||||||
with_fork_metas,
|
with_fork_metas,
|
||||||
)
|
)
|
||||||
|
from eth2spec.test.helpers.attestations import (
|
||||||
|
get_valid_attestation,
|
||||||
|
)
|
||||||
|
from eth2spec.test.helpers.block import (
|
||||||
|
build_empty_block_for_next_slot,
|
||||||
|
)
|
||||||
from eth2spec.test.helpers.constants import (
|
from eth2spec.test.helpers.constants import (
|
||||||
AFTER_DENEB_PRE_POST_FORKS,
|
AFTER_DENEB_PRE_POST_FORKS,
|
||||||
)
|
)
|
||||||
|
from eth2spec.test.helpers.state import (
|
||||||
|
next_epoch_via_block,
|
||||||
|
state_transition_and_sign_block,
|
||||||
|
transition_to,
|
||||||
|
)
|
||||||
from eth2spec.test.helpers.fork_transition import (
|
from eth2spec.test.helpers.fork_transition import (
|
||||||
OperationType,
|
OperationType,
|
||||||
|
do_fork,
|
||||||
run_transition_with_operation,
|
run_transition_with_operation,
|
||||||
|
transition_until_fork,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,3 +65,38 @@ def test_transition_with_btec_right_before_fork(state, fork_epoch, spec, post_sp
|
||||||
operation_type=OperationType.BLS_TO_EXECUTION_CHANGE,
|
operation_type=OperationType.BLS_TO_EXECUTION_CHANGE,
|
||||||
operation_at_slot=fork_epoch * spec.SLOTS_PER_EPOCH - 1,
|
operation_at_slot=fork_epoch * spec.SLOTS_PER_EPOCH - 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2)
|
||||||
|
for pre, post in AFTER_DENEB_PRE_POST_FORKS])
|
||||||
|
def test_transition_attestation_from_previous_fork_with_new_range(
|
||||||
|
state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
||||||
|
"""
|
||||||
|
[EIP-7045] test
|
||||||
|
"""
|
||||||
|
# Transition to the epoch prior to the fork epoch
|
||||||
|
next_epoch_via_block(spec, state)
|
||||||
|
|
||||||
|
# Generate an attestation for slot 0 of this epoch
|
||||||
|
attestation = get_valid_attestation(spec, state, signed=True)
|
||||||
|
|
||||||
|
yield 'pre', state
|
||||||
|
|
||||||
|
# Transition to the fork epoch with a block
|
||||||
|
transition_until_fork(spec, state, fork_epoch)
|
||||||
|
state, fork_block = do_fork(state, spec, post_spec, fork_epoch)
|
||||||
|
current_epoch = spec.get_current_epoch(state)
|
||||||
|
assert current_epoch == fork_epoch
|
||||||
|
# Transition to second to last slot in `fork_epoch`
|
||||||
|
penultimate_slot = post_spec.compute_start_slot_at_epoch(current_epoch + 1) - 2
|
||||||
|
transition_to(post_spec, state, penultimate_slot)
|
||||||
|
|
||||||
|
# Ensure the new state is in the increased EIP-7045 slot inclusion range
|
||||||
|
assert penultimate_slot - attestation.data.slot > post_spec.SLOTS_PER_EPOCH
|
||||||
|
|
||||||
|
block = build_empty_block_for_next_slot(post_spec, state)
|
||||||
|
block.body.attestations.append(attestation)
|
||||||
|
signed_block = state_transition_and_sign_block(post_spec, state, block)
|
||||||
|
|
||||||
|
yield 'blocks', [post_tag(fork_block), post_tag(signed_block)]
|
||||||
|
yield 'post', state
|
||||||
|
|
Loading…
Reference in New Issue