Skip to content

Commit

Permalink
add tests for on_attestation ceckpont state fix
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Jun 22, 2020
1 parent 1f7399e commit a1e3392
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions tests/core/pyspec/eth2spec/test/fork_choice/test_on_attestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def test_on_attestation_inconsistent_target_and_head(spec, state):

@with_all_phases
@spec_state_test
def test_on_attestation_target_not_in_store(spec, state):
def test_on_attestation_target_block_not_in_store(spec, state):
store = spec.get_forkchoice_store(state)
time = store.time + spec.SECONDS_PER_SLOT * spec.SLOTS_PER_EPOCH
time = store.time + spec.SECONDS_PER_SLOT * (spec.SLOTS_PER_EPOCH + 1)
spec.on_tick(store, time)

# move to immediately before next epoch to make block new target
Expand All @@ -183,11 +183,63 @@ def test_on_attestation_target_not_in_store(spec, state):
run_on_attestation(spec, state, store, attestation, False)


@with_all_phases
@spec_state_test
def test_on_attestation_target_checkpoint_not_in_store(spec, state):
store = spec.get_forkchoice_store(state)
time = store.time + spec.SECONDS_PER_SLOT * (spec.SLOTS_PER_EPOCH + 1)
spec.on_tick(store, time)

# move to immediately before next epoch to make block new target
next_epoch = spec.get_current_epoch(state) + 1
transition_to(spec, state, spec.compute_start_slot_at_epoch(next_epoch) - 1)

target_block = build_empty_block_for_next_slot(spec, state)
signed_target_block = state_transition_and_sign_block(spec, state, target_block)

# add target block to store
spec.on_block(store, signed_target_block)

# target checkpoint state is not yet in store

attestation = get_valid_attestation(spec, state, slot=target_block.slot, signed=True)
assert attestation.data.target.root == target_block.hash_tree_root()

run_on_attestation(spec, state, store, attestation)


@with_all_phases
@spec_state_test
def test_on_attestation_target_checkpoint_not_in_store_diff_slot(spec, state):
store = spec.get_forkchoice_store(state)
time = store.time + spec.SECONDS_PER_SLOT * (spec.SLOTS_PER_EPOCH + 1)
spec.on_tick(store, time)

# move to two slots before next epoch to make target block one before an empty slot
next_epoch = spec.get_current_epoch(state) + 1
transition_to(spec, state, spec.compute_start_slot_at_epoch(next_epoch) - 2)

target_block = build_empty_block_for_next_slot(spec, state)
signed_target_block = state_transition_and_sign_block(spec, state, target_block)

# add target block to store
spec.on_block(store, signed_target_block)

# target checkpoint state is not yet in store

attestation_slot = target_block.slot + 1
transition_to(spec, state, attestation_slot)
attestation = get_valid_attestation(spec, state, slot=attestation_slot, signed=True)
assert attestation.data.target.root == target_block.hash_tree_root()

run_on_attestation(spec, state, store, attestation)


@with_all_phases
@spec_state_test
def test_on_attestation_beacon_block_not_in_store(spec, state):
store = spec.get_forkchoice_store(state)
time = store.time + spec.SECONDS_PER_SLOT * spec.SLOTS_PER_EPOCH
time = store.time + spec.SECONDS_PER_SLOT * (spec.SLOTS_PER_EPOCH + 1)
spec.on_tick(store, time)

# move to immediately before next epoch to make block new target
Expand Down

0 comments on commit a1e3392

Please sign in to comment.