From ff7f5371508bc55ad1cb6563c154691e81fdb375 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 25 Jun 2019 10:31:39 -0600 Subject: [PATCH] properly construct genesis latest block header in tests --- .../eth2spec/test/fork_choice/test_on_attestation.py | 10 ---------- .../pyspec/eth2spec/test/fork_choice/test_on_block.py | 8 -------- test_libs/pyspec/eth2spec/test/helpers/genesis.py | 5 ++++- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/fork_choice/test_on_attestation.py b/test_libs/pyspec/eth2spec/test/fork_choice/test_on_attestation.py index cf0e7c9cb8..25b58968e3 100644 --- a/test_libs/pyspec/eth2spec/test/fork_choice/test_on_attestation.py +++ b/test_libs/pyspec/eth2spec/test/fork_choice/test_on_attestation.py @@ -31,8 +31,6 @@ def run_on_attestation(spec, state, store, attestation, valid=True): @with_state @bls_switch def test_on_attestation(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - store = spec.get_genesis_store(state) time = 100 spec.on_tick(store, time) @@ -52,8 +50,6 @@ def test_on_attestation(spec, state): @with_state @bls_switch def test_on_attestation_target_not_in_store(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - store = spec.get_genesis_store(state) time = 100 spec.on_tick(store, time) @@ -74,8 +70,6 @@ def test_on_attestation_target_not_in_store(spec, state): @with_state @bls_switch def test_on_attestation_future_epoch(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - store = spec.get_genesis_store(state) time = 3 * spec.SECONDS_PER_SLOT spec.on_tick(store, time) @@ -98,8 +92,6 @@ def test_on_attestation_future_epoch(spec, state): @with_state @bls_switch def test_on_attestation_same_slot(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - store = spec.get_genesis_store(state) time = 1 * spec.SECONDS_PER_SLOT spec.on_tick(store, time) @@ -117,8 +109,6 @@ def test_on_attestation_same_slot(spec, state): @with_state @bls_switch def test_on_attestation_invalid_attestation(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - store = spec.get_genesis_store(state) time = 3 * spec.SECONDS_PER_SLOT spec.on_tick(store, time) diff --git a/test_libs/pyspec/eth2spec/test/fork_choice/test_on_block.py b/test_libs/pyspec/eth2spec/test/fork_choice/test_on_block.py index b18752f8c6..75a699cd6b 100644 --- a/test_libs/pyspec/eth2spec/test/fork_choice/test_on_block.py +++ b/test_libs/pyspec/eth2spec/test/fork_choice/test_on_block.py @@ -22,8 +22,6 @@ def run_on_block(spec, state, store, block, valid=True): @with_state @bls_switch def test_basic(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - # Initialization store = spec.get_genesis_store(state) time = 100 @@ -48,8 +46,6 @@ def test_basic(spec, state): @with_state @bls_switch def test_on_block_future_block(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - # Initialization store = spec.get_genesis_store(state) @@ -64,8 +60,6 @@ def test_on_block_future_block(spec, state): @with_state @bls_switch def test_on_block_bad_parent_root(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - # Initialization store = spec.get_genesis_store(state) time = 100 @@ -81,8 +75,6 @@ def test_on_block_bad_parent_root(spec, state): @with_state @bls_switch def test_on_block_before_finalized(spec, state): - state.latest_block_header = spec.BeaconBlockHeader(body_root=hash_tree_root(spec.BeaconBlockBody())) - # Initialization store = spec.get_genesis_store(state) time = 100 diff --git a/test_libs/pyspec/eth2spec/test/helpers/genesis.py b/test_libs/pyspec/eth2spec/test/helpers/genesis.py index d1d8189080..8f9b50bbdd 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/genesis.py +++ b/test_libs/pyspec/eth2spec/test/helpers/genesis.py @@ -27,7 +27,10 @@ def create_genesis_state(spec, num_validators): deposit_root=deposit_root, deposit_count=num_validators, block_hash=spec.ZERO_HASH, - )) + ), + latest_block_header=spec.BeaconBlockHeader(body_root=spec.hash_tree_root(spec.BeaconBlockBody())), + ) + # We "hack" in the initial validators, # as it is much faster than creating and processing genesis deposits for every single test case.