Stop yielding from fork-choie tests

This commit is contained in:
Carl Beekhuizen 2019-06-21 13:00:42 +02:00
parent f90469ea25
commit 0e59c6676a
No known key found for this signature in database
GPG Key ID: D05CA176D0020646
2 changed files with 7 additions and 13 deletions

View File

@ -140,14 +140,14 @@ def on_tick(store: Store, time: int) -> None:
```python ```python
def on_block(store: Store, block: BeaconBlock) -> None: 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. # 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 assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
# Add new block to the store # Add new block to the store
store.blocks[signing_root(block)] = block store.blocks[signing_root(block)] = block
# Check block is a descendant of the finalized 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 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 # Check the block is valid and compute the post-state
state = state_transition(pre_state, block) state = state_transition(pre_state, block)
# Add new state to the store # Add new state to the store

View File

@ -2,7 +2,7 @@ from typing import List
from eth2spec.utils.ssz.ssz_impl import signing_root, hash_tree_root 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.block import build_empty_block_for_next_slot
from eth2spec.test.helpers.attestations import get_valid_attestation from eth2spec.test.helpers.attestations import get_valid_attestation
@ -10,10 +10,10 @@ from eth2spec.test.helpers.state import next_slot
@with_all_phases @with_all_phases
@spec_state_test @with_state
@bls_switch
def test_basic(spec, state): def test_basic(spec, state):
state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody()))
yield 'pre', state
# Initialization # Initialization
store = spec.get_genesis_store(state) store = spec.get_genesis_store(state)
@ -36,17 +36,14 @@ def test_basic(spec, state):
spec.on_block(store, block) spec.on_block(store, block)
assert store.blocks[signing_root(block)] == block assert store.blocks[signing_root(block)] == block
yield 'blocks', blocks, List[spec.BeaconBlock]
# TODO: add tests for justified_root and finalized_root # TODO: add tests for justified_root and finalized_root
yield 'post', state
@with_all_phases @with_all_phases
@spec_state_test @with_state
@bls_switch
def test_on_attestation(spec, state): def test_on_attestation(spec, state):
yield 'pre', state
store = spec.get_genesis_store(state) store = spec.get_genesis_store(state)
time = 100 time = 100
spec.on_tick(store, time) spec.on_tick(store, time)
@ -54,7 +51,6 @@ def test_on_attestation(spec, state):
next_slot(spec, state) next_slot(spec, state)
attestation = get_valid_attestation(spec, state, slot=1) attestation = get_valid_attestation(spec, state, slot=1)
yield 'attestation', attestation
indexed_attestation = spec.convert_to_indexed(state, attestation) indexed_attestation = spec.convert_to_indexed(state, attestation)
spec.on_attestation(store, attestation) spec.on_attestation(store, attestation)
assert ( assert (
@ -64,5 +60,3 @@ def test_on_attestation(spec, state):
root=attestation.data.target_root, root=attestation.data.target_root,
) )
) )
yield 'post', state