update block header testing

This commit is contained in:
protolambda 2019-05-06 16:23:53 +02:00
parent 61c0ddbcbb
commit 9ff52193b1
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 21 additions and 16 deletions

View File

@ -13,8 +13,7 @@ from tests.helpers import (
next_slot, next_slot,
) )
# mark entire file as 'header' from .block_test_helpers import spec_state_test
pytestmark = pytest.mark.header
def prepare_state_for_header_processing(state): def prepare_state_for_header_processing(state):
@ -24,43 +23,50 @@ def prepare_state_for_header_processing(state):
def run_block_header_processing(state, block, valid=True): def run_block_header_processing(state, block, valid=True):
""" """
Run ``process_block_header`` returning the pre and post state. Run ``process_block_header``, yielding:
- pre-state ('pre')
- block ('block')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError`` If ``valid == False``, run expecting ``AssertionError``
""" """
prepare_state_for_header_processing(state) prepare_state_for_header_processing(state)
post_state = deepcopy(state)
yield 'pre', state
yield 'block', block
if not valid: if not valid:
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
process_block_header(post_state, block) process_block_header(state, block)
return state, None yield 'post', None
return
process_block_header(post_state, block) process_block_header(state, block)
return state, post_state yield 'post', state
@spec_state_test
def test_success(state): def test_success(state):
block = build_empty_block_for_next_slot(state) block = build_empty_block_for_next_slot(state)
pre_state, post_state = run_block_header_processing(state, block) yield from run_block_header_processing(state, block)
return state, block, post_state
@spec_state_test
def test_invalid_slot(state): def test_invalid_slot(state):
block = build_empty_block_for_next_slot(state) block = build_empty_block_for_next_slot(state)
block.slot = state.slot + 2 # invalid slot block.slot = state.slot + 2 # invalid slot
pre_state, post_state = run_block_header_processing(state, block, valid=False) yield from run_block_header_processing(state, block, valid=False)
return pre_state, block, None
@spec_state_test
def test_invalid_previous_block_root(state): def test_invalid_previous_block_root(state):
block = build_empty_block_for_next_slot(state) block = build_empty_block_for_next_slot(state)
block.previous_block_root = b'\12' * 32 # invalid prev root block.previous_block_root = b'\12' * 32 # invalid prev root
pre_state, post_state = run_block_header_processing(state, block, valid=False) yield from run_block_header_processing(state, block, valid=False)
return pre_state, block, None
@spec_state_test
def test_proposer_slashed(state): def test_proposer_slashed(state):
# use stub state to get proposer index of next slot # use stub state to get proposer index of next slot
stub_state = deepcopy(state) stub_state = deepcopy(state)
@ -72,5 +78,4 @@ def test_proposer_slashed(state):
block = build_empty_block_for_next_slot(state) block = build_empty_block_for_next_slot(state)
pre_state, post_state = run_block_header_processing(state, block, valid=False) yield from run_block_header_processing(state, block, valid=False)
return pre_state, block, None