mirror of
https://github.com/ethereum/consensus-specs.git
synced 2026-02-02 10:54:59 -05:00
demo phase restricted generators for epoch processing
This commit is contained in:
@@ -2,7 +2,7 @@ from typing import Callable, Iterable
|
||||
|
||||
from eth2spec.phase0 import spec as spec_phase0
|
||||
from eth2spec.phase1 import spec as spec_phase1
|
||||
from eth2spec.test.epoch_processing import (
|
||||
from eth2spec.test.phase_0.epoch_processing import (
|
||||
test_process_crosslinks,
|
||||
test_process_registry_updates
|
||||
)
|
||||
@@ -33,8 +33,8 @@ def create_suite(transition_name: str, config_name: str, get_cases: Callable[[],
|
||||
|
||||
if __name__ == "__main__":
|
||||
gen_runner.run_generator("epoch_processing", [
|
||||
create_suite('crosslinks', 'minimal', lambda: generate_from_tests(test_process_crosslinks)),
|
||||
create_suite('crosslinks', 'mainnet', lambda: generate_from_tests(test_process_crosslinks)),
|
||||
create_suite('registry_updates', 'minimal', lambda: generate_from_tests(test_process_registry_updates)),
|
||||
create_suite('registry_updates', 'mainnet', lambda: generate_from_tests(test_process_registry_updates)),
|
||||
create_suite('crosslinks', 'minimal', lambda: generate_from_tests(test_process_crosslinks, 'phase0')),
|
||||
create_suite('crosslinks', 'mainnet', lambda: generate_from_tests(test_process_crosslinks, 'phase0')),
|
||||
create_suite('registry_updates', 'minimal', lambda: generate_from_tests(test_process_registry_updates, 'phase0')),
|
||||
create_suite('registry_updates', 'mainnet', lambda: generate_from_tests(test_process_registry_updates, 'phase0')),
|
||||
])
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from inspect import getmembers, isfunction
|
||||
|
||||
def generate_from_tests(src, bls_active=True):
|
||||
def generate_from_tests(src, phase, bls_active=True):
|
||||
"""
|
||||
Generate a list of test cases by running tests from the given src in generator-mode.
|
||||
:param src: to retrieve tests from (discovered using inspect.getmembers)
|
||||
:param src: to retrieve tests from (discovered using inspect.getmembers).
|
||||
:param phase: to run tests against particular phase.
|
||||
:param bls_active: optional, to override BLS switch preference. Defaults to True.
|
||||
:return: the list of test cases.
|
||||
"""
|
||||
@@ -16,7 +17,7 @@ def generate_from_tests(src, bls_active=True):
|
||||
for name in fn_names:
|
||||
tfn = getattr(src, name)
|
||||
try:
|
||||
test_case = tfn(generator_mode=True, bls_active=bls_active)
|
||||
test_case = tfn(generator_mode=True, phase=phase, bls_active=bls_active)
|
||||
# If no test case data is returned, the test is ignored.
|
||||
if test_case is not None:
|
||||
out.append(test_case)
|
||||
|
||||
@@ -119,9 +119,18 @@ def with_phases(phases):
|
||||
fn(*args, **kw)
|
||||
|
||||
def wrapper(*args, **kw):
|
||||
if 'phase0' in phases:
|
||||
run_phases = phases
|
||||
|
||||
# limit phases if one explicitly specified
|
||||
if 'phase' in kw:
|
||||
phase = kw.pop('phase')
|
||||
if phase not in phases:
|
||||
return
|
||||
run_phases = [phase]
|
||||
|
||||
if 'phase0' in run_phases:
|
||||
run_with_spec_version(spec_phase0, *args, **kw)
|
||||
if 'phase1' in phases:
|
||||
if 'phase1' in run_phases:
|
||||
run_with_spec_version(spec_phase1, *args, **kw)
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user