Merge pull request #2651 from ethereum/fix-testgen-key
Fix test generator duplicate key issue
This commit is contained in:
commit
4b5d0c96b9
|
@ -109,3 +109,24 @@ def run_state_test_generators(runner_name: str,
|
||||||
preset_name=preset_name,
|
preset_name=preset_name,
|
||||||
all_mods=all_mods,
|
all_mods=all_mods,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
def combine_mods(dict_1, dict_2):
|
||||||
|
"""
|
||||||
|
Return the merged dicts, where the result value would be a list of the values from two dicts.
|
||||||
|
"""
|
||||||
|
# The duplicate dict_1 items would be ignored here.
|
||||||
|
dict_3 = {**dict_1, **dict_2}
|
||||||
|
|
||||||
|
intersection = dict_1.keys() & dict_2.keys()
|
||||||
|
for key in intersection:
|
||||||
|
# To list
|
||||||
|
if not isinstance(dict_3[key], List):
|
||||||
|
dict_3[key] = [dict_3[key]]
|
||||||
|
# Append dict_1 value to list
|
||||||
|
if isinstance(dict_1[key], List):
|
||||||
|
dict_3[key] += dict_1[key]
|
||||||
|
else:
|
||||||
|
dict_3[key].append(dict_1[key])
|
||||||
|
|
||||||
|
return dict_3
|
||||||
|
|
|
@ -23,13 +23,19 @@ from eth2spec.test.helpers.inactivity_scores import randomize_inactivity_scores
|
||||||
def run_sync_committee_sanity_test(spec, state, fraction_full=1.0, rng=Random(454545)):
|
def run_sync_committee_sanity_test(spec, state, fraction_full=1.0, rng=Random(454545)):
|
||||||
all_pubkeys = [v.pubkey for v in state.validators]
|
all_pubkeys = [v.pubkey for v in state.validators]
|
||||||
committee = [all_pubkeys.index(pubkey) for pubkey in state.current_sync_committee.pubkeys]
|
committee = [all_pubkeys.index(pubkey) for pubkey in state.current_sync_committee.pubkeys]
|
||||||
participants = rng.sample(committee, int(len(committee) * fraction_full))
|
selected_indices = rng.sample(range(len(committee)), int(len(committee) * fraction_full))
|
||||||
|
sync_committee_bits = [i in selected_indices for i in range(len(committee))]
|
||||||
|
participants = [
|
||||||
|
validator_index
|
||||||
|
for i, validator_index in enumerate(committee)
|
||||||
|
if sync_committee_bits[i]
|
||||||
|
]
|
||||||
|
|
||||||
yield 'pre', state
|
yield 'pre', state
|
||||||
|
|
||||||
block = build_empty_block_for_next_slot(spec, state)
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
block.body.sync_aggregate = spec.SyncAggregate(
|
block.body.sync_aggregate = spec.SyncAggregate(
|
||||||
sync_committee_bits=[index in participants for index in committee],
|
sync_committee_bits=sync_committee_bits,
|
||||||
sync_committee_signature=compute_aggregate_sync_committee_signature(
|
sync_committee_signature=compute_aggregate_sync_committee_signature(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
|
|
|
@ -11,7 +11,7 @@ from eth2spec.test.context import (
|
||||||
|
|
||||||
@with_merge_and_later
|
@with_merge_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_empty_block_transition(spec, state):
|
def test_empty_block_transition_no_tx(spec, state):
|
||||||
yield 'pre', state
|
yield 'pre', state
|
||||||
|
|
||||||
block = build_empty_block_for_next_slot(spec, state)
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators
|
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators, combine_mods
|
||||||
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,14 +15,13 @@ if __name__ == "__main__":
|
||||||
'historical_roots_update',
|
'historical_roots_update',
|
||||||
'participation_record_updates',
|
'participation_record_updates',
|
||||||
]}
|
]}
|
||||||
altair_mods = {
|
|
||||||
**{key: 'eth2spec.test.altair.epoch_processing.test_process_' + key for key in [
|
_new_altair_mods = {key: 'eth2spec.test.altair.epoch_processing.test_process_' + key for key in [
|
||||||
'inactivity_updates',
|
'inactivity_updates',
|
||||||
'participation_flag_updates',
|
'participation_flag_updates',
|
||||||
'sync_committee_updates',
|
'sync_committee_updates',
|
||||||
]},
|
]},
|
||||||
**phase_0_mods,
|
altair_mods = combine_mods(_new_altair_mods, phase_0_mods)
|
||||||
} # also run the previous phase 0 tests
|
|
||||||
|
|
||||||
# No epoch-processing changes in Merge and previous testing repeats with new types, so no additional tests required.
|
# No epoch-processing changes in Merge and previous testing repeats with new types, so no additional tests required.
|
||||||
merge_mods = altair_mods
|
merge_mods = altair_mods
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators
|
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators, combine_mods
|
||||||
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,14 +9,13 @@ if __name__ == "__main__":
|
||||||
]}
|
]}
|
||||||
# No additional Altair specific finality tests, yet.
|
# No additional Altair specific finality tests, yet.
|
||||||
altair_mods = phase_0_mods
|
altair_mods = phase_0_mods
|
||||||
|
|
||||||
# For merge `on_merge_block` test kind added with `pow_block_N.ssz` files with several
|
# For merge `on_merge_block` test kind added with `pow_block_N.ssz` files with several
|
||||||
# PowBlock's which should be resolved by `get_pow_block(hash: Hash32) -> PowBlock` function
|
# PowBlock's which should be resolved by `get_pow_block(hash: Hash32) -> PowBlock` function
|
||||||
merge_mods = {
|
_new_merge_mods = {key: 'eth2spec.test.merge.fork_choice.test_' + key for key in [
|
||||||
**{key: 'eth2spec.test.merge.fork_choice.test_' + key for key in [
|
'on_merge_block',
|
||||||
'on_merge_block',
|
]},
|
||||||
]},
|
merge_mods = combine_mods(_new_merge_mods, altair_mods)
|
||||||
**altair_mods,
|
|
||||||
}
|
|
||||||
|
|
||||||
all_mods = {
|
all_mods = {
|
||||||
PHASE0: phase_0_mods,
|
PHASE0: phase_0_mods,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators
|
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators, combine_mods
|
||||||
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,14 +7,15 @@ if __name__ == "__main__":
|
||||||
'initialization',
|
'initialization',
|
||||||
'validity',
|
'validity',
|
||||||
]}
|
]}
|
||||||
altair_mods = phase_0_mods
|
|
||||||
# we have new unconditional lines in `initialize_beacon_state_from_eth1` and we want to test it
|
# we have new unconditional lines in `initialize_beacon_state_from_eth1` and we want to test it
|
||||||
merge_mods = {
|
altair_mods = phase_0_mods
|
||||||
**{key: 'eth2spec.test.merge.genesis.test_' + key for key in [
|
|
||||||
'initialization',
|
_new_merge_mods = {key: 'eth2spec.test.merge.genesis.test_' + key for key in [
|
||||||
]},
|
'initialization',
|
||||||
**altair_mods,
|
]}
|
||||||
}
|
merge_mods = combine_mods(_new_merge_mods, altair_mods)
|
||||||
|
|
||||||
all_mods = {
|
all_mods = {
|
||||||
PHASE0: phase_0_mods,
|
PHASE0: phase_0_mods,
|
||||||
ALTAIR: altair_mods,
|
ALTAIR: altair_mods,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators
|
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators, combine_mods
|
||||||
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,29 +11,26 @@ if __name__ == "__main__":
|
||||||
'proposer_slashing',
|
'proposer_slashing',
|
||||||
'voluntary_exit',
|
'voluntary_exit',
|
||||||
]}
|
]}
|
||||||
altair_mods = {
|
_new_altair_mods = {'sync_aggregate': [
|
||||||
**{'sync_aggregate': [
|
'eth2spec.test.altair.block_processing.sync_aggregate.test_process_' + key
|
||||||
'eth2spec.test.altair.block_processing.sync_aggregate.test_process_' + key
|
for key in ['sync_aggregate', 'sync_aggregate_random']
|
||||||
for key in ['sync_aggregate', 'sync_aggregate_random']
|
]}
|
||||||
]},
|
altair_mods = combine_mods(_new_altair_mods, phase_0_mods)
|
||||||
**phase_0_mods,
|
|
||||||
} # also run the previous phase 0 tests
|
|
||||||
|
|
||||||
merge_mods = {
|
_new_merge_mods = {key: 'eth2spec.test.merge.block_processing.test_process_' + key for key in [
|
||||||
**{key: 'eth2spec.test.merge.block_processing.test_process_' + key for key in [
|
'execution_payload',
|
||||||
'execution_payload',
|
]}
|
||||||
]},
|
merge_mods = combine_mods(_new_merge_mods, altair_mods)
|
||||||
**altair_mods,
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO Custody Game testgen is disabled for now
|
# TODO Custody Game testgen is disabled for now
|
||||||
# custody_game_mods = {**{key: 'eth2spec.test.custody_game.block_processing.test_process_' + key for key in [
|
# _new_custody_game_mods = {key: 'eth2spec.test.custody_game.block_processing.test_process_' + key for key in [
|
||||||
# 'attestation',
|
# 'attestation',
|
||||||
# 'chunk_challenge',
|
# 'chunk_challenge',
|
||||||
# 'custody_key_reveal',
|
# 'custody_key_reveal',
|
||||||
# 'custody_slashing',
|
# 'custody_slashing',
|
||||||
# 'early_derived_secret_reveal',
|
# 'early_derived_secret_reveal',
|
||||||
# ]}, **phase_0_mods} # also run the previous phase 0 tests (but against custody game spec)
|
# ]}
|
||||||
|
# custody_game_mods = combine_mods(_new_custody_game_mods, phase0_mods)
|
||||||
|
|
||||||
all_mods = {
|
all_mods = {
|
||||||
PHASE0: phase_0_mods,
|
PHASE0: phase_0_mods,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE
|
||||||
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators
|
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators, combine_mods
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -7,12 +7,16 @@ if __name__ == "__main__":
|
||||||
'blocks',
|
'blocks',
|
||||||
'slots',
|
'slots',
|
||||||
]}
|
]}
|
||||||
altair_mods = {**{key: 'eth2spec.test.altair.sanity.test_' + key for key in [
|
|
||||||
|
_new_altair_mods = {key: 'eth2spec.test.altair.sanity.test_' + key for key in [
|
||||||
'blocks',
|
'blocks',
|
||||||
]}, **phase_0_mods}
|
]}
|
||||||
merge_mods = {**{key: 'eth2spec.test.merge.sanity.test_' + key for key in [
|
altair_mods = combine_mods(_new_altair_mods, phase_0_mods)
|
||||||
|
|
||||||
|
_new_merge_mods = {key: 'eth2spec.test.merge.sanity.test_' + key for key in [
|
||||||
'blocks',
|
'blocks',
|
||||||
]}, **altair_mods}
|
]}
|
||||||
|
merge_mods = combine_mods(_new_merge_mods, altair_mods)
|
||||||
|
|
||||||
all_mods = {
|
all_mods = {
|
||||||
PHASE0: phase_0_mods,
|
PHASE0: phase_0_mods,
|
||||||
|
|
Loading…
Reference in New Issue