mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-22 00:20:28 +00:00
Merge pull request #3107 from etan-status/sf-epochoverrides
cleanup explicit fork enumerations in tests
This commit is contained in:
commit
dc17b1e2b6
@ -4,10 +4,11 @@ from eth2spec.test.context import (
|
|||||||
with_all_phases,
|
with_all_phases,
|
||||||
with_phases,
|
with_phases,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.constants import ALTAIR
|
from eth2spec.test.helpers.constants import (
|
||||||
from eth2spec.test.helpers.forks import (
|
PHASE0, ALTAIR,
|
||||||
is_post_capella, is_post_eip4844,
|
ALL_PHASES,
|
||||||
)
|
)
|
||||||
|
from eth2spec.test.helpers.forks import is_post_fork
|
||||||
|
|
||||||
|
|
||||||
@with_phases([ALTAIR])
|
@with_phases([ALTAIR])
|
||||||
@ -30,29 +31,28 @@ def test_config_override(spec, state):
|
|||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test_with_matching_config
|
@spec_state_test_with_matching_config
|
||||||
def test_override_config_fork_epoch(spec, state):
|
def test_override_config_fork_epoch(spec, state):
|
||||||
if state.fork.current_version == spec.config.GENESIS_FORK_VERSION:
|
# Fork schedule must be consistent with state fork
|
||||||
return
|
epoch = spec.get_current_epoch(state)
|
||||||
|
if is_post_fork(spec.fork, ALTAIR):
|
||||||
|
assert state.fork.current_version == spec.compute_fork_version(epoch)
|
||||||
|
else:
|
||||||
|
assert state.fork.current_version == spec.config.GENESIS_FORK_VERSION
|
||||||
|
|
||||||
assert spec.config.ALTAIR_FORK_EPOCH == spec.GENESIS_EPOCH
|
# Identify state fork
|
||||||
if state.fork.current_version == spec.config.ALTAIR_FORK_VERSION:
|
state_fork = None
|
||||||
return
|
for fork in [fork for fork in ALL_PHASES if is_post_fork(spec.fork, fork)]:
|
||||||
|
if fork == PHASE0:
|
||||||
|
fork_version_field = 'GENESIS_FORK_VERSION'
|
||||||
|
else:
|
||||||
|
fork_version_field = fork.upper() + '_FORK_VERSION'
|
||||||
|
if state.fork.current_version == getattr(spec.config, fork_version_field):
|
||||||
|
state_fork = fork
|
||||||
|
break
|
||||||
|
assert state_fork is not None
|
||||||
|
|
||||||
assert spec.config.BELLATRIX_FORK_EPOCH == spec.GENESIS_EPOCH
|
# Check that all prior forks have already been triggered
|
||||||
if state.fork.current_version == spec.config.BELLATRIX_FORK_VERSION:
|
for fork in [fork for fork in ALL_PHASES if is_post_fork(state_fork, fork)]:
|
||||||
return
|
if fork == PHASE0:
|
||||||
|
continue
|
||||||
if is_post_capella(spec):
|
fork_epoch_field = fork.upper() + '_FORK_EPOCH'
|
||||||
assert spec.config.CAPELLA_FORK_EPOCH == spec.GENESIS_EPOCH
|
assert getattr(spec.config, fork_epoch_field) <= epoch
|
||||||
if state.fork.current_version == spec.config.CAPELLA_FORK_VERSION:
|
|
||||||
return
|
|
||||||
|
|
||||||
if is_post_eip4844(spec):
|
|
||||||
assert spec.config.EIP4844_FORK_EPOCH == spec.GENESIS_EPOCH
|
|
||||||
if state.fork.current_version == spec.config.EIP4844_FORK_VERSION:
|
|
||||||
return
|
|
||||||
|
|
||||||
assert spec.config.SHARDING_FORK_EPOCH == spec.GENESIS_EPOCH
|
|
||||||
if state.fork.current_version == spec.config.SHARDING_FORK_VERSION:
|
|
||||||
return
|
|
||||||
|
|
||||||
assert False # Fork is missing
|
|
||||||
|
@ -11,7 +11,7 @@ from eth2spec.utils import bls
|
|||||||
|
|
||||||
from .exceptions import SkippedTest
|
from .exceptions import SkippedTest
|
||||||
from .helpers.constants import (
|
from .helpers.constants import (
|
||||||
PHASE0, ALTAIR, BELLATRIX, CAPELLA, EIP4844, SHARDING,
|
PHASE0, ALTAIR, BELLATRIX, CAPELLA, EIP4844,
|
||||||
MINIMAL, MAINNET,
|
MINIMAL, MAINNET,
|
||||||
ALL_PHASES,
|
ALL_PHASES,
|
||||||
ALL_FORK_UPGRADES,
|
ALL_FORK_UPGRADES,
|
||||||
@ -297,31 +297,16 @@ def _check_current_version(spec, state, version_name):
|
|||||||
|
|
||||||
|
|
||||||
def config_fork_epoch_overrides(spec, state):
|
def config_fork_epoch_overrides(spec, state):
|
||||||
overrides = {}
|
|
||||||
if state.fork.current_version == spec.config.GENESIS_FORK_VERSION:
|
if state.fork.current_version == spec.config.GENESIS_FORK_VERSION:
|
||||||
pass
|
return {}
|
||||||
elif _check_current_version(spec, state, ALTAIR):
|
|
||||||
overrides['ALTAIR_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
for fork in ALL_PHASES:
|
||||||
elif _check_current_version(spec, state, BELLATRIX):
|
if fork != PHASE0 and _check_current_version(spec, state, fork):
|
||||||
overrides['ALTAIR_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
overrides = {}
|
||||||
overrides['BELLATRIX_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
for f in ALL_PHASES:
|
||||||
elif _check_current_version(spec, state, CAPELLA):
|
if f != PHASE0 and is_post_fork(fork, f):
|
||||||
overrides['ALTAIR_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
overrides[f.upper() + '_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
||||||
overrides['BELLATRIX_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
return overrides
|
||||||
overrides['CAPELLA_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
elif _check_current_version(spec, state, EIP4844):
|
|
||||||
overrides['ALTAIR_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
overrides['BELLATRIX_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
overrides['CAPELLA_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
overrides['EIP4844_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
elif _check_current_version(spec, state, SHARDING):
|
|
||||||
overrides['ALTAIR_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
overrides['BELLATRIX_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
overrides['CAPELLA_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
overrides['SHARDING_FORK_EPOCH'] = spec.GENESIS_EPOCH
|
|
||||||
else:
|
|
||||||
assert False # Fork is missing
|
|
||||||
return overrides
|
|
||||||
|
|
||||||
|
|
||||||
def spec_state_test_with_matching_config(fn):
|
def spec_state_test_with_matching_config(fn):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user