Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Oct 8, 2021
2 parents ceb17a7 + ac91155 commit 6ef79b1
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 50 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str]) ->
# NOTE: trim whitespace from spec
ssz_objects[current_name] = "\n".join(line.rstrip() for line in source.splitlines())
else:
raise Exception("unrecognized python code element")
raise Exception("unrecognized python code element: " + source)
elif isinstance(child, Table):
for row in child.children:
cells = row.children
Expand Down
2 changes: 1 addition & 1 deletion tests/core/pyspec/eth2spec/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.1.2
21 changes: 21 additions & 0 deletions tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,24 @@ def run_state_test_generators(runner_name: str,
preset_name=preset_name,
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
10 changes: 8 additions & 2 deletions tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
def run_sync_committee_sanity_test(spec, state, fraction_full=1.0, rng=Random(454545)):
all_pubkeys = [v.pubkey for v in state.validators]
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

block = build_empty_block_for_next_slot(spec, state)
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(
spec,
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@with_merge_and_later
@spec_state_test
def test_empty_block_transition(spec, state):
def test_empty_block_transition_no_tx(spec, state):
yield 'pre', state

block = build_empty_block_for_next_slot(spec, state)
Expand Down
17 changes: 8 additions & 9 deletions tests/generators/epoch_processing/main.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -15,14 +15,13 @@
'historical_roots_update',
'participation_record_updates',
]}
altair_mods = {
**{key: 'eth2spec.test.altair.epoch_processing.test_process_' + key for key in [
'inactivity_updates',
'participation_flag_updates',
'sync_committee_updates',
]},
**phase_0_mods,
} # also run the previous phase 0 tests

_new_altair_mods = {key: 'eth2spec.test.altair.epoch_processing.test_process_' + key for key in [
'inactivity_updates',
'participation_flag_updates',
'sync_committee_updates',
]}
altair_mods = combine_mods(_new_altair_mods, phase_0_mods)

# No epoch-processing changes in Merge and previous testing repeats with new types, so no additional tests required.
merge_mods = altair_mods
Expand Down
13 changes: 6 additions & 7 deletions tests/generators/fork_choice/main.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -9,14 +9,13 @@
]}
# No additional Altair specific finality tests, yet.
altair_mods = phase_0_mods

# 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
merge_mods = {
**{key: 'eth2spec.test.merge.fork_choice.test_' + key for key in [
'on_merge_block',
]},
**altair_mods,
}
_new_merge_mods = {key: 'eth2spec.test.merge.fork_choice.test_' + key for key in [
'on_merge_block',
]}
merge_mods = combine_mods(_new_merge_mods, altair_mods)

all_mods = {
PHASE0: phase_0_mods,
Expand Down
17 changes: 9 additions & 8 deletions tests/generators/genesis/main.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -7,14 +7,15 @@
'initialization',
'validity',
]}
altair_mods = phase_0_mods

# we have new unconditional lines in `initialize_beacon_state_from_eth1` and we want to test it
merge_mods = {
**{key: 'eth2spec.test.merge.genesis.test_' + key for key in [
'initialization',
]},
**altair_mods,
}
altair_mods = phase_0_mods

_new_merge_mods = {key: 'eth2spec.test.merge.genesis.test_' + key for key in [
'initialization',
]}
merge_mods = combine_mods(_new_merge_mods, altair_mods)

all_mods = {
PHASE0: phase_0_mods,
ALTAIR: altair_mods,
Expand Down
29 changes: 13 additions & 16 deletions tests/generators/operations/main.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -11,29 +11,26 @@
'proposer_slashing',
'voluntary_exit',
]}
altair_mods = {
**{'sync_aggregate': [
'eth2spec.test.altair.block_processing.sync_aggregate.test_process_' + key
for key in ['sync_aggregate', 'sync_aggregate_random']
]},
**phase_0_mods,
} # also run the previous phase 0 tests
_new_altair_mods = {'sync_aggregate': [
'eth2spec.test.altair.block_processing.sync_aggregate.test_process_' + key
for key in ['sync_aggregate', 'sync_aggregate_random']
]}
altair_mods = combine_mods(_new_altair_mods, phase_0_mods)

merge_mods = {
**{key: 'eth2spec.test.merge.block_processing.test_process_' + key for key in [
'execution_payload',
]},
**altair_mods,
}
_new_merge_mods = {key: 'eth2spec.test.merge.block_processing.test_process_' + key for key in [
'execution_payload',
]}
merge_mods = combine_mods(_new_merge_mods, altair_mods)

# 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',
# 'chunk_challenge',
# 'custody_key_reveal',
# 'custody_slashing',
# '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 = {
PHASE0: phase_0_mods,
Expand Down
14 changes: 9 additions & 5 deletions tests/generators/sanity/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
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__":
phase_0_mods = {key: 'eth2spec.test.phase0.sanity.test_' + key for key in [
'blocks',
'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',
]}, **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',
]}, **altair_mods}
]}
merge_mods = combine_mods(_new_merge_mods, altair_mods)

all_mods = {
PHASE0: phase_0_mods,
Expand Down

0 comments on commit 6ef79b1

Please sign in to comment.