diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index 2a6f2e324a..0ba4a20f36 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -2,19 +2,17 @@ from copy import deepcopy from dataclasses import dataclass from eth_utils import encode_hex +import importlib -from eth2spec.phase0 import mainnet as spec_phase0_mainnet, minimal as spec_phase0_minimal -from eth2spec.altair import mainnet as spec_altair_mainnet, minimal as spec_altair_minimal -from eth2spec.merge import mainnet as spec_merge_mainnet, minimal as spec_merge_minimal from eth2spec.utils import bls from .exceptions import SkippedTest from .helpers.constants import ( - PHASE0, ALTAIR, MERGE, MINIMAL, MAINNET, + PHASE0, ALTAIR, MINIMAL, ALL_PHASES, FORKS_BEFORE_ALTAIR, FORKS_BEFORE_MERGE, ALL_FORK_UPGRADES, ) -from .helpers.typing import SpecForkName, PresetBaseName +from .helpers.typing import SpecForkName from .helpers.genesis import create_genesis_state from .utils import ( vector_test, @@ -64,20 +62,6 @@ class ForkMeta: fork_epoch: int -spec_targets: Dict[PresetBaseName, Dict[SpecForkName, Spec]] = { - MINIMAL: { - PHASE0: spec_phase0_minimal, - ALTAIR: spec_altair_minimal, - MERGE: spec_merge_minimal, - }, - MAINNET: { - PHASE0: spec_phase0_mainnet, - ALTAIR: spec_altair_mainnet, - MERGE: spec_merge_mainnet, - }, -} - - class SpecForks(TypedDict, total=False): PHASE0: SpecPhase0 ALTAIR: SpecAltair @@ -360,11 +344,31 @@ def decorator(fn): return decorator +def _get_module(module_path): + module_spec = importlib.util.find_spec(module_path) + module = importlib.util.module_from_spec(module_spec) + loader = importlib.util.LazyLoader(module_spec.loader) + module_spec.loader = loader + import sys + sys.modules[module_path] = module + loader.exec_module(module) + return module + + +def _get_targets(preset_name: SpecForkName) -> Dict[SpecForkName, Spec]: + return { + # e.g., eth2spec.phase0.mainnet + fork_name: _get_module('eth2spec.' + fork_name + '.' + preset_name) + for fork_name in ALL_PHASES + } + + def _get_preset_targets(kw): preset_name = DEFAULT_TEST_PRESET if 'preset' in kw: preset_name = kw.pop('preset') - return spec_targets[preset_name] + + return _get_targets(preset_name) def _get_run_phases(phases, kw): diff --git a/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py b/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py index e0703fdf7f..7c52a60bad 100644 --- a/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py +++ b/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py @@ -1,9 +1,10 @@ from eth2spec.utils.ssz.ssz_typing import uint256 from eth2spec.test.exceptions import BlockNotFoundException -from eth2spec.test.context import spec_state_test, with_phases, MERGE +from eth2spec.test.context import spec_state_test, with_phases from eth2spec.test.helpers.block import ( build_empty_block_for_next_slot, ) +from eth2spec.test.helpers.constants import MERGE from eth2spec.test.helpers.fork_choice import ( get_genesis_forkchoice_store_and_block, on_tick_and_append_step, diff --git a/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py b/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py index 9cd388698d..cb4b0c4ba6 100644 --- a/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py +++ b/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py @@ -1,12 +1,14 @@ from eth2spec.test.context import ( - MERGE, single_phase, spec_test, with_presets, with_phases, with_merge_and_later, ) -from eth2spec.test.helpers.constants import MINIMAL +from eth2spec.test.helpers.constants import ( + MERGE, + MINIMAL, +) from eth2spec.test.helpers.deposits import ( prepare_full_genesis_deposits, ) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_ex_ante.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_ex_ante.py index b3a8b38fb2..3995536000 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_ex_ante.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_ex_ante.py @@ -1,5 +1,4 @@ from eth2spec.test.context import ( - MAINNET, spec_configured_state_test, spec_state_test, with_all_phases, @@ -12,6 +11,7 @@ from eth2spec.test.helpers.block import ( build_empty_block, ) +from eth2spec.test.helpers.constants import MAINNET from eth2spec.test.helpers.fork_choice import ( get_genesis_forkchoice_store_and_block, on_tick_and_append_step,