eth2.0-specs/tests/phase0/block_processing/test_process_block_header.py

85 lines
1.7 KiB
Python
Raw Normal View History

2019-03-20 14:22:47 +00:00
from copy import deepcopy
import pytest
from build.phase0.spec import (
2019-03-20 14:51:40 +00:00
cache_state,
advance_slot,
2019-03-20 14:22:47 +00:00
process_block_header,
)
from tests.phase0.helpers import (
build_empty_block_for_next_slot,
)
# mark entire file as 'header'
pytestmark = pytest.mark.header
2019-03-20 14:51:40 +00:00
def test_sucess(state):
2019-03-20 14:22:47 +00:00
pre_state = deepcopy(state)
2019-03-20 14:51:40 +00:00
block = build_empty_block_for_next_slot(pre_state)
#
# setup pre_state to be ready for block transition
#
cache_state(pre_state)
advance_slot(pre_state)
post_state = deepcopy(pre_state)
#
# test block header
#
process_block_header(post_state, block)
return state, [block], post_state
def test_invalid_slot(state):
pre_state = deepcopy(state)
# mess up previous block root
block = build_empty_block_for_next_slot(pre_state)
block.previous_block_root = b'\12'*32
#
# setup pre_state advancing two slots to induce error
#
cache_state(pre_state)
advance_slot(pre_state)
advance_slot(pre_state)
2019-03-20 14:22:47 +00:00
2019-03-20 14:51:40 +00:00
post_state = deepcopy(pre_state)
#
# test block header
#
with pytest.raises(AssertionError):
process_block_header(post_state, block)
return state, [block], None
def test_invalid_previous_block_root(state):
pre_state = deepcopy(state)
# mess up previous block root
2019-03-20 14:22:47 +00:00
block = build_empty_block_for_next_slot(pre_state)
2019-03-20 14:51:40 +00:00
block.previous_block_root = b'\12'*32
#
# setup pre_state to be ready for block transition
#
cache_state(pre_state)
advance_slot(pre_state)
post_state = deepcopy(pre_state)
#
# test block header
#
2019-03-20 14:22:47 +00:00
with pytest.raises(AssertionError):
2019-03-20 14:51:40 +00:00
process_block_header(post_state, block)
2019-03-20 14:22:47 +00:00
return state, [block], None