Skip to content

Commit

Permalink
only allow attestatiosn to be considered from current and previous epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Nov 5, 2019
1 parent 2616210 commit c28738f
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions test_libs/pyspec/eth2spec/test/fork_choice/test_on_attestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def run_on_attestation(spec, state, store, attestation, valid=True):

@with_all_phases
@spec_state_test
def test_on_attestation(spec, state):
def test_on_attestation_current_epoch(spec, state):
store = spec.get_genesis_store(state)
time = 100
spec.on_tick(store, time)
spec.on_tick(store, store.time + spec.SECONDS_PER_SLOT * 2)

block = build_empty_block_for_next_slot(spec, state)
state_transition_and_sign_block(spec, state, block)
Expand All @@ -41,9 +40,54 @@ def test_on_attestation(spec, state):
spec.on_block(store, block)

attestation = get_valid_attestation(spec, state, slot=block.slot)
assert attestation.data.target.epoch == spec.GENESIS_EPOCH
assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == spec.GENESIS_EPOCH

run_on_attestation(spec, state, store, attestation)


@with_all_phases
@spec_state_test
def test_on_attestation_previous_epoch(spec, state):
store = spec.get_genesis_store(state)
spec.on_tick(store, store.time + spec.SECONDS_PER_SLOT * spec.SLOTS_PER_EPOCH)

block = build_empty_block_for_next_slot(spec, state)
state_transition_and_sign_block(spec, state, block)

# store block in store
spec.on_block(store, block)

attestation = get_valid_attestation(spec, state, slot=block.slot)
assert attestation.data.target.epoch == spec.GENESIS_EPOCH
assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == spec.GENESIS_EPOCH + 1

run_on_attestation(spec, state, store, attestation)


@with_all_phases
@spec_state_test
def test_on_attestation_past_epoch(spec, state):
store = spec.get_genesis_store(state)

# move time forward 3 epochs
time = store.time + 2 * spec.SECONDS_PER_SLOT * spec.SLOTS_PER_EPOCH
spec.on_tick(store, time)

# create and store block from 3 epochs ago
block = build_empty_block_for_next_slot(spec, state)
state_transition_and_sign_block(spec, state, block)
spec.on_block(store, block)

# create attestation for past block
attestation_slot = block.slot
attestation = get_valid_attestation(spec, state, slot=state.slot)
assert attestation.data.target.epoch == spec.GENESIS_EPOCH
assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == spec.GENESIS_EPOCH + 2

run_on_attestation(spec, state, store, attestation, False)


@with_all_phases
@spec_state_test
def test_on_attestation_target_not_in_store(spec, state):
Expand Down

0 comments on commit c28738f

Please sign in to comment.