add test for inconsistent head and target in attestation fork choice
This commit is contained in:
parent
b71a0ee6b9
commit
b109e7da5a
|
@ -1,7 +1,7 @@
|
||||||
from eth2spec.test.context import PHASE0, with_all_phases, spec_state_test
|
from eth2spec.test.context import PHASE0, with_all_phases, spec_state_test
|
||||||
from eth2spec.test.helpers.block import build_empty_block_for_next_slot
|
from eth2spec.test.helpers.block import build_empty_block_for_next_slot
|
||||||
from eth2spec.test.helpers.attestations import get_valid_attestation, sign_attestation
|
from eth2spec.test.helpers.attestations import get_valid_attestation, sign_attestation
|
||||||
from eth2spec.test.helpers.state import transition_to, state_transition_and_sign_block, next_epoch
|
from eth2spec.test.helpers.state import transition_to, state_transition_and_sign_block, next_epoch, next_slot
|
||||||
|
|
||||||
|
|
||||||
def run_on_attestation(spec, state, store, attestation, valid=True):
|
def run_on_attestation(spec, state, store, attestation, valid=True):
|
||||||
|
@ -116,6 +116,44 @@ def test_on_attestation_mismatched_target_and_slot(spec, state):
|
||||||
run_on_attestation(spec, state, store, attestation, False)
|
run_on_attestation(spec, state, store, attestation, False)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_on_attestation_inconsistent_target_and_head(spec, state):
|
||||||
|
store = spec.get_forkchoice_store(state)
|
||||||
|
spec.on_tick(store, store.time + 2 * spec.SECONDS_PER_SLOT * spec.SLOTS_PER_EPOCH)
|
||||||
|
|
||||||
|
# Create chain 1 as empty chain between genesis and start of 1st epoch
|
||||||
|
target_state_1 = state.copy()
|
||||||
|
next_epoch(spec, target_state_1)
|
||||||
|
|
||||||
|
# Create chain 2 with different block in chain from chain 1 from chain 1 from chain 1 from chain 1
|
||||||
|
target_state_2 = state.copy()
|
||||||
|
diff_block = build_empty_block_for_next_slot(spec, target_state_2)
|
||||||
|
signed_diff_block = state_transition_and_sign_block(spec, target_state_2, diff_block)
|
||||||
|
spec.on_block(store, signed_diff_block)
|
||||||
|
next_epoch(spec, target_state_2)
|
||||||
|
next_slot(spec, target_state_2)
|
||||||
|
|
||||||
|
# Create and store block new head block on target state 1
|
||||||
|
head_block = build_empty_block_for_next_slot(spec, target_state_1)
|
||||||
|
signed_head_block = state_transition_and_sign_block(spec, target_state_1, head_block)
|
||||||
|
spec.on_block(store, signed_head_block)
|
||||||
|
|
||||||
|
# Attest to head of chain 1
|
||||||
|
attestation = get_valid_attestation(spec, target_state_1, slot=head_block.slot, signed=False)
|
||||||
|
epoch = spec.compute_epoch_at_slot(attestation.data.slot)
|
||||||
|
|
||||||
|
# Set attestation target to be from chain 2
|
||||||
|
attestation.data.target = spec.Checkpoint(epoch=epoch, root=spec.get_block_root(target_state_2, epoch))
|
||||||
|
sign_attestation(spec, state, attestation)
|
||||||
|
|
||||||
|
assert attestation.data.target.epoch == spec.GENESIS_EPOCH + 1
|
||||||
|
assert spec.compute_epoch_at_slot(attestation.data.slot) == spec.GENESIS_EPOCH + 1
|
||||||
|
assert spec.get_block_root(target_state_1, epoch) != attestation.data.target.root
|
||||||
|
|
||||||
|
run_on_attestation(spec, state, store, attestation, False)
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_on_attestation_target_not_in_store(spec, state):
|
def test_on_attestation_target_not_in_store(spec, state):
|
||||||
|
|
Loading…
Reference in New Issue