From 2478e1526a464dd9d93dbce88d98452452ec01dc Mon Sep 17 00:00:00 2001 From: Aditya Asgaonkar Date: Sat, 3 Apr 2021 16:50:43 -0700 Subject: [PATCH] Fix block hierarchy consistency in tests --- .../unittests/fork_choice/test_on_block.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_block.py b/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_block.py index bb5aec578..79c55b2eb 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_block.py +++ b/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_block.py @@ -224,14 +224,19 @@ def test_on_block_outside_safe_slots_and_multiple_better_justified(spec, state): next_epoch(spec, state) spec.on_tick(store, store.time + state.slot * spec.SECONDS_PER_SLOT) state, store, last_signed_block = apply_next_epoch_with_attestations(spec, state, store) + last_block_root = hash_tree_root(last_signed_block.message) + + # Mock ficticious justified checkpoint in store + store.justified_checkpoint = spec.Checkpoint( + epoch=spec.compute_epoch_at_slot(last_signed_block.message.slot), + root=spec.Root("0x4a55535449464945440000000000000000000000000000000000000000000000") + ) + next_epoch(spec, state) spec.on_tick(store, store.time + state.slot * spec.SECONDS_PER_SLOT) - last_block_root = hash_tree_root(last_signed_block.message) - # Mock justified block in store + # Create new higher justified checkpoint not in branch of store's justified checkpoint just_block = build_empty_block_for_next_slot(spec, state) - # Slot is same as justified checkpoint so does not trigger an override in the store - just_block.slot = spec.compute_start_slot_at_epoch(store.justified_checkpoint.epoch) store.blocks[just_block.hash_tree_root()] = just_block just_block_parent = store.blocks[just_block.parent_root] @@ -271,20 +276,25 @@ def test_on_block_outside_safe_slots_and_multiple_better_justified(spec, state): def test_on_block_outside_safe_slots_but_finality(spec, state): # Initialization store = get_genesis_forkchoice_store(spec, state) - time = 100 + time = 0 spec.on_tick(store, time) next_epoch(spec, state) spec.on_tick(store, store.time + state.slot * spec.SECONDS_PER_SLOT) state, store, last_signed_block = apply_next_epoch_with_attestations(spec, state, store) + last_block_root = hash_tree_root(last_signed_block.message) + + # Mock ficticious justified checkpoint in store + store.justified_checkpoint = spec.Checkpoint( + epoch=spec.compute_epoch_at_slot(last_signed_block.message.slot), + root=spec.Root("0x4a55535449464945440000000000000000000000000000000000000000000000") + ) + next_epoch(spec, state) spec.on_tick(store, store.time + state.slot * spec.SECONDS_PER_SLOT) - last_block_root = hash_tree_root(last_signed_block.message) - # Mock justified block in store + # Create new higher justified checkpoint not in branch of store's justified checkpoint just_block = build_empty_block_for_next_slot(spec, state) - # Slot is same as justified checkpoint so does not trigger an override in the store - just_block.slot = spec.compute_start_slot_at_epoch(store.justified_checkpoint.epoch) store.blocks[just_block.hash_tree_root()] = just_block just_block_parent = store.blocks[just_block.parent_root]