From 0641d1c1840f1b374ae4d1383ba720fb1879d99c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 2 Nov 2021 19:01:32 +0800 Subject: [PATCH] `ALL_FORKS` sounds like a list of fork names. Rename it to `ALL_FORK_UPGRADES` --- .../transition/test_activations_and_exits.py | 10 +++++----- .../test/altair/transition/test_leaking.py | 6 +++--- .../test/altair/transition/test_operations.py | 18 +++++++++--------- .../test/altair/transition/test_slashing.py | 4 ++-- .../test/altair/transition/test_transition.py | 18 +++++++++--------- tests/core/pyspec/eth2spec/test/context.py | 4 ++-- .../pyspec/eth2spec/test/helpers/constants.py | 4 +++- tests/generators/transition/main.py | 4 ++-- 8 files changed, 35 insertions(+), 33 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py index 0f5b28db6..e698c56ba 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py @@ -5,7 +5,7 @@ from eth2spec.test.context import ( with_fork_metas, ) from eth2spec.test.helpers.constants import ( - ALL_FORKS, + ALL_PRE_POST_FORKS, MINIMAL, ) from eth2spec.test.helpers.fork_transition import ( @@ -24,7 +24,7 @@ from eth2spec.test.helpers.random import ( # Exit # -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) @with_presets([MINIMAL], reason="only test with enough validators such that at least one exited index is not in sync committee") def test_transition_with_one_fourth_exiting_validators_exit_post_fork(state, @@ -84,7 +84,7 @@ def test_transition_with_one_fourth_exiting_validators_exit_post_fork(state, yield "post", state -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_one_fourth_exiting_validators_exit_at_fork(state, fork_epoch, spec, @@ -142,7 +142,7 @@ def test_transition_with_one_fourth_exiting_validators_exit_at_fork(state, # -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_non_empty_activation_queue(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Create some deposits before the transition @@ -170,7 +170,7 @@ def test_transition_with_non_empty_activation_queue(state, fork_epoch, spec, pos yield "post", state -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_activation_at_fork_epoch(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Create some deposits before the transition diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_leaking.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_leaking.py index 3ed2e37ee..338289597 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_leaking.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_leaking.py @@ -3,7 +3,7 @@ from eth2spec.test.context import ( with_fork_metas, ) from eth2spec.test.helpers.constants import ( - ALL_FORKS, + ALL_PRE_POST_FORKS, ) from eth2spec.test.helpers.fork_transition import ( do_fork, @@ -12,7 +12,7 @@ from eth2spec.test.helpers.fork_transition import ( ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=7) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=7) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_leaking_pre_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Leaking starts at epoch 6 (MIN_EPOCHS_TO_INACTIVITY_PENALTY + 2). @@ -40,7 +40,7 @@ def test_transition_with_leaking_pre_fork(state, fork_epoch, spec, post_spec, pr yield "post", state -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=6) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=6) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_leaking_at_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Leaking starts at epoch 6 (MIN_EPOCHS_TO_INACTIVITY_PENALTY + 2). diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_operations.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_operations.py index 54f37a235..121053186 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_operations.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_operations.py @@ -5,7 +5,7 @@ from eth2spec.test.context import ( with_presets, ) from eth2spec.test.helpers.constants import ( - ALL_FORKS, + ALL_PRE_POST_FORKS, MINIMAL, ) from eth2spec.test.helpers.fork_transition import ( @@ -18,7 +18,7 @@ from eth2spec.test.helpers.fork_transition import ( # PROPOSER_SLASHING # -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) @always_bls def test_transition_with_proposer_slashing_right_after_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ @@ -36,7 +36,7 @@ def test_transition_with_proposer_slashing_right_after_fork(state, fork_epoch, s ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) @always_bls def test_transition_with_proposer_slashing_right_before_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ @@ -59,7 +59,7 @@ def test_transition_with_proposer_slashing_right_before_fork(state, fork_epoch, # -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) @always_bls def test_transition_with_attester_slashing_right_after_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ @@ -77,7 +77,7 @@ def test_transition_with_attester_slashing_right_after_fork(state, fork_epoch, s ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) @always_bls def test_transition_with_attester_slashing_right_before_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ @@ -100,7 +100,7 @@ def test_transition_with_attester_slashing_right_before_fork(state, fork_epoch, # -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_deposit_right_after_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Create a deposit right *after* the transition @@ -117,7 +117,7 @@ def test_transition_with_deposit_right_after_fork(state, fork_epoch, spec, post_ ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_deposit_right_before_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Create a deposit right *before* the transition @@ -139,7 +139,7 @@ def test_transition_with_deposit_right_before_fork(state, fork_epoch, spec, post # -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=66) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=66) for pre, post in ALL_PRE_POST_FORKS]) @with_presets([MINIMAL], reason="too slow") def test_transition_with_voluntary_exit_right_after_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ @@ -161,7 +161,7 @@ def test_transition_with_voluntary_exit_right_after_fork(state, fork_epoch, spec ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=66) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=66) for pre, post in ALL_PRE_POST_FORKS]) @with_presets([MINIMAL], reason="too slow") def test_transition_with_voluntary_exit_right_before_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py index 6d8f23b7d..b3ba92321 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py @@ -5,7 +5,7 @@ from eth2spec.test.context import ( with_presets, ) from eth2spec.test.helpers.constants import ( - ALL_FORKS, + ALL_PRE_POST_FORKS, MINIMAL, ) from eth2spec.test.helpers.fork_transition import ( @@ -18,7 +18,7 @@ from eth2spec.test.helpers.random import ( ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=1) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=1) for pre, post in ALL_PRE_POST_FORKS]) @with_presets([MINIMAL], reason="only test with enough validators such that at least one exited index is not in sync committee") def test_transition_with_one_fourth_slashed_active_validators_pre_fork(state, diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py index 2439b79fc..2ac8bfb48 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py @@ -4,7 +4,7 @@ from eth2spec.test.context import ( with_fork_metas, ) from eth2spec.test.helpers.constants import ( - ALL_FORKS, + ALL_PRE_POST_FORKS, ) from eth2spec.test.helpers.state import ( next_epoch_via_signed_block, @@ -20,7 +20,7 @@ from eth2spec.test.helpers.fork_transition import ( ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_normal_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Transition from the initial ``state`` to the epoch after the ``fork_epoch``, @@ -56,7 +56,7 @@ def test_normal_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag yield "post", state -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_missing_first_post_block(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Transition from the initial ``state`` to the epoch after the ``fork_epoch``, @@ -93,7 +93,7 @@ def test_transition_missing_first_post_block(state, fork_epoch, spec, post_spec, yield "post", state -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_missing_last_pre_fork_block(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Transition from the initial ``state`` to the epoch after the ``fork_epoch``, @@ -132,7 +132,7 @@ def test_transition_missing_last_pre_fork_block(state, fork_epoch, spec, post_sp yield "post", state -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_only_blocks_post_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Transition from the initial ``state`` to the epoch after the ``fork_epoch``, @@ -258,7 +258,7 @@ def _run_transition_test_with_attestations(state, yield "post", state -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_finality(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Transition from the initial ``state`` to the epoch after the ``fork_epoch``, @@ -267,7 +267,7 @@ def test_transition_with_finality(state, fork_epoch, spec, post_spec, pre_tag, p yield from _run_transition_test_with_attestations(state, fork_epoch, spec, post_spec, pre_tag, post_tag) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_random_three_quarters_participation(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Transition from the initial ``state`` to the epoch after the ``fork_epoch``, @@ -294,7 +294,7 @@ def test_transition_with_random_three_quarters_participation(state, fork_epoch, ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_random_half_participation(state, fork_epoch, spec, post_spec, pre_tag, post_tag): rng = random.Random(2020) @@ -318,7 +318,7 @@ def test_transition_with_random_half_participation(state, fork_epoch, spec, post ) -@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_FORKS.items()]) +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=3) for pre, post in ALL_PRE_POST_FORKS]) def test_transition_with_no_attestations_until_after_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ Transition from the initial ``state`` to the ``fork_epoch`` with no attestations, diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index 3001946aa..04da8e653 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -11,7 +11,7 @@ from .exceptions import SkippedTest from .helpers.constants import ( PHASE0, ALTAIR, MERGE, MINIMAL, MAINNET, ALL_PHASES, FORKS_BEFORE_ALTAIR, FORKS_BEFORE_MERGE, - ALL_FORKS, + ALL_FORK_UPGRADES, ) from .helpers.typing import SpecForkName, PresetBaseName from .helpers.genesis import create_genesis_state @@ -432,7 +432,7 @@ def with_phases(phases, other_phases=None): # When running test generator, it sets specific `phase` phase = kw['phase'] _phases = [phase] - _other_phases = [ALL_FORKS[phase]] + _other_phases = [ALL_FORK_UPGRADES[phase]] ret = _run_test_case_with_phases(fn, _phases, _other_phases, kw, args, is_fork_transition=True) else: # When running pytest, go through `fork_metas` diff --git a/tests/core/pyspec/eth2spec/test/helpers/constants.py b/tests/core/pyspec/eth2spec/test/helpers/constants.py index 4b2f37b66..4f0f8bd6d 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/constants.py +++ b/tests/core/pyspec/eth2spec/test/helpers/constants.py @@ -21,11 +21,13 @@ TESTGEN_FORKS = (PHASE0, ALTAIR, MERGE) FORKS_BEFORE_ALTAIR = (PHASE0,) FORKS_BEFORE_MERGE = (PHASE0, ALTAIR) -ALL_FORKS = { +ALL_FORK_UPGRADES = { # pre_fork_name: post_fork_name PHASE0: ALTAIR, ALTAIR: MERGE, } +ALL_PRE_POST_FORKS = ALL_FORK_UPGRADES.items() + # # Config diff --git a/tests/generators/transition/main.py b/tests/generators/transition/main.py index 80aef8fec..de00e774a 100644 --- a/tests/generators/transition/main.py +++ b/tests/generators/transition/main.py @@ -3,7 +3,7 @@ from typing import Iterable from eth2spec.test.helpers.constants import ( MINIMAL, MAINNET, - ALL_FORKS, + ALL_FORK_UPGRADES, ) from eth2spec.gen_helpers.gen_base import gen_runner, gen_typing from eth2spec.gen_helpers.gen_from_tests.gen import ( @@ -45,7 +45,7 @@ if __name__ == "__main__": test_altair_operations, ) for transition_test_module in altair_tests: - for pre_fork, post_fork in ALL_FORKS.items(): + for pre_fork, post_fork in ALL_PRE_POST_FORKS: gen_runner.run_generator("transition", [ create_provider(transition_test_module, MINIMAL, pre_fork, post_fork), create_provider(transition_test_module, MAINNET, pre_fork, post_fork),