From bb63af53c9d1acd66eb5ab13ace6bb3fb71d320c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 13 Apr 2021 23:21:40 +0800 Subject: [PATCH] Refactor genesis.py --- tests/core/pyspec/eth2spec/test/context.py | 8 +++----- tests/core/pyspec/eth2spec/test/helpers/constants.py | 4 +++- tests/core/pyspec/eth2spec/test/helpers/genesis.py | 12 +++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index 147793afe..438e611cf 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -7,8 +7,8 @@ from eth2spec.utils import bls from .exceptions import SkippedTest from .helpers.constants import ( - PHASE0, ALTAIR, MERGE, SHARDING, CUSTODY_GAME, DAS, - ALL_PHASES, + PHASE0, ALTAIR, + ALL_PHASES, FORKS_BEFORE_ALTAIR, ) from .helpers.genesis import create_genesis_state from .utils import vector_test, with_meta_tags @@ -362,8 +362,6 @@ def with_configs(configs, reason=None): def is_post_altair(spec): - # TODO: everything runs in parallel to Altair. - # After features are rebased on the Altair fork, this can be reduced to just PHASE0. - if spec.fork in [PHASE0, MERGE, SHARDING, CUSTODY_GAME, DAS]: + if spec.fork in FORKS_BEFORE_ALTAIR: return False return True diff --git a/tests/core/pyspec/eth2spec/test/helpers/constants.py b/tests/core/pyspec/eth2spec/test/helpers/constants.py index bffffe348..ccd7b20a2 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/constants.py +++ b/tests/core/pyspec/eth2spec/test/helpers/constants.py @@ -18,7 +18,9 @@ DAS = SpecForkName('das') ALL_PHASES = (PHASE0, ALTAIR) # The forks that output to the test vectors. TESTGEN_FORKS = (PHASE0, ALTAIR) - +# TODO: everything runs in parallel to Altair. +# After features are rebased on the Altair fork, this can be reduced to just PHASE0. +FORKS_BEFORE_ALTAIR = (PHASE0, MERGE, SHARDING, CUSTODY_GAME, DAS) # # Config diff --git a/tests/core/pyspec/eth2spec/test/helpers/genesis.py b/tests/core/pyspec/eth2spec/test/helpers/genesis.py index 5f2cd5281..49af43ec1 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/genesis.py +++ b/tests/core/pyspec/eth2spec/test/helpers/genesis.py @@ -1,3 +1,7 @@ +from eth2spec.test.helpers.constants import ( + ALTAIR, + FORKS_BEFORE_ALTAIR, +) from eth2spec.test.helpers.keys import pubkeys @@ -21,8 +25,10 @@ def create_genesis_state(spec, validator_balances, activation_threshold): eth1_block_hash = b'\xda' * 32 current_version = spec.GENESIS_FORK_VERSION - if spec.fork == 'altair': # TODO: fix `context.py` dependency + + if spec.fork == ALTAIR: current_version = spec.ALTAIR_FORK_VERSION + state = spec.BeaconState( genesis_time=0, eth1_deposit_index=len(validator_balances), @@ -50,7 +56,7 @@ def create_genesis_state(spec, validator_balances, activation_threshold): if validator.effective_balance >= activation_threshold: validator.activation_eligibility_epoch = spec.GENESIS_EPOCH validator.activation_epoch = spec.GENESIS_EPOCH - if spec.fork != 'phase0': # TODO: fix `context.py` dependency + if spec.fork not in FORKS_BEFORE_ALTAIR: state.previous_epoch_participation.append(spec.ParticipationFlags(0b0000_0000)) state.current_epoch_participation.append(spec.ParticipationFlags(0b0000_0000)) state.inactivity_scores.append(spec.uint64(0)) @@ -58,7 +64,7 @@ def create_genesis_state(spec, validator_balances, activation_threshold): # Set genesis validators root for domain separation and chain versioning state.genesis_validators_root = spec.hash_tree_root(state.validators) - if spec.fork != 'phase0': # TODO: fix `context.py` dependency + if spec.fork not in FORKS_BEFORE_ALTAIR: # Fill in sync committees state.current_sync_committee = spec.get_sync_committee(state, spec.get_current_epoch(state)) state.next_sync_committee = (