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
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

View File

@ -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