Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions tests/core/pyspec/eth2spec/test/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: hoist import sys to the top of the file

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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from eth2spec.test.context import (
MAINNET,
spec_configured_state_test,
spec_state_test,
with_all_phases,
Expand All @@ -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,
Expand Down