move sanity tests, separate slot tests
This commit is contained in:
parent
1bbab9aa00
commit
21c48b574f
|
@ -1,6 +1,6 @@
|
||||||
from typing import Callable, Iterable
|
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_base import gen_runner, gen_suite, gen_typing
|
||||||
from gen_from_tests.gen import generate_from_tests
|
from gen_from_tests.gen import generate_from_tests
|
||||||
|
@ -8,25 +8,28 @@ from preset_loader import loader
|
||||||
from eth2spec.phase0 import spec
|
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]:
|
-> Callable[[str], gen_typing.TestSuiteOutput]:
|
||||||
def suite_definition(configs_path: str) -> gen_typing.TestSuiteOutput:
|
def suite_definition(configs_path: str) -> gen_typing.TestSuiteOutput:
|
||||||
presets = loader.load_presets(configs_path, config_name)
|
presets = loader.load_presets(configs_path, config_name)
|
||||||
spec.apply_constants_preset(presets)
|
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",
|
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_timeline="testing",
|
||||||
forks=["phase0"],
|
forks=["phase0"],
|
||||||
config=config_name,
|
config=config_name,
|
||||||
runner="sanity",
|
runner="sanity",
|
||||||
handler="core",
|
handler=handler_name,
|
||||||
test_cases=get_cases()))
|
test_cases=get_cases()))
|
||||||
return suite_definition
|
return suite_definition
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
gen_runner.run_generator("sanity", [
|
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)),
|
||||||
])
|
])
|
||||||
|
|
|
@ -13,42 +13,20 @@ from eth2spec.phase0.spec import (
|
||||||
get_block_root_at_slot,
|
get_block_root_at_slot,
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
get_domain,
|
get_domain,
|
||||||
advance_slot,
|
|
||||||
cache_state,
|
|
||||||
)
|
)
|
||||||
from eth2spec.phase0.state_transition import (
|
from eth2spec.phase0.state_transition import (
|
||||||
state_transition,
|
state_transition,
|
||||||
)
|
)
|
||||||
from .helpers.state import (
|
from eth2spec.test.helpers.state import get_balance
|
||||||
get_balance,
|
from eth2spec.test.helpers.transfers import get_valid_transfer
|
||||||
get_state_root
|
from eth2spec.test.helpers.block import build_empty_block_for_next_slot, sign_block
|
||||||
)
|
from eth2spec.test.helpers.keys import privkeys, pubkeys
|
||||||
from .helpers.transfers import get_valid_transfer
|
from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing
|
||||||
from .helpers.block import build_empty_block_for_next_slot, sign_block
|
from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing
|
||||||
from .helpers.keys import (
|
from eth2spec.test.helpers.attestations import get_valid_attestation
|
||||||
privkeys,
|
from eth2spec.test.helpers.deposits import prepare_state_and_deposit
|
||||||
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 .context import spec_state_test, never_bls
|
from eth2spec.test.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
|
|
||||||
|
|
||||||
|
|
||||||
@never_bls
|
@never_bls
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue