diff --git a/test_generators/sanity/main.py b/test_generators/sanity/main.py index 887d0eb06..bba6ed03d 100644 --- a/test_generators/sanity/main.py +++ b/test_generators/sanity/main.py @@ -1,6 +1,6 @@ from typing import Callable, Iterable -from eth2spec.test import test_sanity +from eth2spec.test.sanity import test_blocks, test_slots from gen_base import gen_runner, gen_suite, gen_typing from gen_from_tests.gen import generate_from_tests @@ -8,25 +8,28 @@ from preset_loader import loader from eth2spec.phase0 import spec -def create_suite(config_name: str, get_cases: Callable[[], Iterable[gen_typing.TestCase]]) \ +def create_suite(handler_name: str, config_name: str, get_cases: Callable[[], Iterable[gen_typing.TestCase]]) \ -> Callable[[str], gen_typing.TestSuiteOutput]: def suite_definition(configs_path: str) -> gen_typing.TestSuiteOutput: presets = loader.load_presets(configs_path, config_name) spec.apply_constants_preset(presets) - return ("%s_sanity" % config_name, "core", gen_suite.render_suite( + return ("%sanity_s_%s" % (handler_name, config_name), handler_name, gen_suite.render_suite( title="sanity testing", - summary="Sanity test suite, generated from pytests", + summary="Sanity test suite, %s type, generated from pytests" % handler_name, forks_timeline="testing", forks=["phase0"], config=config_name, runner="sanity", - handler="core", + handler=handler_name, test_cases=get_cases())) return suite_definition if __name__ == "__main__": gen_runner.run_generator("sanity", [ - create_suite('minimal', lambda: generate_from_tests(test_sanity)), + create_suite('blocks', 'minimal', lambda: generate_from_tests(test_blocks)), + create_suite('blocks', 'mainnet', lambda: generate_from_tests(test_blocks)), + create_suite('slots', 'minimal', lambda: generate_from_tests(test_slots)), + create_suite('slots', 'mainnet', lambda: generate_from_tests(test_slots)), ]) diff --git a/test_libs/pyspec/eth2spec/test/sanity/__init__.py b/test_libs/pyspec/eth2spec/test/sanity/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test_libs/pyspec/eth2spec/test/test_sanity.py b/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py similarity index 93% rename from test_libs/pyspec/eth2spec/test/test_sanity.py rename to test_libs/pyspec/eth2spec/test/sanity/test_blocks.py index 6d65cc7f4..01ffa304e 100644 --- a/test_libs/pyspec/eth2spec/test/test_sanity.py +++ b/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py @@ -13,42 +13,20 @@ from eth2spec.phase0.spec import ( get_block_root_at_slot, get_current_epoch, get_domain, - advance_slot, - cache_state, ) from eth2spec.phase0.state_transition import ( state_transition, ) -from .helpers.state import ( - get_balance, - get_state_root -) -from .helpers.transfers import get_valid_transfer -from .helpers.block import build_empty_block_for_next_slot, sign_block -from .helpers.keys import ( - privkeys, - pubkeys, -) -from .helpers.attester_slashings import get_valid_attester_slashing -from .helpers.proposer_slashings import get_valid_proposer_slashing -from .helpers.attestations import get_valid_attestation -from .helpers.deposits import prepare_state_and_deposit +from eth2spec.test.helpers.state import get_balance +from eth2spec.test.helpers.transfers import get_valid_transfer +from eth2spec.test.helpers.block import build_empty_block_for_next_slot, sign_block +from eth2spec.test.helpers.keys import privkeys, pubkeys +from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing +from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing +from eth2spec.test.helpers.attestations import get_valid_attestation +from eth2spec.test.helpers.deposits import prepare_state_and_deposit -from .context import spec_state_test, never_bls - - -@spec_state_test -def test_slot_transition(state): - pre_slot = state.slot - pre_root = state.hash_tree_root() - yield 'pre', state - - cache_state(state) - advance_slot(state) - yield 'post', state - - assert state.slot == pre_slot + 1 - assert get_state_root(state, pre_slot) == pre_root +from eth2spec.test.context import spec_state_test, never_bls @never_bls diff --git a/test_libs/pyspec/eth2spec/test/sanity/test_slots.py b/test_libs/pyspec/eth2spec/test/sanity/test_slots.py new file mode 100644 index 000000000..2e5f3a5df --- /dev/null +++ b/test_libs/pyspec/eth2spec/test/sanity/test_slots.py @@ -0,0 +1,58 @@ +import eth2spec.phase0.spec as spec + +from eth2spec.phase0.state_transition import state_transition_to +from eth2spec.test.helpers.state import get_state_root +from eth2spec.test.context import spec_state_test + + +@spec_state_test +def test_slots_1(state): + pre_slot = state.slot + pre_root = state.hash_tree_root() + yield 'pre', state + + slots = 1 + yield 'slots', slots + state_transition_to(state, state.slot + slots) + + yield 'post', state + assert state.slot == pre_slot + 1 + assert get_state_root(state, pre_slot) == pre_root + + +@spec_state_test +def test_slots_2(state): + yield 'pre', state + slots = 2 + yield 'slots', slots + state_transition_to(state, state.slot + slots) + yield 'post', state + + +@spec_state_test +def test_empty_epoch(state): + yield 'pre', state + slots = spec.SLOTS_PER_EPOCH + yield 'slots', slots + state_transition_to(state, state.slot + slots) + yield 'post', state + + +@spec_state_test +def test_double_empty_epoch(state): + yield 'pre', state + slots = spec.SLOTS_PER_EPOCH * 2 + yield 'slots', slots + state_transition_to(state, state.slot + slots) + yield 'post', state + + +@spec_state_test +def test_over_epoch_boundary(state): + state_transition_to(state, state.slot + (spec.SLOTS_PER_EPOCH // 2)) + yield 'pre', state + slots = spec.SLOTS_PER_EPOCH + yield 'slots', slots + state_transition_to(state, state.slot + slots) + yield 'post', state +