From 0e59c6676a66bf1f0b40bf0eb76c3040da01656f Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Fri, 21 Jun 2019 13:00:42 +0200 Subject: [PATCH] Stop yielding from fork-choie tests --- specs/core/0_fork-choice.md | 4 ++-- .../pyspec/eth2spec/test/test_fork_choice.py | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index eb7c1a579..3d85cf571 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -140,14 +140,14 @@ def on_tick(store: Store, time: int) -> None: ```python def on_block(store: Store, block: BeaconBlock) -> None: + # Make a copy of the state to avoid mutability issues + pre_state = store.states[block.parent_root].copy() # Blocks cannot be in the future. If they are, their consideration must be delayed until the are in the past. assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT # Add new block to the store store.blocks[signing_root(block)] = block # Check block is a descendant of the finalized block assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_root].slot) == store.finalized_root - # Check block slot against Unix time - pre_state = store.states[block.parent_root].copy() # Check the block is valid and compute the post-state state = state_transition(pre_state, block) # Add new state to the store diff --git a/test_libs/pyspec/eth2spec/test/test_fork_choice.py b/test_libs/pyspec/eth2spec/test/test_fork_choice.py index ab1728251..4bc7e8b0a 100644 --- a/test_libs/pyspec/eth2spec/test/test_fork_choice.py +++ b/test_libs/pyspec/eth2spec/test/test_fork_choice.py @@ -2,7 +2,7 @@ from typing import List from eth2spec.utils.ssz.ssz_impl import signing_root, hash_tree_root -from eth2spec.test.context import with_all_phases, spec_state_test +from eth2spec.test.context import with_all_phases, with_state, bls_switch from eth2spec.test.helpers.block import build_empty_block_for_next_slot from eth2spec.test.helpers.attestations import get_valid_attestation @@ -10,10 +10,10 @@ from eth2spec.test.helpers.state import next_slot @with_all_phases -@spec_state_test +@with_state +@bls_switch def test_basic(spec, state): state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - yield 'pre', state # Initialization store = spec.get_genesis_store(state) @@ -36,17 +36,14 @@ def test_basic(spec, state): spec.on_block(store, block) assert store.blocks[signing_root(block)] == block - yield 'blocks', blocks, List[spec.BeaconBlock] # TODO: add tests for justified_root and finalized_root - yield 'post', state @with_all_phases -@spec_state_test +@with_state +@bls_switch def test_on_attestation(spec, state): - yield 'pre', state - store = spec.get_genesis_store(state) time = 100 spec.on_tick(store, time) @@ -54,7 +51,6 @@ def test_on_attestation(spec, state): next_slot(spec, state) attestation = get_valid_attestation(spec, state, slot=1) - yield 'attestation', attestation indexed_attestation = spec.convert_to_indexed(state, attestation) spec.on_attestation(store, attestation) assert ( @@ -64,5 +60,3 @@ def test_on_attestation(spec, state): root=attestation.data.target_root, ) ) - - yield 'post', state