update attestation testing

This commit is contained in:
protolambda 2019-05-06 16:23:15 +02:00
parent dcedfc350a
commit 7bbf9ed3fc
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 15 additions and 18 deletions

View File

@ -17,13 +17,15 @@ from tests.helpers import (
next_slot, next_slot,
) )
from tests.utils import spectest from .block_test_helpers import spec_state_test
from tests.context import with_state
def run_attestation_processing(state, attestation, valid=True): def run_attestation_processing(state, attestation, valid=True):
""" """
Run ``process_attestation``, yielding pre-state ('pre'), attestation ('attestation'), and post-state ('post'). Run ``process_attestation``, yielding:
- pre-state ('pre')
- attestation ('attestation')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError`` If ``valid == False``, run expecting ``AssertionError``
""" """
# yield pre-state # yield pre-state
@ -54,12 +56,7 @@ def run_attestation_processing(state, attestation, valid=True):
yield 'post', state yield 'post', state
# shorthand for decorating @with_state @spectest() @spec_state_test
def attestation_test(fn):
return with_state(spectest()(fn))
@attestation_test
def test_success(state): def test_success(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
@ -67,7 +64,7 @@ def test_success(state):
yield from run_attestation_processing(state, attestation) yield from run_attestation_processing(state, attestation)
@attestation_test @spec_state_test
def test_success_prevous_epoch(state): def test_success_prevous_epoch(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
block = build_empty_block_for_next_slot(state) block = build_empty_block_for_next_slot(state)
@ -77,7 +74,7 @@ def test_success_prevous_epoch(state):
yield from run_attestation_processing(state, attestation) yield from run_attestation_processing(state, attestation)
@attestation_test @spec_state_test
def test_before_inclusion_delay(state): def test_before_inclusion_delay(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
# do not increment slot to allow for inclusion delay # do not increment slot to allow for inclusion delay
@ -85,7 +82,7 @@ def test_before_inclusion_delay(state):
yield from run_attestation_processing(state, attestation, False) yield from run_attestation_processing(state, attestation, False)
@attestation_test @spec_state_test
def test_after_epoch_slots(state): def test_after_epoch_slots(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
block = build_empty_block_for_next_slot(state) block = build_empty_block_for_next_slot(state)
@ -96,7 +93,7 @@ def test_after_epoch_slots(state):
yield from run_attestation_processing(state, attestation, False) yield from run_attestation_processing(state, attestation, False)
@attestation_test @spec_state_test
def test_bad_source_epoch(state): def test_bad_source_epoch(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
@ -106,7 +103,7 @@ def test_bad_source_epoch(state):
yield from run_attestation_processing(state, attestation, False) yield from run_attestation_processing(state, attestation, False)
@attestation_test @spec_state_test
def test_bad_source_root(state): def test_bad_source_root(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
@ -116,7 +113,7 @@ def test_bad_source_root(state):
yield from run_attestation_processing(state, attestation, False) yield from run_attestation_processing(state, attestation, False)
@attestation_test @spec_state_test
def test_non_zero_crosslink_data_root(state): def test_non_zero_crosslink_data_root(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
@ -126,7 +123,7 @@ def test_non_zero_crosslink_data_root(state):
yield from run_attestation_processing(state, attestation, False) yield from run_attestation_processing(state, attestation, False)
@attestation_test @spec_state_test
def test_bad_previous_crosslink(state): def test_bad_previous_crosslink(state):
next_epoch(state) next_epoch(state)
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
@ -138,7 +135,7 @@ def test_bad_previous_crosslink(state):
yield from run_attestation_processing(state, attestation, False) yield from run_attestation_processing(state, attestation, False)
@attestation_test @spec_state_test
def test_non_empty_custody_bitfield(state): def test_non_empty_custody_bitfield(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
@ -148,7 +145,7 @@ def test_non_empty_custody_bitfield(state):
yield from run_attestation_processing(state, attestation, False) yield from run_attestation_processing(state, attestation, False)
@attestation_test @spec_state_test
def test_empty_aggregation_bitfield(state): def test_empty_aggregation_bitfield(state):
attestation = get_valid_attestation(state) attestation = get_valid_attestation(state)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY