Apply with_config_overrides to all phases

When defining a fork transition test, additional spec forks are made
available through `@with_phases(..., other_phases=...)`.
The `with_config_overrides` decorator only applies to the primary phase
so far, which can be unexpected. `with_config_overrides` is adjusted to
override config in subsequent `other_phases` as well.
This commit is contained in:
Etan Kissling 2022-11-19 12:57:13 +01:00
parent 208da34ac4
commit f42da8d00b
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
2 changed files with 44 additions and 20 deletions

View File

@ -1,10 +1,13 @@
from eth2spec.test.context import (
spec_configured_state_test,
spec_state_test_with_matching_config,
spec_test,
with_all_phases,
with_matching_spec_config,
with_phases,
with_state,
)
from eth2spec.test.helpers.constants import ALTAIR
from eth2spec.test.helpers.constants import ALTAIR, BELLATRIX
from eth2spec.test.helpers.forks import (
is_post_capella, is_post_eip4844,
)
@ -56,3 +59,12 @@ def test_override_config_fork_epoch(spec, state):
return
assert False # Fork is missing
@with_phases(phases=[ALTAIR], other_phases=[BELLATRIX])
@spec_test
@with_state
@with_matching_spec_config
def test_capella_store_with_legacy_data(spec, phases, state):
assert state.fork.current_version == spec.config.ALTAIR_FORK_VERSION
assert phases[BELLATRIX].ALTAIR_FORK_EPOCH == spec.config.ALTAIR_FORK_EPOCH

View File

@ -318,14 +318,16 @@ def config_fork_epoch_overrides(spec, state):
return overrides
def spec_state_test_with_matching_config(fn):
def decorator(fn):
def wrapper(*args, spec: Spec, **kw):
def with_matching_spec_config(fn):
def decorator(*args, spec: Spec, **kw):
conf = config_fork_epoch_overrides(spec, kw['state'])
overrides = with_config_overrides(conf)
return overrides(fn)(*args, spec=spec, **kw)
return wrapper
return spec_test(with_state(decorator(single_phase(fn))))
return decorator
def spec_state_test_with_matching_config(fn):
return spec_test(with_state(with_matching_spec_config(single_phase(fn))))
def expect_assertion_error(fn):
@ -569,6 +571,22 @@ def _get_copy_of_spec(spec):
return module
def spec_with_config_overrides(spec, config_overrides):
# apply our overrides to a copy of it, and apply it to the spec
config = spec.config._asdict()
config.update(config_overrides)
config_types = spec.Configuration.__annotations__
modified_config = {k: config_types[k](v) for k, v in config.items()}
spec.config = spec.Configuration(**modified_config)
# To output the changed config in a format compatible with yaml test vectors,
# the dict SSZ objects have to be converted into Python built-in types.
output_config = _get_basic_dict(modified_config)
return spec, output_config
def with_config_overrides(config_overrides):
"""
WARNING: the spec_test decorator must wrap this, to ensure the decorated test actually runs.
@ -579,20 +597,14 @@ def with_config_overrides(config_overrides):
"""
def decorator(fn):
def wrapper(*args, spec: Spec, **kw):
spec = _get_copy_of_spec(spec)
# apply our overrides to a copy of it, and apply it to the spec
config = spec.config._asdict()
config.update(config_overrides)
config_types = spec.Configuration.__annotations__
modified_config = {k: config_types[k](v) for k, v in config.items()}
# To output the changed config to could be serialized with yaml test vectors,
# the dict SSZ objects have to be converted into Python built-in types.
output_config = _get_basic_dict(modified_config)
spec, output_config = spec_with_config_overrides(_get_copy_of_spec(spec), config_overrides)
yield 'config', 'cfg', output_config
spec.config = spec.Configuration(**modified_config)
if 'phases' in kw:
for fork in kw['phases']:
if is_post_fork(fork, spec.fork):
kw['phases'][fork], _ = \
spec_with_config_overrides(_get_copy_of_spec(kw['phases'][fork]), config_overrides)
# Run the function
out = fn(*args, spec=spec, **kw)