From 63ca480ea3f36f80e9f542a29262bc8e6ed3ef5d Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 14 Jul 2021 20:02:21 +0800 Subject: [PATCH 001/122] Add condition check in `on_tick` to ensure that `store.justified_checkpoint` is a descendant of `store.finalized_checkpoint` --- specs/phase0/fork-choice.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/specs/phase0/fork-choice.md b/specs/phase0/fork-choice.md index 181a874fb..d4a3a9b85 100644 --- a/specs/phase0/fork-choice.md +++ b/specs/phase0/fork-choice.md @@ -327,9 +327,13 @@ def on_tick(store: Store, time: uint64) -> None: # Not a new epoch, return if not (current_slot > previous_slot and compute_slots_since_epoch_start(current_slot) == 0): return - # Update store.justified_checkpoint if a better checkpoint is known + + # Update store.justified_checkpoint if a better checkpoint on the store.finalized_checkpoint chain if store.best_justified_checkpoint.epoch > store.justified_checkpoint.epoch: - store.justified_checkpoint = store.best_justified_checkpoint + finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + ancestor_at_finalized_slot = get_ancestor(store, store.best_justified_checkpoint.root, finalized_slot) + if ancestor_at_finalized_slot == store.finalized_checkpoint.root: + store.justified_checkpoint = store.best_justified_checkpoint ``` #### `on_block` From cc3690ce3899cfe22a4d44890d63739f3aed093f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 14 Jul 2021 20:05:14 +0800 Subject: [PATCH 002/122] Add unit tests to test the new condition. --- .../unittests/fork_choice/test_on_tick.py | 98 +++++++++++++++++-- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py b/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py index ef643fd6b..40606197e 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py +++ b/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py @@ -1,5 +1,13 @@ from eth2spec.test.context import with_all_phases, spec_state_test from eth2spec.test.helpers.fork_choice import get_genesis_forkchoice_store +from eth2spec.test.helpers.block import ( + build_empty_block_for_next_slot, +) +from eth2spec.test.helpers.state import ( + next_epoch, + state_transition_and_sign_block, + transition_to, +) def run_on_tick(spec, store, time, new_justified_checkpoint=False): @@ -26,18 +34,92 @@ def test_basic(spec, state): @with_all_phases @spec_state_test -def test_update_justified_single(spec, state): +def test_update_justified_single_on_store_finalized_chain(spec, state): store = get_genesis_forkchoice_store(spec, state) - next_epoch = spec.get_current_epoch(state) + 1 - next_epoch_start_slot = spec.compute_start_slot_at_epoch(next_epoch) - seconds_until_next_epoch = next_epoch_start_slot * spec.config.SECONDS_PER_SLOT - store.time - store.best_justified_checkpoint = spec.Checkpoint( - epoch=store.justified_checkpoint.epoch + 1, - root=b'\x55' * 32, + # [Mock store.best_justified_checkpoint] + # Create a block at epoch 1 + next_epoch(spec, state) + block = build_empty_block_for_next_slot(spec, state) + state_transition_and_sign_block(spec, state, block) + store.blocks[block.hash_tree_root()] = block.copy() + store.block_states[block.hash_tree_root()] = state.copy() + parent_block = block.copy() + # To make compute_slots_since_epoch_start(current_slot) == 0, transition to the end of the epoch + slot = state.slot + spec.SLOTS_PER_EPOCH - (state.slot + spec.SLOTS_PER_EPOCH) % spec.SLOTS_PER_EPOCH - 1 + transition_to(spec, state, slot) + # Create a block at the start of epoch 2 + block = build_empty_block_for_next_slot(spec, state) + # Mock state + state.current_justified_checkpoint = spec.Checkpoint( + epoch=spec.compute_epoch_at_slot(parent_block.slot), + root=parent_block.hash_tree_root(), + ) + state_transition_and_sign_block(spec, state, block) + store.blocks[block.hash_tree_root()] = block + store.block_states[block.hash_tree_root()] = state + # Mock store.best_justified_checkpoint + store.best_justified_checkpoint = state.current_justified_checkpoint.copy() + + run_on_tick( + spec, + store, + store.genesis_time + state.slot * spec.config.SECONDS_PER_SLOT, + new_justified_checkpoint=True ) - run_on_tick(spec, store, store.time + seconds_until_next_epoch, True) + +@with_all_phases +@spec_state_test +def test_update_justified_single_not_on_store_finalized_chain(spec, state): + store = get_genesis_forkchoice_store(spec, state) + init_state = state.copy() + + # Chain grows + # Create a block at epoch 1 + next_epoch(spec, state) + block = build_empty_block_for_next_slot(spec, state) + block.body.graffiti = b'\x11' * 32 + state_transition_and_sign_block(spec, state, block) + store.blocks[block.hash_tree_root()] = block.copy() + store.block_states[block.hash_tree_root()] = state.copy() + # Mock store.finalized_checkpoint + store.finalized_checkpoint = spec.Checkpoint( + epoch=spec.compute_epoch_at_slot(block.slot), + root=block.hash_tree_root(), + ) + + # [Mock store.best_justified_checkpoint] + # Create a block at epoch 1 + state = init_state.copy() + next_epoch(spec, state) + block = build_empty_block_for_next_slot(spec, state) + block.body.graffiti = b'\x22' * 32 + state_transition_and_sign_block(spec, state, block) + store.blocks[block.hash_tree_root()] = block.copy() + store.block_states[block.hash_tree_root()] = state.copy() + parent_block = block.copy() + # To make compute_slots_since_epoch_start(current_slot) == 0, transition to the end of the epoch + slot = state.slot + spec.SLOTS_PER_EPOCH - (state.slot + spec.SLOTS_PER_EPOCH) % spec.SLOTS_PER_EPOCH - 1 + transition_to(spec, state, slot) + # Create a block at the start of epoch 2 + block = build_empty_block_for_next_slot(spec, state) + # Mock state + state.current_justified_checkpoint = spec.Checkpoint( + epoch=spec.compute_epoch_at_slot(parent_block.slot), + root=parent_block.hash_tree_root(), + ) + state_transition_and_sign_block(spec, state, block) + store.blocks[block.hash_tree_root()] = block.copy() + store.block_states[block.hash_tree_root()] = state.copy() + # Mock store.best_justified_checkpoint + store.best_justified_checkpoint = state.current_justified_checkpoint.copy() + + run_on_tick( + spec, + store, + store.genesis_time + state.slot * spec.config.SECONDS_PER_SLOT, + ) @with_all_phases From eadefa274d2fac1840e14ae7f0c07a75b5941fb6 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 19 Aug 2021 12:54:21 -0600 Subject: [PATCH 003/122] WIP: broad-spectrum randomized block tests --- .../test/phase0/sanity/test_blocks_random.py | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py new file mode 100644 index 000000000..ffc37c7c2 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -0,0 +1,67 @@ +from eth2spec.test.helpers.state import ( + next_epoch, + next_slot, +) +from eth2spec.test.context import ( + with_all_phases, + spec_state_test, +) + + +def generate_randomized_scenarios(): + # TODO: WIP schema + return { + # ("randomize_state", "ensure all validator states present: pending/deposited, activated, exited, slashed"), + # ("randomized balances", "ensure distribution of bals"), + # ("transition to leak if not already, maybe", "assert is or is not leaking"), + "setup": [], + "epochs_to_skip": 0, # 0, 1, 2, N, EPOCHS_TO_INACTIVITY_LEAK, + "slots_to_skip": 0, # 0, 1, 2, N, SLOTS_PER_EPOCH - 1, + "transitions": [ # TODO: consider large numbers of blocks, load on generated data + { + "block_producer": lambda spec, state: spec.SignedBeaconBlock(), + "epochs_to_skip": 0, # 0, 1, 2, N, EPOCHS_TO_INACTIVITY_LEAK, + "slots_to_skip": 0, # 0, 1, 2, N, SLOTS_PER_EPOCH - 1, + } + ], + } + + +def id_from_scenario(test_description): + return '-'.join(':'.join((str(k),str(v))) for k,v in test_description.items()) + + +def pytest_generate_tests(metafunc): + """ + Pytest hook to generate test cases from dynamically computed data + """ + generated_name = "test_description" + generated_values = generate_randomized_scenarios() + metafunc.parametrize(generated_name, generated_values, ids=id_from_scenario, scope="module") + + +def pytest_generate_tests_adapter(f): + """ + Adapter decorator to allow dynamic test case generation + while leveraging existing decorators specific to spec tests. + """ + def wrapper(test_description, *args, **kwargs): + kwargs["test_description"] = test_description + f(*args, **kwargs) + return wrapper + + +@pytest_generate_tests_adapter +@with_all_phases +@spec_state_test +def test_harness_for_randomized_blocks(spec, state, test_description): + for mutation, validation in test_description["setup"]: + mutation(spec, state) + validation(spec, state) + for _ in range(len(test_description["epochs_to_skip"])): + next_epoch(spec, state) + for _ in range(len(test_description["slots_to_skip"])): + next_slot(spec, state) + for transition in test_description["transitions"]: + # TODO apply transition + pass From 00df808f59e6212ffc28d46fe39f99b63ed7253b Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 20 Aug 2021 13:35:23 -0600 Subject: [PATCH 004/122] expose functionality to make random block --- .../eth2spec/test/helpers/multi_operations.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 4b6c9b25d..dc64882b8 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -125,10 +125,7 @@ def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): return prepare_signed_exits(spec, state, exit_indices) -def run_test_full_random_operations(spec, state, rng=Random(2080)): - # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit - state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - +def build_random_block_from_state(spec, state, rng=Random(2188)): # prepare state for deposits before building block deposits = prepare_state_and_get_random_deposits(spec, state, rng) @@ -148,6 +145,15 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): slashed_indices = slashed_indices.union(attester_slashing.attestation_2.attesting_indices) block.body.voluntary_exits = get_random_voluntary_exits(spec, state, slashed_indices, rng) + return block + + +def run_test_full_random_operations(spec, state, rng=Random(2080)): + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + block = build_random_block_from_state(spec, state, rng) + yield 'pre', state signed_block = state_transition_and_sign_block(spec, state, block) From 4420d1381666a405b82429e76a50ffb513eb9ea1 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 20 Aug 2021 13:35:42 -0600 Subject: [PATCH 005/122] add helper to check existence of many validator types --- .../pyspec/eth2spec/test/helpers/state.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index 666023fec..b4c9e1d67 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -1,5 +1,6 @@ from eth2spec.test.context import expect_assertion_error, is_post_altair from eth2spec.test.helpers.block import apply_empty_block, sign_block, transition_unsigned_block +from eth2spec.test.helpers.voluntary_exits import get_exited_validators def get_balance(state, index): @@ -133,3 +134,24 @@ def _set_empty_participation(spec, state, current=True, previous=True): def set_empty_participation(spec, state, rng=None): _set_empty_participation(spec, state) + + +def ensure_state_has_validators_across_lifecycle(spec, state): + """ + Scan the validator registry to ensure there is at least 1 validator + for each of the following lifecycle states: + 1. Pending / deposited + 2. Active + 3. Exited + 4. Slashed + """ + has_pending = any(filter(spec.is_eligible_for_activation_queue, state.validators)) + + current_epoch = spec.get_current_epoch(state) + has_active = any(filter(lambda v: spec.is_active_validator(v, current_epoch), state.validators)) + + has_exited = any(get_exited_validators(spec, state)) + + has_slashed = any(filter(lambda v: v.slashed, state.validators)) + + return has_pending and has_active and has_exited and has_slashed From 619e82889881354e1fef8b43e0f683b4c9f3105e Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 20 Aug 2021 13:57:26 -0600 Subject: [PATCH 006/122] Progress on block test gen --- .../test/phase0/sanity/test_blocks_random.py | 290 ++++++++++++++++-- 1 file changed, 263 insertions(+), 27 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index ffc37c7c2..9b10ab355 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,34 +1,240 @@ +import itertools +from random import Random +from typing import Callable +from tests.core.pyspec.eth2spec.test.context import default_activation_threshold +from eth2spec.test.helpers.multi_operations import ( + build_random_block_from_state, +) from eth2spec.test.helpers.state import ( next_epoch, next_slot, + ensure_state_has_validators_across_lifecycle, + state_transition_and_sign_block, +) +from eth2spec.test.helpers.random import ( + randomize_state, ) from eth2spec.test.context import ( with_all_phases, - spec_state_test, + always_bls, + spec_test, + with_custom_state, + default_activation_threshold, + single_phase, + misc_balances, ) +# primitives +## epochs -def generate_randomized_scenarios(): - # TODO: WIP schema +def _epochs_until_leak(spec): + return spec.MIN_EPOCHS_TO_INACTIVITY_PENALTY + + +def _epochs_for_shard_committee_period(spec): + return spec.config.SHARD_COMMITTEE_PERIOD + + +## slots + +def _last_slot_in_epoch(spec): + return spec.SLOTS_PER_EPOCH - 1 + + +def _random_slot_in_epoch(rng): + def f(spec): + return rng.randrange(1, spec.SLOTS_PER_EPOCH - 2) + return f + + +def _penultimate_slot_in_epoch(spec): + return spec.SLOTS_PER_EPOCH - 2 + + +## blocks + +def _no_block(_spec, _pre_state, _signed_blocks): + return None + + +def _random_block_for_next_slot(spec, pre_state, _signed_blocks): + return build_random_block_from_state(spec, pre_state) + + +## validations + +def _no_op_validation(spec, state): + return True + + +def _validate_is_leaking(spec, state): + return spec.is_in_inactivity_leak(state) + + +# transitions + +def _no_op_transition(): + return {} + + +def _epoch_transition(n=0): return { - # ("randomize_state", "ensure all validator states present: pending/deposited, activated, exited, slashed"), - # ("randomized balances", "ensure distribution of bals"), - # ("transition to leak if not already, maybe", "assert is or is not leaking"), - "setup": [], - "epochs_to_skip": 0, # 0, 1, 2, N, EPOCHS_TO_INACTIVITY_LEAK, - "slots_to_skip": 0, # 0, 1, 2, N, SLOTS_PER_EPOCH - 1, - "transitions": [ # TODO: consider large numbers of blocks, load on generated data - { - "block_producer": lambda spec, state: spec.SignedBeaconBlock(), - "epochs_to_skip": 0, # 0, 1, 2, N, EPOCHS_TO_INACTIVITY_LEAK, - "slots_to_skip": 0, # 0, 1, 2, N, SLOTS_PER_EPOCH - 1, - } - ], + "epochs_to_skip": n, } -def id_from_scenario(test_description): - return '-'.join(':'.join((str(k),str(v))) for k,v in test_description.items()) +def _slot_transition(n=0): + return { + "slots_to_skip": n, + } + + +def _transition_to_leaking(): + return { + "epochs_to_skip": _epochs_until_leak, + "validation": _validate_is_leaking, + } + + +## block transitions + +def _transition_with_random_block(epochs=None, slots=None): + """ + Build a block transition with randomized data. + Provide optional sub-transitions to advance some + number of epochs or slots before applying the random block. + """ + transition = { + "block_producer": _random_block_for_next_slot, + } + if epochs: + transition.update(epochs) + if slots: + transition.update(slots) + return transition + + +# setup and test gen + +def _randomized_scenario_setup(): + """ + Return a sequence of pairs of ("mutator", "validator"), + a function that accepts (spec, state) arguments and performs some change + and a function that accepts (spec, state) arguments and validates some change was made. + """ + def _skip_epochs(epoch_producer): + def f(spec, state): + """ + The unoptimized spec implementation is too slow to advance via ``next_epoch``. + Instead, just overwrite the ``state.slot`` and continue... + """ + epochs_to_skip = epoch_producer(spec) + slots_to_skip = epochs_to_skip * spec.SLOTS_PER_EPOCH + state.slot += slots_to_skip + return f + + return ( + # NOTE: the block randomization function assumes at least 1 shard committee period + # so advance the state before doing anything else. + (_skip_epochs(_epochs_for_shard_committee_period), _no_op_validation), + (randomize_state, ensure_state_has_validators_across_lifecycle), + ) + + +def _normalize_transition(transition): + """ + Provide "empty" or "no op" sub-transitions + to a given transition. + """ + if isinstance(transition, Callable): + transition = transition() + if "epochs_to_skip" not in transition: + transition["epochs_to_skip"] = 0 + if "slots_to_skip" not in transition: + transition["slots_to_skip"] = 0 + if "block_producer" not in transition: + transition["block_producer"] = _no_block + if "validation" not in transition: + transition["validation"] = _no_op_validation + return transition + + +def _normalize_scenarios(scenarios): + """ + "Normalize" a "scenario" so that a producer of a test case + does not need to provide every expected key/value. + """ + for scenario in scenarios: + if "setup" not in scenario: + scenario["setup"] = _randomized_scenario_setup() + + transitions = scenario["transitions"] + for i, transition in enumerate(transitions): + transitions[i] = _normalize_transition(transition) + + +def _generate_randomized_scenarios(): + """ + Generates a set of randomized testing scenarios. + Return a sequence of "scenarios" where each scenario: + 1. Provides some setup + 2. Provides a sequence of transitions that mutate the state in some way, + possibly yielding blocks along the way + NOTE: scenarios are "normalized" with empty/no-op elements before returning + to the test generation to facilitate brevity when writing scenarios by hand. + NOTE: the main block driver builds a block for the **next** slot, so + the slot transitions are offset by -1 to target certain boundaries. + """ + rng = Random(1336) + leak_transitions = (_no_op_transition, _transition_to_leaking) + + # go forward 0 or 1 epochs + epochs_set = (_epoch_transition(n=0), _epoch_transition(n=1)) + # within those epochs, go forward to: + slots_set = ( + # the first slot in an epoch (see note in docstring about offsets...) + _slot_transition(_last_slot_in_epoch), + # the second slot in an epoch + _slot_transition(n=0), + # some random number of slots, but not at epoch boundaries + _slot_transition(_random_slot_in_epoch(rng)), + # the last slot in an epoch (see note in docstring about offsets...) + _slot_transition(_penultimate_slot_in_epoch), + ) + # build a set of block transitions from combinations of sub-transitions + block_transitions = list( + _transition_with_random_block(epochs=epochs, slots=slots) + for epochs, slots in itertools.product(epochs_set, slots_set) + ) + + # and preface each block transition with the possible leak transitions + # (... either no leak or transition to a leak before applying the block transition) + scenarios = [ + {"transitions": list(t)} + for t in itertools.product(leak_transitions, block_transitions) + ] + _normalize_scenarios(scenarios) + return scenarios + + +def _id_from_scenario(test_description): + """ + Construct a test name for ``pytest`` infra. + """ + def _to_id_part(prefix, x): + suffix = str(x) + if isinstance(x, Callable): + suffix = x.__name__ + return f"{prefix}{suffix}" + + def _id_from_transition(transition): + return ",".join(( + _to_id_part("epochs:", transition["epochs_to_skip"]), + _to_id_part("slots:", transition["slots_to_skip"]), + _to_id_part("with-block:", transition["block_producer"]) + )) + + return "|".join(map(_id_from_transition, test_description["transitions"])) def pytest_generate_tests(metafunc): @@ -36,8 +242,8 @@ def pytest_generate_tests(metafunc): Pytest hook to generate test cases from dynamically computed data """ generated_name = "test_description" - generated_values = generate_randomized_scenarios() - metafunc.parametrize(generated_name, generated_values, ids=id_from_scenario, scope="module") + generated_values = _generate_randomized_scenarios() + metafunc.parametrize(generated_name, generated_values, ids=_id_from_scenario, scope="module") def pytest_generate_tests_adapter(f): @@ -51,17 +257,47 @@ def pytest_generate_tests_adapter(f): return wrapper +def _iter_temporal(spec, callable_or_int): + """ + Intended to advance some number of {epochs, slots}. + Caller can provide a constant integer or a callable deriving a number from + the ``spec`` under consideration. + """ + numeric = callable_or_int + if isinstance(callable_or_int, Callable): + numeric = callable_or_int(spec) + for i in range(numeric): + yield i + + @pytest_generate_tests_adapter @with_all_phases -@spec_state_test +@with_custom_state(balances_fn=misc_balances, threshold_fn=default_activation_threshold) +@spec_test +@single_phase +@always_bls def test_harness_for_randomized_blocks(spec, state, test_description): for mutation, validation in test_description["setup"]: mutation(spec, state) validation(spec, state) - for _ in range(len(test_description["epochs_to_skip"])): - next_epoch(spec, state) - for _ in range(len(test_description["slots_to_skip"])): - next_slot(spec, state) + + yield "pre", state + + blocks = [] for transition in test_description["transitions"]: - # TODO apply transition - pass + epochs_to_skip = _iter_temporal(spec, transition["epochs_to_skip"]) + for _ in epochs_to_skip: + next_epoch(spec, state) + slots_to_skip = _iter_temporal(spec, transition["slots_to_skip"]) + for _ in slots_to_skip: + next_slot(spec, state) + + block = transition["block_producer"](spec, state, blocks) + if block: + signed_block = state_transition_and_sign_block(spec, state, block) + blocks.append(signed_block) + + assert transition["validation"](spec, state) + + yield "blocks", blocks + yield "post", state From 92aabcd207c7564668ce70e04217d43cdd10c1e6 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 20 Aug 2021 18:49:04 -0600 Subject: [PATCH 007/122] add randomized block tests to test generator --- tests/generators/sanity/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/generators/sanity/main.py b/tests/generators/sanity/main.py index 8caedc8e5..63efa3897 100644 --- a/tests/generators/sanity/main.py +++ b/tests/generators/sanity/main.py @@ -5,6 +5,7 @@ from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators if __name__ == "__main__": phase_0_mods = {key: 'eth2spec.test.phase0.sanity.test_' + key for key in [ 'blocks', + 'blocks_random', 'slots', ]} altair_mods = {**{key: 'eth2spec.test.altair.sanity.test_' + key for key in [ From 5094193f9ab4c751a439b4c2de4763f65b17e3f1 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 16:59:02 -0700 Subject: [PATCH 008/122] formatting --- .../pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 9b10ab355..8767ad12c 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -186,7 +186,6 @@ def _generate_randomized_scenarios(): the slot transitions are offset by -1 to target certain boundaries. """ rng = Random(1336) - leak_transitions = (_no_op_transition, _transition_to_leaking) # go forward 0 or 1 epochs epochs_set = (_epoch_transition(n=0), _epoch_transition(n=1)) @@ -209,6 +208,7 @@ def _generate_randomized_scenarios(): # and preface each block transition with the possible leak transitions # (... either no leak or transition to a leak before applying the block transition) + leak_transitions = (_no_op_transition, _transition_to_leaking) scenarios = [ {"transitions": list(t)} for t in itertools.product(leak_transitions, block_transitions) From 6da2c7a91671868b6c3bdcc0daf1482d07a1b153 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 16:59:54 -0700 Subject: [PATCH 009/122] ensure all validators in randomized test are active --- tests/core/pyspec/eth2spec/test/context.py | 15 +++++++++++++++ .../test/phase0/sanity/test_blocks_random.py | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index 7fddc0762..a6828f7e0 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -152,6 +152,21 @@ def misc_balances(spec): return balances +def misc_balances_in_default_range(spec): + """ + Helper method to create a series of balances that includes some misc. balances but + none that are below the ``EJECTION_BALANCE``. + """ + num_validators = spec.SLOTS_PER_EPOCH * 8 + floor = spec.config.EJECTION_BALANCE + spec.EFFECTIVE_BALANCE_INCREMENT + balances = [ + max(spec.MAX_EFFECTIVE_BALANCE * 2 * i // num_validators, floor) for i in range(num_validators) + ] + rng = Random(1234) + rng.shuffle(balances) + return balances + + def low_single_balance(spec): """ Helper method to create a single of balance of 1 Gwei. diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 8767ad12c..f015362ac 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,7 +1,7 @@ import itertools from random import Random from typing import Callable -from tests.core.pyspec.eth2spec.test.context import default_activation_threshold +from tests.core.pyspec.eth2spec.test.context import default_activation_threshold, misc_balances_in_default_range from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state, ) @@ -272,7 +272,7 @@ def _iter_temporal(spec, callable_or_int): @pytest_generate_tests_adapter @with_all_phases -@with_custom_state(balances_fn=misc_balances, threshold_fn=default_activation_threshold) +@with_custom_state(balances_fn=misc_balances_in_default_range, threshold_fn=default_activation_threshold) @spec_test @single_phase @always_bls From 86643d805a82e6e8ec0bf700e3e99d1b8452ce21 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 17:36:50 -0700 Subject: [PATCH 010/122] adjust some helper code for randomized environment 1. randomized block helpers assume most of the validator set is not slashed 2. `randomize_state` helper slashes or exits ~1/2 of the validator set So, adjust helpers to be less aggresive with exits and slashings and to skip elements as needed if we happen to make something by a validator who has been slashed. --- .../pyspec/eth2spec/test/helpers/random.py | 26 ++++++++----- .../test/phase0/sanity/test_blocks_random.py | 37 ++++++++++++++++--- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/random.py b/tests/core/pyspec/eth2spec/test/helpers/random.py index 70c871a34..8f095aebb 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/random.py +++ b/tests/core/pyspec/eth2spec/test/helpers/random.py @@ -20,16 +20,20 @@ def set_some_new_deposits(spec, state, rng): state.validators[index].activation_eligibility_epoch = spec.get_current_epoch(state) -def exit_random_validators(spec, state, rng): +def exit_random_validators(spec, state, rng, fraction=None): + if fraction is None: + # Exit ~1/2 + fraction = 0.5 + if spec.get_current_epoch(state) < 5: # Move epochs forward to allow for some validators already exited/withdrawable for _ in range(5): next_epoch(spec, state) current_epoch = spec.get_current_epoch(state) - # Exit ~1/2 of validators for index in spec.get_active_validator_indices(state, current_epoch): - if rng.choice([True, False]): + sampled = rng.random() < fraction + if not sampled: continue validator = state.validators[index] @@ -41,11 +45,15 @@ def exit_random_validators(spec, state, rng): validator.withdrawable_epoch = current_epoch + 1 -def slash_random_validators(spec, state, rng): - # Slash ~1/2 of validators +def slash_random_validators(spec, state, rng, fraction=None): + if fraction is None: + # Slash ~1/2 of validators + fraction = 0.5 + for index in range(len(state.validators)): # slash at least one validator - if index == 0 or rng.choice([True, False]): + sampled = rng.random() < fraction + if index == 0 or sampled: spec.slash_validator(state, index) @@ -115,8 +123,8 @@ def randomize_attestation_participation(spec, state, rng=Random(8020)): randomize_epoch_participation(spec, state, spec.get_current_epoch(state), rng) -def randomize_state(spec, state, rng=Random(8020)): +def randomize_state(spec, state, rng=Random(8020), exit_fraction=None, slash_fraction=None): set_some_new_deposits(spec, state, rng) - exit_random_validators(spec, state, rng) - slash_random_validators(spec, state, rng) + exit_random_validators(spec, state, rng, fraction=exit_fraction) + slash_random_validators(spec, state, rng, fraction=slash_fraction) randomize_attestation_participation(spec, state, rng) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index f015362ac..d4740d080 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,7 +1,7 @@ import itertools from random import Random from typing import Callable -from tests.core.pyspec.eth2spec.test.context import default_activation_threshold, misc_balances_in_default_range +from tests.core.pyspec.eth2spec.test.context import misc_balances_in_default_range, zero_activation_threshold from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state, ) @@ -24,7 +24,17 @@ from eth2spec.test.context import ( misc_balances, ) +# May need to make several attempts to find a block that does not correspond to a slashed +# proposer with the randomization helpers... +BLOCK_ATTEMPTS = 32 + # primitives +## state + +def _randomize_state(spec, state): + return randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) + + ## epochs def _epochs_until_leak(spec): @@ -57,8 +67,23 @@ def _no_block(_spec, _pre_state, _signed_blocks): return None -def _random_block_for_next_slot(spec, pre_state, _signed_blocks): - return build_random_block_from_state(spec, pre_state) +def _random_block(spec, state, _signed_blocks): + """ + Produce a random block. + NOTE: this helper may mutate state, as it will attempt + to produce a block over ``BLOCK_ATTEMPTS`` slots in order + to find a valid block in the event that the proposer has already been slashed. + """ + block = build_random_block_from_state(spec, state) + for _ in range(BLOCK_ATTEMPTS): + proposer = state.validators[block.proposer_index] + if proposer.slashed: + next_slot(spec, state) + block = build_random_block_from_state(spec, state) + else: + return block + else: + raise AssertionError("could not find a block with an unslashed proposer, check ``state`` input") ## validations @@ -105,7 +130,7 @@ def _transition_with_random_block(epochs=None, slots=None): number of epochs or slots before applying the random block. """ transition = { - "block_producer": _random_block_for_next_slot, + "block_producer": _random_block, } if epochs: transition.update(epochs) @@ -137,7 +162,7 @@ def _randomized_scenario_setup(): # NOTE: the block randomization function assumes at least 1 shard committee period # so advance the state before doing anything else. (_skip_epochs(_epochs_for_shard_committee_period), _no_op_validation), - (randomize_state, ensure_state_has_validators_across_lifecycle), + (_randomize_state, ensure_state_has_validators_across_lifecycle), ) @@ -272,7 +297,7 @@ def _iter_temporal(spec, callable_or_int): @pytest_generate_tests_adapter @with_all_phases -@with_custom_state(balances_fn=misc_balances_in_default_range, threshold_fn=default_activation_threshold) +@with_custom_state(balances_fn=misc_balances_in_default_range, threshold_fn=zero_activation_threshold) @spec_test @single_phase @always_bls From 7bc2f9547a038d7ee9c271c262c114a3bf31f699 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 17:52:26 -0700 Subject: [PATCH 011/122] skip validators when building a random block if they are slashed --- .../eth2spec/test/helpers/multi_operations.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index dc64882b8..2629206e7 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -45,7 +45,11 @@ def run_slash_and_exit(spec, state, slash_index, exit_index, valid=True): def get_random_proposer_slashings(spec, state, rng): num_slashings = rng.randrange(spec.MAX_PROPOSER_SLASHINGS) - indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() + active_indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() + indices = [ + index for index in active_indices + if not state.validators[index].slashed + ] slashings = [ get_valid_proposer_slashing( spec, state, @@ -58,7 +62,11 @@ def get_random_proposer_slashings(spec, state, rng): def get_random_attester_slashings(spec, state, rng): num_slashings = rng.randrange(spec.MAX_ATTESTER_SLASHINGS) - indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() + active_indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() + indices = [ + index for index in active_indices + if not state.validators[index].slashed + ] slot_range = list(range(state.slot - spec.SLOTS_PER_HISTORICAL_ROOT + 1, state.slot)) slashings = [ get_valid_attester_slashing_by_indices( @@ -119,9 +127,14 @@ def prepare_state_and_get_random_deposits(spec, state, rng): def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): num_exits = rng.randrange(spec.MAX_VOLUNTARY_EXITS) - indices = set(spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy()) + active_indices = set(spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy()) + indices = set( + index for index in active_indices + if not state.validators[index].slashed + ) eligible_indices = indices - to_be_slashed_indices - exit_indices = [eligible_indices.pop() for _ in range(num_exits)] + indices_count = min(num_exits, len(eligible_indices)) + exit_indices = [eligible_indices.pop() for _ in range(indices_count)] return prepare_signed_exits(spec, state, exit_indices) From fde71cbe74b9aefa87593f54b9b6e246eda5d17e Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 18:07:00 -0700 Subject: [PATCH 012/122] add warnings if empty block --- .../test/phase0/sanity/test_blocks_random.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index d4740d080..d7749909e 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,4 +1,5 @@ import itertools +import warnings from random import Random from typing import Callable from tests.core.pyspec.eth2spec.test.context import misc_balances_in_default_range, zero_activation_threshold @@ -24,6 +25,23 @@ from eth2spec.test.context import ( misc_balances, ) +def _warn_if_empty_operations(block): + if len(block.body.deposits) == 0: + warnings.warn(f"deposits missing in block at slot {block.slot}") + + if len(block.body.proposer_slashings) == 0: + warnings.warn(f"proposer slashings missing in block at slot {block.slot}") + + if len(block.body.attester_slashings) == 0: + warnings.warn(f"attester slashings missing in block at slot {block.slot}") + + if len(block.body.attestations) == 0: + warnings.warn(f"attestations missing in block at slot {block.slot}") + + if len(block.body.voluntary_exits) == 0: + warnings.warn(f"voluntary exits missing in block at slot {block.slot}") + + # May need to make several attempts to find a block that does not correspond to a slashed # proposer with the randomization helpers... BLOCK_ATTEMPTS = 32 @@ -81,6 +99,7 @@ def _random_block(spec, state, _signed_blocks): next_slot(spec, state) block = build_random_block_from_state(spec, state) else: + _warn_if_empty_operations(block) return block else: raise AssertionError("could not find a block with an unslashed proposer, check ``state`` input") From 9e6a51ef70f3e93d0fe4c5c802ee3c2d20b62ff9 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 18:07:12 -0700 Subject: [PATCH 013/122] update fn name for test id --- .../pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index d7749909e..98b251add 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -70,9 +70,9 @@ def _last_slot_in_epoch(spec): def _random_slot_in_epoch(rng): - def f(spec): + def _a_slot_in_epoch(spec): return rng.randrange(1, spec.SLOTS_PER_EPOCH - 2) - return f + return _a_slot_in_epoch def _penultimate_slot_in_epoch(spec): From b17ada2d67ba9c944c75ebc9c9ff52e796a6c8f3 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 18:24:26 -0700 Subject: [PATCH 014/122] only target phase 0 and altair for now --- .../pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 98b251add..05ae545b8 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,8 +1,9 @@ import itertools import warnings from random import Random +from tests.core.pyspec.eth2spec.test.helpers.constants import PHASE0, ALTAIR from typing import Callable -from tests.core.pyspec.eth2spec.test.context import misc_balances_in_default_range, zero_activation_threshold +from tests.core.pyspec.eth2spec.test.context import misc_balances_in_default_range, with_phases, zero_activation_threshold from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state, ) @@ -315,7 +316,7 @@ def _iter_temporal(spec, callable_or_int): @pytest_generate_tests_adapter -@with_all_phases +@with_phases([PHASE0, ALTAIR]) @with_custom_state(balances_fn=misc_balances_in_default_range, threshold_fn=zero_activation_threshold) @spec_test @single_phase From 513f57f74c923d7300fe06a879d56a8340be6d6f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 09:55:41 -0700 Subject: [PATCH 015/122] formatting --- .../eth2spec/test/phase0/sanity/test_blocks_random.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 05ae545b8..cead514a5 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -233,7 +233,10 @@ def _generate_randomized_scenarios(): rng = Random(1336) # go forward 0 or 1 epochs - epochs_set = (_epoch_transition(n=0), _epoch_transition(n=1)) + epochs_set = ( + _epoch_transition(n=0), + _epoch_transition(n=1), + ) # within those epochs, go forward to: slots_set = ( # the first slot in an epoch (see note in docstring about offsets...) @@ -253,7 +256,10 @@ def _generate_randomized_scenarios(): # and preface each block transition with the possible leak transitions # (... either no leak or transition to a leak before applying the block transition) - leak_transitions = (_no_op_transition, _transition_to_leaking) + leak_transitions = ( + _no_op_transition, + _transition_to_leaking, + ) scenarios = [ {"transitions": list(t)} for t in itertools.product(leak_transitions, block_transitions) From 820affd2aaa8e9f0d889a125d43ef0d62936eb8c Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 09:58:54 -0700 Subject: [PATCH 016/122] extend validator set so randomized helpers have more room for operation --- tests/core/pyspec/eth2spec/test/context.py | 5 +++-- .../eth2spec/test/phase0/sanity/test_blocks_random.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index a6828f7e0..f6f120d55 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -152,12 +152,13 @@ def misc_balances(spec): return balances -def misc_balances_in_default_range(spec): +def misc_balances_in_default_range_with_many_validators(spec): """ Helper method to create a series of balances that includes some misc. balances but none that are below the ``EJECTION_BALANCE``. """ - num_validators = spec.SLOTS_PER_EPOCH * 8 + # Double validators to facilitate randomized testing + num_validators = spec.SLOTS_PER_EPOCH * 8 * 2 floor = spec.config.EJECTION_BALANCE + spec.EFFECTIVE_BALANCE_INCREMENT balances = [ max(spec.MAX_EFFECTIVE_BALANCE * 2 * i // num_validators, floor) for i in range(num_validators) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index cead514a5..52868c744 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -3,7 +3,11 @@ import warnings from random import Random from tests.core.pyspec.eth2spec.test.helpers.constants import PHASE0, ALTAIR from typing import Callable -from tests.core.pyspec.eth2spec.test.context import misc_balances_in_default_range, with_phases, zero_activation_threshold +from tests.core.pyspec.eth2spec.test.context import ( + misc_balances_in_default_range_with_many_validators, + with_phases, + zero_activation_threshold, +) from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state, ) @@ -323,7 +327,10 @@ def _iter_temporal(spec, callable_or_int): @pytest_generate_tests_adapter @with_phases([PHASE0, ALTAIR]) -@with_custom_state(balances_fn=misc_balances_in_default_range, threshold_fn=zero_activation_threshold) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) @spec_test @single_phase @always_bls From 270814e20fbc9b80cbe6c34eb1dff5534a4cd52e Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 09:59:28 -0700 Subject: [PATCH 017/122] fix bug with `_epochs_until_leak` helper --- .../eth2spec/test/phase0/sanity/test_blocks_random.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 52868c744..e0043332d 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -61,7 +61,11 @@ def _randomize_state(spec, state): ## epochs def _epochs_until_leak(spec): - return spec.MIN_EPOCHS_TO_INACTIVITY_PENALTY + """ + State is "leaking" if the current epoch is at least + this value after the last finalized epoch. + """ + return spec.MIN_EPOCHS_TO_INACTIVITY_PENALTY + 1 def _epochs_for_shard_committee_period(spec): From 993997aca5ddf88d17db341791ac89156adee77b Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 10:07:31 -0700 Subject: [PATCH 018/122] ensure no leak on "normal" transitions --- .../test/phase0/sanity/test_blocks_random.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index e0043332d..c3b55e49d 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -124,8 +124,19 @@ def _validate_is_leaking(spec, state): return spec.is_in_inactivity_leak(state) +def _validate_is_not_leaking(spec, state): + return not _validate_is_leaking(spec, state) + + # transitions +def _with_validation(transition, validation): + if isinstance(transition, Callable): + transition = transition() + transition["validation"] = validation + return transition + + def _no_op_transition(): return {} @@ -264,8 +275,9 @@ def _generate_randomized_scenarios(): # and preface each block transition with the possible leak transitions # (... either no leak or transition to a leak before applying the block transition) + _transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) leak_transitions = ( - _no_op_transition, + _transition_without_leak, _transition_to_leaking, ) scenarios = [ From f76a29c1f9b2ede7cc2ce371d1e5b94df2fef85f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 10:52:22 -0700 Subject: [PATCH 019/122] patch state to not be leaking at start --- .../test/phase0/sanity/test_blocks_random.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index c3b55e49d..c379d5815 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -197,10 +197,35 @@ def _randomized_scenario_setup(): state.slot += slots_to_skip return f + def _simulate_honest_execution(spec, state): + """ + Want to start tests not in a leak state; the finality data + may not reflect this condition with prior (arbitrary) mutations, + so this mutator addresses that fact. + """ + state.justification_bits = (True, True, True, True) + previous_epoch = spec.get_previous_epoch(state) + previous_root = spec.get_block_root(state, previous_epoch) + previous_previous_epoch = max(spec.GENESIS_EPOCH, spec.Epoch(previous_epoch - 1)) + previous_previous_root = spec.get_block_root(state, previous_previous_epoch) + state.previous_justified_checkpoint = spec.Checkpoint( + epoch=previous_previous_epoch, + root=previous_previous_root, + ) + state.current_justified_checkpoint = spec.Checkpoint( + epoch=previous_epoch, + root=previous_root, + ) + state.finalized_checkpoint = spec.Checkpoint( + epoch=previous_previous_epoch, + root=previous_previous_root, + ) + return ( # NOTE: the block randomization function assumes at least 1 shard committee period # so advance the state before doing anything else. (_skip_epochs(_epochs_for_shard_committee_period), _no_op_validation), + (_simulate_honest_execution, _no_op_validation), (_randomize_state, ensure_state_has_validators_across_lifecycle), ) From ce471b702e57114e3c66a8cec13f8f14b627ca46 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 10:54:00 -0700 Subject: [PATCH 020/122] code org --- .../pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index c379d5815..93f31a4da 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -160,6 +160,8 @@ def _transition_to_leaking(): } +_transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) + ## block transitions def _transition_with_random_block(epochs=None, slots=None): @@ -300,7 +302,6 @@ def _generate_randomized_scenarios(): # and preface each block transition with the possible leak transitions # (... either no leak or transition to a leak before applying the block transition) - _transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) leak_transitions = ( _transition_without_leak, _transition_to_leaking, From 0c401a3e2a470b8f567f53e03254ffe6536ae0f1 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 12:13:40 -0700 Subject: [PATCH 021/122] filter for exit eligibility in helper --- .../eth2spec/test/helpers/multi_operations.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 2629206e7..54e45b335 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -125,12 +125,24 @@ def prepare_state_and_get_random_deposits(spec, state, rng): return deposits +def _eligible_for_exit(spec, state, index): + validator = state.validators[index] + + not_slashed = not validator.slashed + + current_epoch = spec.get_current_epoch(state) + activation_epoch = validator.activation_epoch + active_for_long_enough = current_epoch >= activation_epoch + spec.config.SHARD_COMMITTEE_PERIOD + + return not_slashed and active_for_long_enough + + def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): num_exits = rng.randrange(spec.MAX_VOLUNTARY_EXITS) active_indices = set(spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy()) indices = set( index for index in active_indices - if not state.validators[index].slashed + if _eligible_for_exit(spec, state, index) ) eligible_indices = indices - to_be_slashed_indices indices_count = min(num_exits, len(eligible_indices)) From 253f927c0a45c4830c54f2fd99163e8191f9b6b3 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 12:14:17 -0700 Subject: [PATCH 022/122] fix randomness seed across randomized test --- .../pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 93f31a4da..8928b9309 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,6 +1,6 @@ import itertools import warnings -from random import Random +import random from tests.core.pyspec.eth2spec.test.helpers.constants import PHASE0, ALTAIR from typing import Callable from tests.core.pyspec.eth2spec.test.context import ( @@ -276,7 +276,7 @@ def _generate_randomized_scenarios(): NOTE: the main block driver builds a block for the **next** slot, so the slot transitions are offset by -1 to target certain boundaries. """ - rng = Random(1336) + rng = random.Random(1336) # go forward 0 or 1 epochs epochs_set = ( @@ -377,6 +377,7 @@ def _iter_temporal(spec, callable_or_int): @single_phase @always_bls def test_harness_for_randomized_blocks(spec, state, test_description): + random.seed(1337) for mutation, validation in test_description["setup"]: mutation(spec, state) validation(spec, state) From 2db01ba6d06bb3290f6d2ac02b59152cee4615c0 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sun, 22 Aug 2021 13:33:30 -0700 Subject: [PATCH 023/122] use fixed seed for block randomization --- .../eth2spec/test/phase0/sanity/test_blocks_random.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 8928b9309..7279e19d0 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -30,6 +30,8 @@ from eth2spec.test.context import ( misc_balances, ) +rng = random.Random(1337) + def _warn_if_empty_operations(block): if len(block.body.deposits) == 0: warnings.warn(f"deposits missing in block at slot {block.slot}") @@ -101,7 +103,7 @@ def _random_block(spec, state, _signed_blocks): to produce a block over ``BLOCK_ATTEMPTS`` slots in order to find a valid block in the event that the proposer has already been slashed. """ - block = build_random_block_from_state(spec, state) + block = build_random_block_from_state(spec, state, rng) for _ in range(BLOCK_ATTEMPTS): proposer = state.validators[block.proposer_index] if proposer.slashed: @@ -276,8 +278,6 @@ def _generate_randomized_scenarios(): NOTE: the main block driver builds a block for the **next** slot, so the slot transitions are offset by -1 to target certain boundaries. """ - rng = random.Random(1336) - # go forward 0 or 1 epochs epochs_set = ( _epoch_transition(n=0), @@ -377,7 +377,6 @@ def _iter_temporal(spec, callable_or_int): @single_phase @always_bls def test_harness_for_randomized_blocks(spec, state, test_description): - random.seed(1337) for mutation, validation in test_description["setup"]: mutation(spec, state) validation(spec, state) From fe1b9961ff413d7ca72eab3e9525a8851b92fe56 Mon Sep 17 00:00:00 2001 From: ericsson Date: Mon, 23 Aug 2021 14:21:38 +0300 Subject: [PATCH 024/122] Fix typos in sharding.md --- specs/sharding/beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index 2e2c3d487..c7e528810 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -257,7 +257,7 @@ class AttestedDataCommitment(Container): includer_index: ValidatorIndex ``` -### ShardBlobBody +### `ShardBlobBody` Unsigned shard data, bundled by a shard-builder. Unique, signing different bodies as shard proposer for the same `(slot, shard)` is slashable. @@ -759,7 +759,7 @@ def process_shard_header(state: BeaconState, signed_header: SignedShardBlobHeade commitment=body_summary.commitment, root=header_root, includer_index=get_beacon_proposer_index(state), - ) + ), votes=initial_votes, weight=0, update_slot=state.slot, @@ -885,7 +885,7 @@ def reset_pending_shard_work(state: BeaconState) -> None: selector=SHARD_WORK_PENDING, value=List[PendingShardHeader, MAX_SHARD_HEADERS_PER_SHARD]( PendingShardHeader( - attested=AttestedDataCommitment() + attested=AttestedDataCommitment(), votes=Bitlist[MAX_VALIDATORS_PER_COMMITTEE]([0] * committee_length), weight=0, update_slot=slot, From 43a6beceb68c7c60c5738c5dc00abec00b7c1d77 Mon Sep 17 00:00:00 2001 From: ericsson Date: Mon, 23 Aug 2021 14:46:06 +0300 Subject: [PATCH 025/122] make doctoc happy --- specs/sharding/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index c7e528810..031d8087f 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -32,7 +32,7 @@ - [`Builder`](#builder) - [`DataCommitment`](#datacommitment) - [`AttestedDataCommitment`](#attesteddatacommitment) - - [ShardBlobBody](#shardblobbody) + - [`ShardBlobBody`](#shardblobbody) - [`ShardBlobBodySummary`](#shardblobbodysummary) - [`ShardBlob`](#shardblob) - [`ShardBlobHeader`](#shardblobheader) From 838c263c4a82ffc7c43a426bfb91adc958e001c4 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 23 Aug 2021 23:21:15 +0800 Subject: [PATCH 026/122] Apply suggestions from code review Co-authored-by: Aditya Asgaonkar --- .../test/phase0/unittests/fork_choice/test_on_tick.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py b/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py index 40606197e..0d9f6ddf5 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py +++ b/tests/core/pyspec/eth2spec/test/phase0/unittests/fork_choice/test_on_tick.py @@ -46,7 +46,7 @@ def test_update_justified_single_on_store_finalized_chain(spec, state): store.block_states[block.hash_tree_root()] = state.copy() parent_block = block.copy() # To make compute_slots_since_epoch_start(current_slot) == 0, transition to the end of the epoch - slot = state.slot + spec.SLOTS_PER_EPOCH - (state.slot + spec.SLOTS_PER_EPOCH) % spec.SLOTS_PER_EPOCH - 1 + slot = state.slot + spec.SLOTS_PER_EPOCH - state.slot % spec.SLOTS_PER_EPOCH - 1 transition_to(spec, state, slot) # Create a block at the start of epoch 2 block = build_empty_block_for_next_slot(spec, state) @@ -100,7 +100,7 @@ def test_update_justified_single_not_on_store_finalized_chain(spec, state): store.block_states[block.hash_tree_root()] = state.copy() parent_block = block.copy() # To make compute_slots_since_epoch_start(current_slot) == 0, transition to the end of the epoch - slot = state.slot + spec.SLOTS_PER_EPOCH - (state.slot + spec.SLOTS_PER_EPOCH) % spec.SLOTS_PER_EPOCH - 1 + slot = state.slot + spec.SLOTS_PER_EPOCH - state.slot % spec.SLOTS_PER_EPOCH - 1 transition_to(spec, state, slot) # Create a block at the start of epoch 2 block = build_empty_block_for_next_slot(spec, state) From 96c05adcf824ca403e5e5a22d3ed0e72886def23 Mon Sep 17 00:00:00 2001 From: ericsson Date: Mon, 23 Aug 2021 18:52:09 +0300 Subject: [PATCH 027/122] Fix typing problem: `is_merge_block` accepts `BeaconBlockBody` as a second argument, while `BeaconBlock` is provided --- specs/merge/fork-choice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index 900d8b331..15ef1c301 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -129,7 +129,7 @@ def on_block(store: Store, signed_block: SignedBeaconBlock, transition_store: Tr assert get_ancestor(store, block.parent_root, finalized_slot) == store.finalized_checkpoint.root # [New in Merge] - if (transition_store is not None) and is_merge_block(pre_state, block): + if (transition_store is not None) and is_merge_block(pre_state, block.body): # Delay consideration of block until PoW block is processed by the PoW node pow_block = get_pow_block(block.body.execution_payload.parent_hash) pow_parent = get_pow_block(pow_block.parent_hash) From 33552279bf218b109ad42f76408aa7c122544adf Mon Sep 17 00:00:00 2001 From: ericsson Date: Mon, 23 Aug 2021 20:09:01 +0300 Subject: [PATCH 028/122] Fix typos in `get_shard_proposer_index`: `beacon_state` vs `state` --- specs/sharding/beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index 031d8087f..0249590b8 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -503,14 +503,14 @@ def get_active_shard_count(state: BeaconState, epoch: Epoch) -> uint64: #### `get_shard_proposer_index` ```python -def get_shard_proposer_index(beacon_state: BeaconState, slot: Slot, shard: Shard) -> ValidatorIndex: +def get_shard_proposer_index(state: BeaconState, slot: Slot, shard: Shard) -> ValidatorIndex: """ Return the proposer's index of shard block at ``slot``. """ epoch = compute_epoch_at_slot(slot) - seed = hash(get_seed(beacon_state, epoch, DOMAIN_SHARD_BLOB) + uint_to_bytes(slot) + uint_to_bytes(shard)) + seed = hash(get_seed(state, epoch, DOMAIN_SHARD_BLOB) + uint_to_bytes(slot) + uint_to_bytes(shard)) indices = get_active_validator_indices(state, epoch) - return compute_proposer_index(beacon_state, indices, seed) + return compute_proposer_index(state, indices, seed) ``` #### `get_start_shard` From 34d42b640d8cc72d11df3af4c3935bc619eac71c Mon Sep 17 00:00:00 2001 From: ericsson Date: Mon, 23 Aug 2021 20:09:41 +0300 Subject: [PATCH 029/122] Fix typo in `get_start_shard` --- specs/sharding/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index 0249590b8..f54394275 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -520,7 +520,7 @@ def get_start_shard(state: BeaconState, slot: Slot) -> Shard: """ Return the start shard at ``slot``. """ - epoch = compute_epoch_at_slot(Slot(_slot)) + epoch = compute_epoch_at_slot(Slot(slot)) committee_count = get_committee_count_per_slot(state, epoch) active_shard_count = get_active_shard_count(state, epoch) return committee_count * slot % active_shard_count From 361d97c54bf0f97dd1a31142186b0ac02e7be83c Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 09:54:00 -0700 Subject: [PATCH 030/122] fix bug with proposer search --- .../pyspec/eth2spec/test/helpers/multi_operations.py | 4 ++-- .../eth2spec/test/phase0/sanity/test_blocks_random.py | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 54e45b335..c53cc40c7 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -150,7 +150,7 @@ def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): return prepare_signed_exits(spec, state, exit_indices) -def build_random_block_from_state(spec, state, rng=Random(2188)): +def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188)): # prepare state for deposits before building block deposits = prepare_state_and_get_random_deposits(spec, state, rng) @@ -177,7 +177,7 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - block = build_random_block_from_state(spec, state, rng) + block = build_random_block_from_state_for_next_slot(spec, state, rng) yield 'pre', state diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 7279e19d0..fb7b308f6 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -9,7 +9,7 @@ from tests.core.pyspec.eth2spec.test.context import ( zero_activation_threshold, ) from eth2spec.test.helpers.multi_operations import ( - build_random_block_from_state, + build_random_block_from_state_for_next_slot, ) from eth2spec.test.helpers.state import ( next_epoch, @@ -103,13 +103,16 @@ def _random_block(spec, state, _signed_blocks): to produce a block over ``BLOCK_ATTEMPTS`` slots in order to find a valid block in the event that the proposer has already been slashed. """ - block = build_random_block_from_state(spec, state, rng) + temp_state = state.copy() + next_slot(spec, temp_state) for _ in range(BLOCK_ATTEMPTS): - proposer = state.validators[block.proposer_index] + proposer_index = spec.get_beacon_proposer_index(temp_state) + proposer = state.validators[proposer_index] if proposer.slashed: next_slot(spec, state) - block = build_random_block_from_state(spec, state) + next_slot(spec, temp_state) else: + block = build_random_block_from_state_for_next_slot(spec, state) _warn_if_empty_operations(block) return block else: From 6316c7d364888264b209c6cbd01b9e6373fe6c0b Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 10:29:39 -0700 Subject: [PATCH 031/122] ensure at least 1 attester slashing --- tests/core/pyspec/eth2spec/test/helpers/multi_operations.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index c53cc40c7..962ab6404 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -61,7 +61,9 @@ def get_random_proposer_slashings(spec, state, rng): def get_random_attester_slashings(spec, state, rng): - num_slashings = rng.randrange(spec.MAX_ATTESTER_SLASHINGS) + # ensure at least one attester slashing, the max count + # is small so not much room for random inclusion + num_slashings = max(1, rng.randrange(spec.MAX_ATTESTER_SLASHINGS)) active_indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() indices = [ index for index in active_indices From 16423880aa6d8335125e6c73507848c846289c4a Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 11:00:33 -0700 Subject: [PATCH 032/122] add multiple blocks to each test --- .../test/phase0/sanity/test_blocks_random.py | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index fb7b308f6..4051f9c7d 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -52,6 +52,8 @@ def _warn_if_empty_operations(block): # May need to make several attempts to find a block that does not correspond to a slashed # proposer with the randomization helpers... BLOCK_ATTEMPTS = 32 +# Ensure this many blocks are present in *each* randomized scenario +BLOCK_TRANSITIONS_COUNT = 2 # primitives ## state @@ -269,6 +271,15 @@ def _normalize_scenarios(scenarios): transitions[i] = _normalize_transition(transition) +def _flatten(t): + leak_transition = t[0] + result = [leak_transition] + for transition_batch in t[1]: + for transition in transition_batch: + result.append(transition) + return result + + def _generate_randomized_scenarios(): """ Generates a set of randomized testing scenarios. @@ -297,20 +308,24 @@ def _generate_randomized_scenarios(): # the last slot in an epoch (see note in docstring about offsets...) _slot_transition(_penultimate_slot_in_epoch), ) - # build a set of block transitions from combinations of sub-transitions - block_transitions = list( - _transition_with_random_block(epochs=epochs, slots=slots) - for epochs, slots in itertools.product(epochs_set, slots_set) + # and produce a block... + blocks_set = ( + _transition_with_random_block, ) + # build a set of block transitions from combinations of sub-transitions + transitions_generator = ( + itertools.product(epochs_set, slots_set, blocks_set) for + _ in range(BLOCK_TRANSITIONS_COUNT) + ) + block_transitions = zip(*transitions_generator) - # and preface each block transition with the possible leak transitions - # (... either no leak or transition to a leak before applying the block transition) + # and preface each set of block transitions with the possible leak transitions leak_transitions = ( _transition_without_leak, _transition_to_leaking, ) scenarios = [ - {"transitions": list(t)} + {"transitions": _flatten(t)} for t in itertools.product(leak_transitions, block_transitions) ] _normalize_scenarios(scenarios) From 20e3934fa2fd66ca7dcc53b67f75fe088ae93ac2 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 11:12:40 -0700 Subject: [PATCH 033/122] do not exit validators who are already exited --- tests/core/pyspec/eth2spec/test/helpers/multi_operations.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 962ab6404..52234fa97 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -136,7 +136,9 @@ def _eligible_for_exit(spec, state, index): activation_epoch = validator.activation_epoch active_for_long_enough = current_epoch >= activation_epoch + spec.config.SHARD_COMMITTEE_PERIOD - return not_slashed and active_for_long_enough + not_exited = validator.exit_epoch == spec.FAR_FUTURE_EPOCH + + return not_slashed and active_for_long_enough and not_exited def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): From 31d46247ce403651d98dc4a2bcbb41c799a4533e Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 11:48:22 -0700 Subject: [PATCH 034/122] file re-org to re-use for later forks --- .../test/phase0/sanity/test_blocks_random.py | 403 +----------------- .../pyspec/eth2spec/test/utils/__init__.py | 5 + .../core/pyspec/eth2spec/test/utils/random.py | 398 +++++++++++++++++ .../pyspec/eth2spec/test/{ => utils}/utils.py | 0 4 files changed, 412 insertions(+), 394 deletions(-) create mode 100644 tests/core/pyspec/eth2spec/test/utils/__init__.py create mode 100644 tests/core/pyspec/eth2spec/test/utils/random.py rename tests/core/pyspec/eth2spec/test/{ => utils}/utils.py (100%) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 4051f9c7d..6ea793206 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,392 +1,30 @@ -import itertools -import warnings -import random -from tests.core.pyspec.eth2spec.test.helpers.constants import PHASE0, ALTAIR -from typing import Callable +from tests.core.pyspec.eth2spec.test.helpers.constants import PHASE0 from tests.core.pyspec.eth2spec.test.context import ( misc_balances_in_default_range_with_many_validators, with_phases, zero_activation_threshold, ) -from eth2spec.test.helpers.multi_operations import ( - build_random_block_from_state_for_next_slot, -) -from eth2spec.test.helpers.state import ( - next_epoch, - next_slot, - ensure_state_has_validators_across_lifecycle, - state_transition_and_sign_block, -) -from eth2spec.test.helpers.random import ( - randomize_state, -) from eth2spec.test.context import ( - with_all_phases, always_bls, spec_test, with_custom_state, - default_activation_threshold, single_phase, - misc_balances, ) - -rng = random.Random(1337) - -def _warn_if_empty_operations(block): - if len(block.body.deposits) == 0: - warnings.warn(f"deposits missing in block at slot {block.slot}") - - if len(block.body.proposer_slashings) == 0: - warnings.warn(f"proposer slashings missing in block at slot {block.slot}") - - if len(block.body.attester_slashings) == 0: - warnings.warn(f"attester slashings missing in block at slot {block.slot}") - - if len(block.body.attestations) == 0: - warnings.warn(f"attestations missing in block at slot {block.slot}") - - if len(block.body.voluntary_exits) == 0: - warnings.warn(f"voluntary exits missing in block at slot {block.slot}") - - -# May need to make several attempts to find a block that does not correspond to a slashed -# proposer with the randomization helpers... -BLOCK_ATTEMPTS = 32 -# Ensure this many blocks are present in *each* randomized scenario -BLOCK_TRANSITIONS_COUNT = 2 - -# primitives -## state - -def _randomize_state(spec, state): - return randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) - - -## epochs - -def _epochs_until_leak(spec): - """ - State is "leaking" if the current epoch is at least - this value after the last finalized epoch. - """ - return spec.MIN_EPOCHS_TO_INACTIVITY_PENALTY + 1 - - -def _epochs_for_shard_committee_period(spec): - return spec.config.SHARD_COMMITTEE_PERIOD - - -## slots - -def _last_slot_in_epoch(spec): - return spec.SLOTS_PER_EPOCH - 1 - - -def _random_slot_in_epoch(rng): - def _a_slot_in_epoch(spec): - return rng.randrange(1, spec.SLOTS_PER_EPOCH - 2) - return _a_slot_in_epoch - - -def _penultimate_slot_in_epoch(spec): - return spec.SLOTS_PER_EPOCH - 2 - - -## blocks - -def _no_block(_spec, _pre_state, _signed_blocks): - return None - - -def _random_block(spec, state, _signed_blocks): - """ - Produce a random block. - NOTE: this helper may mutate state, as it will attempt - to produce a block over ``BLOCK_ATTEMPTS`` slots in order - to find a valid block in the event that the proposer has already been slashed. - """ - temp_state = state.copy() - next_slot(spec, temp_state) - for _ in range(BLOCK_ATTEMPTS): - proposer_index = spec.get_beacon_proposer_index(temp_state) - proposer = state.validators[proposer_index] - if proposer.slashed: - next_slot(spec, state) - next_slot(spec, temp_state) - else: - block = build_random_block_from_state_for_next_slot(spec, state) - _warn_if_empty_operations(block) - return block - else: - raise AssertionError("could not find a block with an unslashed proposer, check ``state`` input") - - -## validations - -def _no_op_validation(spec, state): - return True - - -def _validate_is_leaking(spec, state): - return spec.is_in_inactivity_leak(state) - - -def _validate_is_not_leaking(spec, state): - return not _validate_is_leaking(spec, state) - - -# transitions - -def _with_validation(transition, validation): - if isinstance(transition, Callable): - transition = transition() - transition["validation"] = validation - return transition - - -def _no_op_transition(): - return {} - - -def _epoch_transition(n=0): - return { - "epochs_to_skip": n, - } - - -def _slot_transition(n=0): - return { - "slots_to_skip": n, - } - - -def _transition_to_leaking(): - return { - "epochs_to_skip": _epochs_until_leak, - "validation": _validate_is_leaking, - } - - -_transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) - -## block transitions - -def _transition_with_random_block(epochs=None, slots=None): - """ - Build a block transition with randomized data. - Provide optional sub-transitions to advance some - number of epochs or slots before applying the random block. - """ - transition = { - "block_producer": _random_block, - } - if epochs: - transition.update(epochs) - if slots: - transition.update(slots) - return transition - - -# setup and test gen - -def _randomized_scenario_setup(): - """ - Return a sequence of pairs of ("mutator", "validator"), - a function that accepts (spec, state) arguments and performs some change - and a function that accepts (spec, state) arguments and validates some change was made. - """ - def _skip_epochs(epoch_producer): - def f(spec, state): - """ - The unoptimized spec implementation is too slow to advance via ``next_epoch``. - Instead, just overwrite the ``state.slot`` and continue... - """ - epochs_to_skip = epoch_producer(spec) - slots_to_skip = epochs_to_skip * spec.SLOTS_PER_EPOCH - state.slot += slots_to_skip - return f - - def _simulate_honest_execution(spec, state): - """ - Want to start tests not in a leak state; the finality data - may not reflect this condition with prior (arbitrary) mutations, - so this mutator addresses that fact. - """ - state.justification_bits = (True, True, True, True) - previous_epoch = spec.get_previous_epoch(state) - previous_root = spec.get_block_root(state, previous_epoch) - previous_previous_epoch = max(spec.GENESIS_EPOCH, spec.Epoch(previous_epoch - 1)) - previous_previous_root = spec.get_block_root(state, previous_previous_epoch) - state.previous_justified_checkpoint = spec.Checkpoint( - epoch=previous_previous_epoch, - root=previous_previous_root, - ) - state.current_justified_checkpoint = spec.Checkpoint( - epoch=previous_epoch, - root=previous_root, - ) - state.finalized_checkpoint = spec.Checkpoint( - epoch=previous_previous_epoch, - root=previous_previous_root, - ) - - return ( - # NOTE: the block randomization function assumes at least 1 shard committee period - # so advance the state before doing anything else. - (_skip_epochs(_epochs_for_shard_committee_period), _no_op_validation), - (_simulate_honest_execution, _no_op_validation), - (_randomize_state, ensure_state_has_validators_across_lifecycle), - ) - - -def _normalize_transition(transition): - """ - Provide "empty" or "no op" sub-transitions - to a given transition. - """ - if isinstance(transition, Callable): - transition = transition() - if "epochs_to_skip" not in transition: - transition["epochs_to_skip"] = 0 - if "slots_to_skip" not in transition: - transition["slots_to_skip"] = 0 - if "block_producer" not in transition: - transition["block_producer"] = _no_block - if "validation" not in transition: - transition["validation"] = _no_op_validation - return transition - - -def _normalize_scenarios(scenarios): - """ - "Normalize" a "scenario" so that a producer of a test case - does not need to provide every expected key/value. - """ - for scenario in scenarios: - if "setup" not in scenario: - scenario["setup"] = _randomized_scenario_setup() - - transitions = scenario["transitions"] - for i, transition in enumerate(transitions): - transitions[i] = _normalize_transition(transition) - - -def _flatten(t): - leak_transition = t[0] - result = [leak_transition] - for transition_batch in t[1]: - for transition in transition_batch: - result.append(transition) - return result - - -def _generate_randomized_scenarios(): - """ - Generates a set of randomized testing scenarios. - Return a sequence of "scenarios" where each scenario: - 1. Provides some setup - 2. Provides a sequence of transitions that mutate the state in some way, - possibly yielding blocks along the way - NOTE: scenarios are "normalized" with empty/no-op elements before returning - to the test generation to facilitate brevity when writing scenarios by hand. - NOTE: the main block driver builds a block for the **next** slot, so - the slot transitions are offset by -1 to target certain boundaries. - """ - # go forward 0 or 1 epochs - epochs_set = ( - _epoch_transition(n=0), - _epoch_transition(n=1), - ) - # within those epochs, go forward to: - slots_set = ( - # the first slot in an epoch (see note in docstring about offsets...) - _slot_transition(_last_slot_in_epoch), - # the second slot in an epoch - _slot_transition(n=0), - # some random number of slots, but not at epoch boundaries - _slot_transition(_random_slot_in_epoch(rng)), - # the last slot in an epoch (see note in docstring about offsets...) - _slot_transition(_penultimate_slot_in_epoch), - ) - # and produce a block... - blocks_set = ( - _transition_with_random_block, - ) - # build a set of block transitions from combinations of sub-transitions - transitions_generator = ( - itertools.product(epochs_set, slots_set, blocks_set) for - _ in range(BLOCK_TRANSITIONS_COUNT) - ) - block_transitions = zip(*transitions_generator) - - # and preface each set of block transitions with the possible leak transitions - leak_transitions = ( - _transition_without_leak, - _transition_to_leaking, - ) - scenarios = [ - {"transitions": _flatten(t)} - for t in itertools.product(leak_transitions, block_transitions) - ] - _normalize_scenarios(scenarios) - return scenarios - - -def _id_from_scenario(test_description): - """ - Construct a test name for ``pytest`` infra. - """ - def _to_id_part(prefix, x): - suffix = str(x) - if isinstance(x, Callable): - suffix = x.__name__ - return f"{prefix}{suffix}" - - def _id_from_transition(transition): - return ",".join(( - _to_id_part("epochs:", transition["epochs_to_skip"]), - _to_id_part("slots:", transition["slots_to_skip"]), - _to_id_part("with-block:", transition["block_producer"]) - )) - - return "|".join(map(_id_from_transition, test_description["transitions"])) - +from eth2spec.test.utils.random import ( + generate_randomized_tests, + pytest_generate_tests_adapter, + run_generated_randomized_test, +) def pytest_generate_tests(metafunc): """ Pytest hook to generate test cases from dynamically computed data """ - generated_name = "test_description" - generated_values = _generate_randomized_scenarios() - metafunc.parametrize(generated_name, generated_values, ids=_id_from_scenario, scope="module") - - -def pytest_generate_tests_adapter(f): - """ - Adapter decorator to allow dynamic test case generation - while leveraging existing decorators specific to spec tests. - """ - def wrapper(test_description, *args, **kwargs): - kwargs["test_description"] = test_description - f(*args, **kwargs) - return wrapper - - -def _iter_temporal(spec, callable_or_int): - """ - Intended to advance some number of {epochs, slots}. - Caller can provide a constant integer or a callable deriving a number from - the ``spec`` under consideration. - """ - numeric = callable_or_int - if isinstance(callable_or_int, Callable): - numeric = callable_or_int(spec) - for i in range(numeric): - yield i + generate_randomized_tests(metafunc) @pytest_generate_tests_adapter -@with_phases([PHASE0, ALTAIR]) +@with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, threshold_fn=zero_activation_threshold @@ -395,27 +33,4 @@ def _iter_temporal(spec, callable_or_int): @single_phase @always_bls def test_harness_for_randomized_blocks(spec, state, test_description): - for mutation, validation in test_description["setup"]: - mutation(spec, state) - validation(spec, state) - - yield "pre", state - - blocks = [] - for transition in test_description["transitions"]: - epochs_to_skip = _iter_temporal(spec, transition["epochs_to_skip"]) - for _ in epochs_to_skip: - next_epoch(spec, state) - slots_to_skip = _iter_temporal(spec, transition["slots_to_skip"]) - for _ in slots_to_skip: - next_slot(spec, state) - - block = transition["block_producer"](spec, state, blocks) - if block: - signed_block = state_transition_and_sign_block(spec, state, block) - blocks.append(signed_block) - - assert transition["validation"](spec, state) - - yield "blocks", blocks - yield "post", state + yield from run_generated_randomized_test(spec, state, test_description) diff --git a/tests/core/pyspec/eth2spec/test/utils/__init__.py b/tests/core/pyspec/eth2spec/test/utils/__init__.py new file mode 100644 index 000000000..56e4d44ca --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/utils/__init__.py @@ -0,0 +1,5 @@ +from .utils import ( + vector_test, + with_meta_tags, + build_transition_test, +) diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py new file mode 100644 index 000000000..f28f7ff70 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -0,0 +1,398 @@ +""" +Utility code to generate randomized block tests +""" + +import itertools +import random +import warnings +from typing import Callable +from eth2spec.test.helpers.multi_operations import ( + build_random_block_from_state_for_next_slot, +) +from eth2spec.test.helpers.state import ( + next_slot, + next_epoch, + ensure_state_has_validators_across_lifecycle, + state_transition_and_sign_block, +) +from eth2spec.test.helpers.random import ( + randomize_state, +) + +rng = random.Random(1337) + +def _warn_if_empty_operations(block): + if len(block.body.deposits) == 0: + warnings.warn(f"deposits missing in block at slot {block.slot}") + + if len(block.body.proposer_slashings) == 0: + warnings.warn(f"proposer slashings missing in block at slot {block.slot}") + + if len(block.body.attester_slashings) == 0: + warnings.warn(f"attester slashings missing in block at slot {block.slot}") + + if len(block.body.attestations) == 0: + warnings.warn(f"attestations missing in block at slot {block.slot}") + + if len(block.body.voluntary_exits) == 0: + warnings.warn(f"voluntary exits missing in block at slot {block.slot}") + + +# May need to make several attempts to find a block that does not correspond to a slashed +# proposer with the randomization helpers... +BLOCK_ATTEMPTS = 32 +# Ensure this many blocks are present in *each* randomized scenario +BLOCK_TRANSITIONS_COUNT = 2 + +# primitives +## state + +def _randomize_state(spec, state): + return randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) + + +## epochs + +def _epochs_until_leak(spec): + """ + State is "leaking" if the current epoch is at least + this value after the last finalized epoch. + """ + return spec.MIN_EPOCHS_TO_INACTIVITY_PENALTY + 1 + + +def _epochs_for_shard_committee_period(spec): + return spec.config.SHARD_COMMITTEE_PERIOD + + +## slots + +def _last_slot_in_epoch(spec): + return spec.SLOTS_PER_EPOCH - 1 + + +def _random_slot_in_epoch(rng): + def _a_slot_in_epoch(spec): + return rng.randrange(1, spec.SLOTS_PER_EPOCH - 2) + return _a_slot_in_epoch + + +def _penultimate_slot_in_epoch(spec): + return spec.SLOTS_PER_EPOCH - 2 + + +## blocks + +def _no_block(_spec, _pre_state, _signed_blocks): + return None + + +def _random_block(spec, state, _signed_blocks): + """ + Produce a random block. + NOTE: this helper may mutate state, as it will attempt + to produce a block over ``BLOCK_ATTEMPTS`` slots in order + to find a valid block in the event that the proposer has already been slashed. + """ + temp_state = state.copy() + next_slot(spec, temp_state) + for _ in range(BLOCK_ATTEMPTS): + proposer_index = spec.get_beacon_proposer_index(temp_state) + proposer = state.validators[proposer_index] + if proposer.slashed: + next_slot(spec, state) + next_slot(spec, temp_state) + else: + block = build_random_block_from_state_for_next_slot(spec, state) + _warn_if_empty_operations(block) + return block + else: + raise AssertionError("could not find a block with an unslashed proposer, check ``state`` input") + + +## validations + +def _no_op_validation(spec, state): + return True + + +def _validate_is_leaking(spec, state): + return spec.is_in_inactivity_leak(state) + + +def _validate_is_not_leaking(spec, state): + return not _validate_is_leaking(spec, state) + + +# transitions + +def _with_validation(transition, validation): + if isinstance(transition, Callable): + transition = transition() + transition["validation"] = validation + return transition + + +def _no_op_transition(): + return {} + + +def _epoch_transition(n=0): + return { + "epochs_to_skip": n, + } + + +def _slot_transition(n=0): + return { + "slots_to_skip": n, + } + + +def _transition_to_leaking(): + return { + "epochs_to_skip": _epochs_until_leak, + "validation": _validate_is_leaking, + } + + +_transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) + +## block transitions + +def _transition_with_random_block(block_randomizer): + """ + Build a block transition with randomized data. + Provide optional sub-transitions to advance some + number of epochs or slots before applying the random block. + """ + return { + "block_producer": block_randomizer, + } + + +# setup and test gen + +def _randomized_scenario_setup(state_randomizer): + """ + Return a sequence of pairs of ("mutator", "validator"), + a function that accepts (spec, state) arguments and performs some change + and a function that accepts (spec, state) arguments and validates some change was made. + """ + def _skip_epochs(epoch_producer): + def f(spec, state): + """ + The unoptimized spec implementation is too slow to advance via ``next_epoch``. + Instead, just overwrite the ``state.slot`` and continue... + """ + epochs_to_skip = epoch_producer(spec) + slots_to_skip = epochs_to_skip * spec.SLOTS_PER_EPOCH + state.slot += slots_to_skip + return f + + def _simulate_honest_execution(spec, state): + """ + Want to start tests not in a leak state; the finality data + may not reflect this condition with prior (arbitrary) mutations, + so this mutator addresses that fact. + """ + state.justification_bits = (True, True, True, True) + previous_epoch = spec.get_previous_epoch(state) + previous_root = spec.get_block_root(state, previous_epoch) + previous_previous_epoch = max(spec.GENESIS_EPOCH, spec.Epoch(previous_epoch - 1)) + previous_previous_root = spec.get_block_root(state, previous_previous_epoch) + state.previous_justified_checkpoint = spec.Checkpoint( + epoch=previous_previous_epoch, + root=previous_previous_root, + ) + state.current_justified_checkpoint = spec.Checkpoint( + epoch=previous_epoch, + root=previous_root, + ) + state.finalized_checkpoint = spec.Checkpoint( + epoch=previous_previous_epoch, + root=previous_previous_root, + ) + + return ( + # NOTE: the block randomization function assumes at least 1 shard committee period + # so advance the state before doing anything else. + (_skip_epochs(_epochs_for_shard_committee_period), _no_op_validation), + (_simulate_honest_execution, _no_op_validation), + (state_randomizer, ensure_state_has_validators_across_lifecycle), + ) + + +def _normalize_transition(transition): + """ + Provide "empty" or "no op" sub-transitions + to a given transition. + """ + if isinstance(transition, Callable): + transition = transition() + if "epochs_to_skip" not in transition: + transition["epochs_to_skip"] = 0 + if "slots_to_skip" not in transition: + transition["slots_to_skip"] = 0 + if "block_producer" not in transition: + transition["block_producer"] = _no_block + if "validation" not in transition: + transition["validation"] = _no_op_validation + return transition + + +def _normalize_scenarios(scenarios, state_randomizer): + """ + "Normalize" a "scenario" so that a producer of a test case + does not need to provide every expected key/value. + """ + for scenario in scenarios: + if "setup" not in scenario: + scenario["setup"] = _randomized_scenario_setup(state_randomizer) + + transitions = scenario["transitions"] + for i, transition in enumerate(transitions): + transitions[i] = _normalize_transition(transition) + + +def _flatten(t): + leak_transition = t[0] + result = [leak_transition] + for transition_batch in t[1]: + for transition in transition_batch: + result.append(transition) + return result + + +def _generate_randomized_scenarios(state_randomizer, block_randomizer): + """ + Generates a set of randomized testing scenarios. + Return a sequence of "scenarios" where each scenario: + 1. Provides some setup + 2. Provides a sequence of transitions that mutate the state in some way, + possibly yielding blocks along the way + NOTE: scenarios are "normalized" with empty/no-op elements before returning + to the test generation to facilitate brevity when writing scenarios by hand. + NOTE: the main block driver builds a block for the **next** slot, so + the slot transitions are offset by -1 to target certain boundaries. + """ + # go forward 0 or 1 epochs + epochs_set = ( + _epoch_transition(n=0), + _epoch_transition(n=1), + ) + # within those epochs, go forward to: + slots_set = ( + # the first slot in an epoch (see note in docstring about offsets...) + _slot_transition(_last_slot_in_epoch), + # the second slot in an epoch + _slot_transition(n=0), + # some random number of slots, but not at epoch boundaries + _slot_transition(_random_slot_in_epoch(rng)), + # the last slot in an epoch (see note in docstring about offsets...) + _slot_transition(_penultimate_slot_in_epoch), + ) + # and produce a block... + blocks_set = ( + _transition_with_random_block(block_randomizer), + ) + # build a set of block transitions from combinations of sub-transitions + transitions_generator = ( + itertools.product(epochs_set, slots_set, blocks_set) for + _ in range(BLOCK_TRANSITIONS_COUNT) + ) + block_transitions = zip(*transitions_generator) + + # and preface each set of block transitions with the possible leak transitions + leak_transitions = ( + _transition_without_leak, + _transition_to_leaking, + ) + scenarios = [ + {"transitions": _flatten(t)} + for t in itertools.product(leak_transitions, block_transitions) + ] + _normalize_scenarios(scenarios, state_randomizer) + return scenarios + + +def _id_from_scenario(test_description): + """ + Construct a test name for ``pytest`` infra. + """ + def _to_id_part(prefix, x): + suffix = str(x) + if isinstance(x, Callable): + suffix = x.__name__ + return f"{prefix}{suffix}" + + def _id_from_transition(transition): + return ",".join(( + _to_id_part("epochs:", transition["epochs_to_skip"]), + _to_id_part("slots:", transition["slots_to_skip"]), + _to_id_part("with-block:", transition["block_producer"]) + )) + + return "|".join(map(_id_from_transition, test_description["transitions"])) + +# Generate a series of randomized block tests: + +def generate_randomized_tests(metafunc, state_randomizer=_randomize_state, block_randomizer=_random_block): + """ + Pytest hook to generate test cases from dynamically computed data + """ + generated_name = "test_description" + generated_values = _generate_randomized_scenarios(state_randomizer, block_randomizer) + metafunc.parametrize(generated_name, generated_values, ids=_id_from_scenario, scope="module") + + +def pytest_generate_tests_adapter(f): + """ + Adapter decorator to allow dynamic test case generation + while leveraging existing decorators specific to spec tests. + """ + def wrapper(test_description, *args, **kwargs): + kwargs["test_description"] = test_description + f(*args, **kwargs) + return wrapper + +# Run the generated tests: + +def _iter_temporal(spec, callable_or_int): + """ + Intended to advance some number of {epochs, slots}. + Caller can provide a constant integer or a callable deriving a number from + the ``spec`` under consideration. + """ + numeric = callable_or_int + if isinstance(callable_or_int, Callable): + numeric = callable_or_int(spec) + for i in range(numeric): + yield i + + +def run_generated_randomized_test(spec, state, test_description): + for mutation, validation in test_description["setup"]: + mutation(spec, state) + validation(spec, state) + + yield "pre", state + + blocks = [] + for transition in test_description["transitions"]: + epochs_to_skip = _iter_temporal(spec, transition["epochs_to_skip"]) + for _ in epochs_to_skip: + next_epoch(spec, state) + slots_to_skip = _iter_temporal(spec, transition["slots_to_skip"]) + for _ in slots_to_skip: + next_slot(spec, state) + + block = transition["block_producer"](spec, state, blocks) + if block: + signed_block = state_transition_and_sign_block(spec, state, block) + blocks.append(signed_block) + + assert transition["validation"](spec, state) + + yield "blocks", blocks + yield "post", state diff --git a/tests/core/pyspec/eth2spec/test/utils.py b/tests/core/pyspec/eth2spec/test/utils/utils.py similarity index 100% rename from tests/core/pyspec/eth2spec/test/utils.py rename to tests/core/pyspec/eth2spec/test/utils/utils.py From ff6863e6899a92c89006d985625587ef6da4ac68 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 12:01:05 -0700 Subject: [PATCH 035/122] fix bug with deposit generation code --- tests/core/pyspec/eth2spec/test/helpers/multi_operations.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 52234fa97..32998b3ba 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -103,6 +103,7 @@ def prepare_state_and_get_random_deposits(spec, state, rng): deposits = [] # First build deposit data leaves + root = None for i in range(num_deposits): index = len(state.validators) + i _, root, deposit_data_leaves = build_deposit( @@ -115,7 +116,9 @@ def prepare_state_and_get_random_deposits(spec, state, rng): signed=True, ) - state.eth1_data.deposit_root = root + if root: + # NOTE: if ``num_deposits == 0``, ``root`` is never assigned to + state.eth1_data.deposit_root = root state.eth1_data.deposit_count += num_deposits # Then for that context, build deposits/proofs From 7b9d70fcec86f82a33256c6fa52bcab6e8cfce07 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 12:15:09 -0700 Subject: [PATCH 036/122] allow test customization (for future forks) --- tests/core/pyspec/eth2spec/test/utils/random.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py index f28f7ff70..b50a67349 100644 --- a/tests/core/pyspec/eth2spec/test/utils/random.py +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -16,7 +16,7 @@ from eth2spec.test.helpers.state import ( state_transition_and_sign_block, ) from eth2spec.test.helpers.random import ( - randomize_state, + randomize_state as randomize_state_helper, ) rng = random.Random(1337) @@ -47,8 +47,8 @@ BLOCK_TRANSITIONS_COUNT = 2 # primitives ## state -def _randomize_state(spec, state): - return randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) +def randomize_state(spec, state): + randomize_state_helper(spec, state, exit_fraction=0.1, slash_fraction=0.1) ## epochs @@ -87,7 +87,7 @@ def _no_block(_spec, _pre_state, _signed_blocks): return None -def _random_block(spec, state, _signed_blocks): +def random_block(spec, state, _signed_blocks): """ Produce a random block. NOTE: this helper may mutate state, as it will attempt @@ -337,7 +337,7 @@ def _id_from_scenario(test_description): # Generate a series of randomized block tests: -def generate_randomized_tests(metafunc, state_randomizer=_randomize_state, block_randomizer=_random_block): +def generate_randomized_tests(metafunc, state_randomizer=randomize_state, block_randomizer=random_block): """ Pytest hook to generate test cases from dynamically computed data """ From 58c6f33e8522a176b2065bec9e21aa5fce1ffe6b Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 12:15:22 -0700 Subject: [PATCH 037/122] ensure at least one proposer slashing --- tests/core/pyspec/eth2spec/test/helpers/multi_operations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 32998b3ba..68ca02b91 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -44,7 +44,7 @@ def run_slash_and_exit(spec, state, slash_index, exit_index, valid=True): def get_random_proposer_slashings(spec, state, rng): - num_slashings = rng.randrange(spec.MAX_PROPOSER_SLASHINGS) + num_slashings = max(1, rng.randrange(spec.MAX_PROPOSER_SLASHINGS)) active_indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() indices = [ index for index in active_indices From cc04da8e795ca9d8774f033434765e5be2edafe6 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 12:30:05 -0700 Subject: [PATCH 038/122] add randomized block tests for altair --- .../test/altair/sanity/test_blocks_random.py | 63 +++++++++++++++++++ .../eth2spec/test/helpers/multi_operations.py | 20 ++++++ .../core/pyspec/eth2spec/test/utils/random.py | 4 +- tests/generators/sanity/main.py | 1 + 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py diff --git a/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py new file mode 100644 index 000000000..b0c0e86b5 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py @@ -0,0 +1,63 @@ +from tests.core.pyspec.eth2spec.test.helpers.constants import ALTAIR +from tests.core.pyspec.eth2spec.test.context import ( + misc_balances_in_default_range_with_many_validators, + with_phases, + zero_activation_threshold, +) +from eth2spec.test.helpers.multi_operations import ( + get_random_sync_aggregate, +) +from eth2spec.test.helpers.inactivity_scores import ( + randomize_inactivity_scores, +) +from eth2spec.test.context import ( + always_bls, + spec_test, + with_custom_state, + single_phase, +) +from eth2spec.test.utils.random import ( + generate_randomized_tests, + pytest_generate_tests_adapter, + run_generated_randomized_test, + random_block, + randomize_state, +) + +SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4 + +def _randomize_altair_state(spec, state): + randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) + randomize_inactivity_scores(spec, state) + + +def _randomize_altair_block(spec, state, signed_blocks): + block = random_block(spec, state, signed_blocks) + fraction_missed = len(signed_blocks) / SYNC_AGGREGATE_PARTICIPATION_BUCKETS + fraction_participated = 1.0 - fraction_missed + block.body.sync_aggregate = get_random_sync_aggregate(spec, state, fraction_participated=fraction_participated) + return block + + +def pytest_generate_tests(metafunc): + """ + Pytest hook to generate test cases from dynamically computed data + """ + generate_randomized_tests( + metafunc, + state_randomizer=_randomize_altair_state, + block_randomizer=_randomize_altair_block, + ) + + +@pytest_generate_tests_adapter +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_harness_for_randomized_blocks(spec, state, test_description): + yield from run_generated_randomized_test(spec, state, test_description) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 68ca02b91..10de14253 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -7,6 +7,10 @@ from eth2spec.test.helpers.state import ( from eth2spec.test.helpers.block import ( build_empty_block_for_next_slot, ) +from eth2spec.test.helpers.sync_committee import ( + compute_committee_indices, + compute_aggregate_sync_committee_signature, +) from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing_by_indices from eth2spec.test.helpers.attestations import get_valid_attestation @@ -192,3 +196,19 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): yield 'blocks', [signed_block] yield 'post', state + + +def get_random_sync_aggregate(spec, state, fraction_participated=1.0, rng=Random(2099)): + committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + participant_count = int(len(committee_indices) * fraction_participated) + participants = rng.sample(committee_indices, participant_count) + signature = compute_aggregate_sync_committee_signature( + spec, + state, + state.slot, + participants, + ) + return spec.SyncAggregate( + sync_committee_bits=[index in participants for index in committee_indices], + sync_committee_signature=signature, + ) diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py index b50a67349..5a7067b3f 100644 --- a/tests/core/pyspec/eth2spec/test/utils/random.py +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -47,8 +47,8 @@ BLOCK_TRANSITIONS_COUNT = 2 # primitives ## state -def randomize_state(spec, state): - randomize_state_helper(spec, state, exit_fraction=0.1, slash_fraction=0.1) +def randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1): + randomize_state_helper(spec, state, exit_fraction=exit_fraction, slash_fraction=slash_fraction) ## epochs diff --git a/tests/generators/sanity/main.py b/tests/generators/sanity/main.py index 63efa3897..89e622f1c 100644 --- a/tests/generators/sanity/main.py +++ b/tests/generators/sanity/main.py @@ -10,6 +10,7 @@ if __name__ == "__main__": ]} altair_mods = {**{key: 'eth2spec.test.altair.sanity.test_' + key for key in [ 'blocks', + 'blocks_random', ]}, **phase_0_mods} # also run the previous phase 0 tests # Altair-specific test cases are ignored, but should be included after the Merge is rebased onto Altair work. From d037c6662acb4329269a848af9106a70e8eacb35 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 12:40:42 -0700 Subject: [PATCH 039/122] lint fix --- .../test/altair/sanity/test_blocks_random.py | 1 + .../test/phase0/sanity/test_blocks_random.py | 1 + .../pyspec/eth2spec/test/utils/__init__.py | 7 +++++++ .../core/pyspec/eth2spec/test/utils/random.py | 18 ++++++++++++------ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py index b0c0e86b5..bc391b1f7 100644 --- a/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py @@ -26,6 +26,7 @@ from eth2spec.test.utils.random import ( SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4 + def _randomize_altair_state(spec, state): randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) randomize_inactivity_scores(spec, state) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 6ea793206..1244785cd 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -16,6 +16,7 @@ from eth2spec.test.utils.random import ( run_generated_randomized_test, ) + def pytest_generate_tests(metafunc): """ Pytest hook to generate test cases from dynamically computed data diff --git a/tests/core/pyspec/eth2spec/test/utils/__init__.py b/tests/core/pyspec/eth2spec/test/utils/__init__.py index 56e4d44ca..f6b2a8a44 100644 --- a/tests/core/pyspec/eth2spec/test/utils/__init__.py +++ b/tests/core/pyspec/eth2spec/test/utils/__init__.py @@ -3,3 +3,10 @@ from .utils import ( with_meta_tags, build_transition_test, ) + + +__all__ = [ # avoid "unused import" lint error + "vector_test", + "with_meta_tags", + "build_transition_test", +] diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py index 5a7067b3f..da8e391e8 100644 --- a/tests/core/pyspec/eth2spec/test/utils/random.py +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -21,6 +21,7 @@ from eth2spec.test.helpers.random import ( rng = random.Random(1337) + def _warn_if_empty_operations(block): if len(block.body.deposits) == 0: warnings.warn(f"deposits missing in block at slot {block.slot}") @@ -45,13 +46,14 @@ BLOCK_ATTEMPTS = 32 BLOCK_TRANSITIONS_COUNT = 2 # primitives -## state +# state + def randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1): randomize_state_helper(spec, state, exit_fraction=exit_fraction, slash_fraction=slash_fraction) -## epochs +# epochs def _epochs_until_leak(spec): """ @@ -65,7 +67,7 @@ def _epochs_for_shard_committee_period(spec): return spec.config.SHARD_COMMITTEE_PERIOD -## slots +# slots def _last_slot_in_epoch(spec): return spec.SLOTS_PER_EPOCH - 1 @@ -81,7 +83,7 @@ def _penultimate_slot_in_epoch(spec): return spec.SLOTS_PER_EPOCH - 2 -## blocks +# blocks def _no_block(_spec, _pre_state, _signed_blocks): return None @@ -110,7 +112,7 @@ def random_block(spec, state, _signed_blocks): raise AssertionError("could not find a block with an unslashed proposer, check ``state`` input") -## validations +# validations def _no_op_validation(spec, state): return True @@ -158,7 +160,8 @@ def _transition_to_leaking(): _transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) -## block transitions +# block transitions + def _transition_with_random_block(block_randomizer): """ @@ -173,6 +176,7 @@ def _transition_with_random_block(block_randomizer): # setup and test gen + def _randomized_scenario_setup(state_randomizer): """ Return a sequence of pairs of ("mutator", "validator"), @@ -337,6 +341,7 @@ def _id_from_scenario(test_description): # Generate a series of randomized block tests: + def generate_randomized_tests(metafunc, state_randomizer=randomize_state, block_randomizer=random_block): """ Pytest hook to generate test cases from dynamically computed data @@ -358,6 +363,7 @@ def pytest_generate_tests_adapter(f): # Run the generated tests: + def _iter_temporal(spec, callable_or_int): """ Intended to advance some number of {epochs, slots}. From 505bdba8f8aaa7be89591e28b8fb8e7e83780ca1 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 12:49:36 -0700 Subject: [PATCH 040/122] fix imports --- .../pyspec/eth2spec/test/altair/sanity/test_blocks_random.py | 4 ++-- .../pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py index bc391b1f7..d546588d7 100644 --- a/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py @@ -1,5 +1,5 @@ -from tests.core.pyspec.eth2spec.test.helpers.constants import ALTAIR -from tests.core.pyspec.eth2spec.test.context import ( +from eth2spec.test.helpers.constants import ALTAIR +from eth2spec.test.context import ( misc_balances_in_default_range_with_many_validators, with_phases, zero_activation_threshold, diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 1244785cd..96193c3f9 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,5 +1,5 @@ -from tests.core.pyspec.eth2spec.test.helpers.constants import PHASE0 -from tests.core.pyspec.eth2spec.test.context import ( +from eth2spec.test.helpers.constants import PHASE0 +from eth2spec.test.context import ( misc_balances_in_default_range_with_many_validators, with_phases, zero_activation_threshold, From c27e4d140e444ee3543d3cdd9e1f3a7413c61cfa Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 11:21:14 -0700 Subject: [PATCH 041/122] move to code-gen under new test generator --- .../eth2spec/test/altair/random/__init__.py | 0 .../test/altair/random/test_random.py | 421 ++++++++++++++++++ .../test/altair/sanity/test_blocks_random.py | 64 --- .../eth2spec/test/phase0/random/__init__.py | 0 .../test/phase0/random/test_random.py | 421 ++++++++++++++++++ .../test/phase0/sanity/test_blocks_random.py | 37 -- .../core/pyspec/eth2spec/test/utils/random.py | 273 ++++-------- tests/generators/random/Makefile | 7 + tests/generators/random/README.md | 29 ++ tests/generators/random/generate.py | 243 ++++++++++ tests/generators/random/main.py | 18 + tests/generators/random/requirements.txt | 2 + tests/generators/sanity/main.py | 2 - 13 files changed, 1226 insertions(+), 291 deletions(-) create mode 100644 tests/core/pyspec/eth2spec/test/altair/random/__init__.py create mode 100644 tests/core/pyspec/eth2spec/test/altair/random/test_random.py delete mode 100644 tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py create mode 100644 tests/core/pyspec/eth2spec/test/phase0/random/__init__.py create mode 100644 tests/core/pyspec/eth2spec/test/phase0/random/test_random.py delete mode 100644 tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py create mode 100644 tests/generators/random/Makefile create mode 100644 tests/generators/random/README.md create mode 100644 tests/generators/random/generate.py create mode 100644 tests/generators/random/main.py create mode 100644 tests/generators/random/requirements.txt diff --git a/tests/core/pyspec/eth2spec/test/altair/random/__init__.py b/tests/core/pyspec/eth2spec/test/altair/random/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py new file mode 100644 index 000000000..86f8f97b1 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py @@ -0,0 +1,421 @@ +""" +This module is generated from the ``random`` test generator. +Please do not edit this file manually. +See the README for that generator for more information. +""" + +from eth2spec.test.helpers.constants import ALTAIR +from eth2spec.test.context import ( + misc_balances_in_default_range_with_many_validators, + with_phases, + zero_activation_threshold, +) +from eth2spec.test.context import ( + always_bls, + spec_test, + with_custom_state, + single_phase, +) +from eth2spec.test.utils.random import ( + run_generated_randomized_test, +) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_0(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_1(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_2(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_3(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_4(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_5(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_6(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_7(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_8(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_9(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_10(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_11(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_12(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_13(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_14(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([ALTAIR]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_15(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) diff --git a/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py deleted file mode 100644 index d546588d7..000000000 --- a/tests/core/pyspec/eth2spec/test/altair/sanity/test_blocks_random.py +++ /dev/null @@ -1,64 +0,0 @@ -from eth2spec.test.helpers.constants import ALTAIR -from eth2spec.test.context import ( - misc_balances_in_default_range_with_many_validators, - with_phases, - zero_activation_threshold, -) -from eth2spec.test.helpers.multi_operations import ( - get_random_sync_aggregate, -) -from eth2spec.test.helpers.inactivity_scores import ( - randomize_inactivity_scores, -) -from eth2spec.test.context import ( - always_bls, - spec_test, - with_custom_state, - single_phase, -) -from eth2spec.test.utils.random import ( - generate_randomized_tests, - pytest_generate_tests_adapter, - run_generated_randomized_test, - random_block, - randomize_state, -) - -SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4 - - -def _randomize_altair_state(spec, state): - randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) - randomize_inactivity_scores(spec, state) - - -def _randomize_altair_block(spec, state, signed_blocks): - block = random_block(spec, state, signed_blocks) - fraction_missed = len(signed_blocks) / SYNC_AGGREGATE_PARTICIPATION_BUCKETS - fraction_participated = 1.0 - fraction_missed - block.body.sync_aggregate = get_random_sync_aggregate(spec, state, fraction_participated=fraction_participated) - return block - - -def pytest_generate_tests(metafunc): - """ - Pytest hook to generate test cases from dynamically computed data - """ - generate_randomized_tests( - metafunc, - state_randomizer=_randomize_altair_state, - block_randomizer=_randomize_altair_block, - ) - - -@pytest_generate_tests_adapter -@with_phases([ALTAIR]) -@with_custom_state( - balances_fn=misc_balances_in_default_range_with_many_validators, - threshold_fn=zero_activation_threshold -) -@spec_test -@single_phase -@always_bls -def test_harness_for_randomized_blocks(spec, state, test_description): - yield from run_generated_randomized_test(spec, state, test_description) diff --git a/tests/core/pyspec/eth2spec/test/phase0/random/__init__.py b/tests/core/pyspec/eth2spec/test/phase0/random/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py new file mode 100644 index 000000000..bfa93330f --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py @@ -0,0 +1,421 @@ +""" +This module is generated from the ``random`` test generator. +Please do not edit this file manually. +See the README for that generator for more information. +""" + +from eth2spec.test.helpers.constants import PHASE0 +from eth2spec.test.context import ( + misc_balances_in_default_range_with_many_validators, + with_phases, + zero_activation_threshold, +) +from eth2spec.test.context import ( + always_bls, + spec_test, + with_custom_state, + single_phase, +) +from eth2spec.test.utils.random import ( + run_generated_randomized_test, +) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_0(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_1(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_2(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_3(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_4(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_5(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_6(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_7(spec, state): + # scenario as high-level, informal text: + # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_8(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_9(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_10(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_11(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_12(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_13(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_14(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) + + +@with_phases([PHASE0]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_15(spec, state): + # scenario as high-level, informal text: + # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + yield from run_generated_randomized_test( + spec, + state, + scenario, + ) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py deleted file mode 100644 index 96193c3f9..000000000 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ /dev/null @@ -1,37 +0,0 @@ -from eth2spec.test.helpers.constants import PHASE0 -from eth2spec.test.context import ( - misc_balances_in_default_range_with_many_validators, - with_phases, - zero_activation_threshold, -) -from eth2spec.test.context import ( - always_bls, - spec_test, - with_custom_state, - single_phase, -) -from eth2spec.test.utils.random import ( - generate_randomized_tests, - pytest_generate_tests_adapter, - run_generated_randomized_test, -) - - -def pytest_generate_tests(metafunc): - """ - Pytest hook to generate test cases from dynamically computed data - """ - generate_randomized_tests(metafunc) - - -@pytest_generate_tests_adapter -@with_phases([PHASE0]) -@with_custom_state( - balances_fn=misc_balances_in_default_range_with_many_validators, - threshold_fn=zero_activation_threshold -) -@spec_test -@single_phase -@always_bls -def test_harness_for_randomized_blocks(spec, state, test_description): - yield from run_generated_randomized_test(spec, state, test_description) diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py index da8e391e8..b12fca96b 100644 --- a/tests/core/pyspec/eth2spec/test/utils/random.py +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -2,12 +2,20 @@ Utility code to generate randomized block tests """ -import itertools -import random +import sys import warnings +from random import Random from typing import Callable + from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state_for_next_slot, + get_random_sync_aggregate, +) +from eth2spec.test.helpers.inactivity_scores import ( + randomize_inactivity_scores, +) +from eth2spec.test.helpers.random import ( + randomize_state as randomize_state_helper, ) from eth2spec.test.helpers.state import ( next_slot, @@ -15,37 +23,8 @@ from eth2spec.test.helpers.state import ( ensure_state_has_validators_across_lifecycle, state_transition_and_sign_block, ) -from eth2spec.test.helpers.random import ( - randomize_state as randomize_state_helper, -) -rng = random.Random(1337) - - -def _warn_if_empty_operations(block): - if len(block.body.deposits) == 0: - warnings.warn(f"deposits missing in block at slot {block.slot}") - - if len(block.body.proposer_slashings) == 0: - warnings.warn(f"proposer slashings missing in block at slot {block.slot}") - - if len(block.body.attester_slashings) == 0: - warnings.warn(f"attester slashings missing in block at slot {block.slot}") - - if len(block.body.attestations) == 0: - warnings.warn(f"attestations missing in block at slot {block.slot}") - - if len(block.body.voluntary_exits) == 0: - warnings.warn(f"voluntary exits missing in block at slot {block.slot}") - - -# May need to make several attempts to find a block that does not correspond to a slashed -# proposer with the randomization helpers... -BLOCK_ATTEMPTS = 32 -# Ensure this many blocks are present in *each* randomized scenario -BLOCK_TRANSITIONS_COUNT = 2 - -# primitives +# primitives: # state @@ -53,6 +32,11 @@ def randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1): randomize_state_helper(spec, state, exit_fraction=exit_fraction, slash_fraction=slash_fraction) +def randomize_state_altair(spec, state): + randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) + randomize_inactivity_scores(spec, state) + + # epochs def _epochs_until_leak(spec): @@ -69,26 +53,46 @@ def _epochs_for_shard_committee_period(spec): # slots -def _last_slot_in_epoch(spec): +def last_slot_in_epoch(spec): return spec.SLOTS_PER_EPOCH - 1 -def _random_slot_in_epoch(rng): - def _a_slot_in_epoch(spec): - return rng.randrange(1, spec.SLOTS_PER_EPOCH - 2) - return _a_slot_in_epoch +def random_slot_in_epoch(spec, rng=Random(1336)): + return rng.randrange(1, spec.SLOTS_PER_EPOCH - 2) -def _penultimate_slot_in_epoch(spec): +def penultimate_slot_in_epoch(spec): return spec.SLOTS_PER_EPOCH - 2 # blocks -def _no_block(_spec, _pre_state, _signed_blocks): +def no_block(_spec, _pre_state, _signed_blocks): return None +# May need to make several attempts to find a block that does not correspond to a slashed +# proposer with the randomization helpers... +BLOCK_ATTEMPTS = 32 + + +def _warn_if_empty_operations(block): + if len(block.body.deposits) == 0: + warnings.warn(f"deposits missing in block at slot {block.slot}") + + if len(block.body.proposer_slashings) == 0: + warnings.warn(f"proposer slashings missing in block at slot {block.slot}") + + if len(block.body.attester_slashings) == 0: + warnings.warn(f"attester slashings missing in block at slot {block.slot}") + + if len(block.body.attestations) == 0: + warnings.warn(f"attestations missing in block at slot {block.slot}") + + if len(block.body.voluntary_exits) == 0: + warnings.warn(f"voluntary exits missing in block at slot {block.slot}") + + def random_block(spec, state, _signed_blocks): """ Produce a random block. @@ -112,9 +116,20 @@ def random_block(spec, state, _signed_blocks): raise AssertionError("could not find a block with an unslashed proposer, check ``state`` input") +SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4 + + +def random_block_altair(spec, state, signed_blocks): + block = random_block(spec, state, signed_blocks) + fraction_missed = len(signed_blocks) / SYNC_AGGREGATE_PARTICIPATION_BUCKETS + fraction_participated = 1.0 - fraction_missed + block.body.sync_aggregate = get_random_sync_aggregate(spec, state, fraction_participated=fraction_participated) + return block + + # validations -def _no_op_validation(spec, state): +def no_op_validation(spec, state): return True @@ -139,31 +154,31 @@ def _no_op_transition(): return {} -def _epoch_transition(n=0): +def epoch_transition(n=0): return { "epochs_to_skip": n, } -def _slot_transition(n=0): +def slot_transition(n=0): return { "slots_to_skip": n, } -def _transition_to_leaking(): +def transition_to_leaking(): return { "epochs_to_skip": _epochs_until_leak, "validation": _validate_is_leaking, } -_transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) +transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) # block transitions -def _transition_with_random_block(block_randomizer): +def transition_with_random_block(block_randomizer): """ Build a block transition with randomized data. Provide optional sub-transitions to advance some @@ -221,163 +236,43 @@ def _randomized_scenario_setup(state_randomizer): return ( # NOTE: the block randomization function assumes at least 1 shard committee period # so advance the state before doing anything else. - (_skip_epochs(_epochs_for_shard_committee_period), _no_op_validation), - (_simulate_honest_execution, _no_op_validation), + (_skip_epochs(_epochs_for_shard_committee_period), no_op_validation), + (_simulate_honest_execution, no_op_validation), (state_randomizer, ensure_state_has_validators_across_lifecycle), ) - -def _normalize_transition(transition): - """ - Provide "empty" or "no op" sub-transitions - to a given transition. - """ - if isinstance(transition, Callable): - transition = transition() - if "epochs_to_skip" not in transition: - transition["epochs_to_skip"] = 0 - if "slots_to_skip" not in transition: - transition["slots_to_skip"] = 0 - if "block_producer" not in transition: - transition["block_producer"] = _no_block - if "validation" not in transition: - transition["validation"] = _no_op_validation - return transition - - -def _normalize_scenarios(scenarios, state_randomizer): - """ - "Normalize" a "scenario" so that a producer of a test case - does not need to provide every expected key/value. - """ - for scenario in scenarios: - if "setup" not in scenario: - scenario["setup"] = _randomized_scenario_setup(state_randomizer) - - transitions = scenario["transitions"] - for i, transition in enumerate(transitions): - transitions[i] = _normalize_transition(transition) - - -def _flatten(t): - leak_transition = t[0] - result = [leak_transition] - for transition_batch in t[1]: - for transition in transition_batch: - result.append(transition) - return result - - -def _generate_randomized_scenarios(state_randomizer, block_randomizer): - """ - Generates a set of randomized testing scenarios. - Return a sequence of "scenarios" where each scenario: - 1. Provides some setup - 2. Provides a sequence of transitions that mutate the state in some way, - possibly yielding blocks along the way - NOTE: scenarios are "normalized" with empty/no-op elements before returning - to the test generation to facilitate brevity when writing scenarios by hand. - NOTE: the main block driver builds a block for the **next** slot, so - the slot transitions are offset by -1 to target certain boundaries. - """ - # go forward 0 or 1 epochs - epochs_set = ( - _epoch_transition(n=0), - _epoch_transition(n=1), - ) - # within those epochs, go forward to: - slots_set = ( - # the first slot in an epoch (see note in docstring about offsets...) - _slot_transition(_last_slot_in_epoch), - # the second slot in an epoch - _slot_transition(n=0), - # some random number of slots, but not at epoch boundaries - _slot_transition(_random_slot_in_epoch(rng)), - # the last slot in an epoch (see note in docstring about offsets...) - _slot_transition(_penultimate_slot_in_epoch), - ) - # and produce a block... - blocks_set = ( - _transition_with_random_block(block_randomizer), - ) - # build a set of block transitions from combinations of sub-transitions - transitions_generator = ( - itertools.product(epochs_set, slots_set, blocks_set) for - _ in range(BLOCK_TRANSITIONS_COUNT) - ) - block_transitions = zip(*transitions_generator) - - # and preface each set of block transitions with the possible leak transitions - leak_transitions = ( - _transition_without_leak, - _transition_to_leaking, - ) - scenarios = [ - {"transitions": _flatten(t)} - for t in itertools.product(leak_transitions, block_transitions) - ] - _normalize_scenarios(scenarios, state_randomizer) - return scenarios - - -def _id_from_scenario(test_description): - """ - Construct a test name for ``pytest`` infra. - """ - def _to_id_part(prefix, x): - suffix = str(x) - if isinstance(x, Callable): - suffix = x.__name__ - return f"{prefix}{suffix}" - - def _id_from_transition(transition): - return ",".join(( - _to_id_part("epochs:", transition["epochs_to_skip"]), - _to_id_part("slots:", transition["slots_to_skip"]), - _to_id_part("with-block:", transition["block_producer"]) - )) - - return "|".join(map(_id_from_transition, test_description["transitions"])) - -# Generate a series of randomized block tests: - - -def generate_randomized_tests(metafunc, state_randomizer=randomize_state, block_randomizer=random_block): - """ - Pytest hook to generate test cases from dynamically computed data - """ - generated_name = "test_description" - generated_values = _generate_randomized_scenarios(state_randomizer, block_randomizer) - metafunc.parametrize(generated_name, generated_values, ids=_id_from_scenario, scope="module") - - -def pytest_generate_tests_adapter(f): - """ - Adapter decorator to allow dynamic test case generation - while leveraging existing decorators specific to spec tests. - """ - def wrapper(test_description, *args, **kwargs): - kwargs["test_description"] = test_description - f(*args, **kwargs) - return wrapper - # Run the generated tests: -def _iter_temporal(spec, callable_or_int): +# while the test implementation works via code-gen, +# references to helper code in this module are serialized as str names. +# to resolve this references at runtime, we need a reference to this module: +_this_module = sys.modules[__name__] + +def _resolve_ref(ref): + if isinstance(ref, str): + return getattr(_this_module, ref) + return ref + + +def _iter_temporal(spec, description): """ Intended to advance some number of {epochs, slots}. Caller can provide a constant integer or a callable deriving a number from the ``spec`` under consideration. """ - numeric = callable_or_int - if isinstance(callable_or_int, Callable): - numeric = callable_or_int(spec) + numeric = _resolve_ref(description) + if isinstance(numeric, Callable): + numeric = numeric(spec) for i in range(numeric): yield i def run_generated_randomized_test(spec, state, test_description): + if "setup" not in test_description: + state_randomizer = _resolve_ref(test_description.get("state_randomizer", randomize_state)) + test_description["setup"] = _randomized_scenario_setup(state_randomizer) + for mutation, validation in test_description["setup"]: mutation(spec, state) validation(spec, state) @@ -393,12 +288,14 @@ def run_generated_randomized_test(spec, state, test_description): for _ in slots_to_skip: next_slot(spec, state) - block = transition["block_producer"](spec, state, blocks) + block_producer = _resolve_ref(transition["block_producer"]) + block = block_producer(spec, state, blocks) if block: signed_block = state_transition_and_sign_block(spec, state, block) blocks.append(signed_block) - assert transition["validation"](spec, state) + validation = _resolve_ref(transition["validation"]) + assert validation(spec, state) yield "blocks", blocks yield "post", state diff --git a/tests/generators/random/Makefile b/tests/generators/random/Makefile new file mode 100644 index 000000000..a3c845243 --- /dev/null +++ b/tests/generators/random/Makefile @@ -0,0 +1,7 @@ +all: + . ./venv/bin/activate + pip install -r requirements.txt + rm -f ../../core/pyspec/eth2spec/test/phase0/random/test_random.py + rm -f ../../core/pyspec/eth2spec/test/altair/random/test_random.py + python generate.py phase0 > ../../core/pyspec/eth2spec/test/phase0/random/test_random.py + python generate.py altair > ../../core/pyspec/eth2spec/test/altair/random/test_random.py diff --git a/tests/generators/random/README.md b/tests/generators/random/README.md new file mode 100644 index 000000000..e1942b7f4 --- /dev/null +++ b/tests/generators/random/README.md @@ -0,0 +1,29 @@ +# Randomized tests + +Randomized tests in the format of `sanity` tests, with randomized operations. + +Information on the format of the tests can be found in the [sanity test formats documentation](../../formats/sanity/README.md). + +# To generate test sources + +```bash +$ make +``` + +The necessary commands are in the `Makefile`, as the only target. + +The generated files are committed to the repo so you should not need to do this. + +# To run tests + +Use the usual `pytest` mechanics used elsewhere in this repo. + +# To generate spec tests (from the generated files) + +Run the test generator in the usual way. + +E.g. from the root of this repo, you can run: + +```bash +$ make gen_random +``` diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py new file mode 100644 index 000000000..b31aac6a3 --- /dev/null +++ b/tests/generators/random/generate.py @@ -0,0 +1,243 @@ +""" +This test format currently uses code generation to assemble the tests +as the current test infra does not have a facility to dynamically +generate tests that can be seen by ``pytest``. + +This will likley change in future releases of the testing infra. + +NOTE: To add additional scenarios, add test cases below in ``_generate_randomized_scenarios``. +""" + +import sys +import warnings +from typing import Callable +import itertools + +from eth2spec.test.utils.random import ( + no_block, + no_op_validation, + randomize_state, + randomize_state_altair, + random_block, + random_block_altair, + last_slot_in_epoch, + random_slot_in_epoch, + penultimate_slot_in_epoch, + epoch_transition, + slot_transition, + transition_with_random_block, + transition_to_leaking, + transition_without_leak, +) +from eth2spec.test.helpers.constants import PHASE0, ALTAIR + + +# Ensure this many blocks are present in *each* randomized scenario +BLOCK_TRANSITIONS_COUNT = 2 + + +def _normalize_transition(transition): + """ + Provide "empty" or "no op" sub-transitions + to a given transition. + """ + if isinstance(transition, Callable): + transition = transition() + if "epochs_to_skip" not in transition: + transition["epochs_to_skip"] = 0 + if "slots_to_skip" not in transition: + transition["slots_to_skip"] = 0 + if "block_producer" not in transition: + transition["block_producer"] = no_block + if "validation" not in transition: + transition["validation"] = no_op_validation + return transition + + +def _normalize_scenarios(scenarios): + """ + "Normalize" a "scenario" so that a producer of a test case + does not need to provide every expected key/value. + """ + for scenario in scenarios: + transitions = scenario["transitions"] + for i, transition in enumerate(transitions): + transitions[i] = _normalize_transition(transition) + + +def _flatten(t): + leak_transition = t[0] + result = [leak_transition] + for transition_batch in t[1]: + for transition in transition_batch: + result.append(transition) + return result + + +def _generate_randomized_scenarios(block_randomizer): + """ + Generates a set of randomized testing scenarios. + Return a sequence of "scenarios" where each scenario: + 1. Provides some setup + 2. Provides a sequence of transitions that mutate the state in some way, + possibly yielding blocks along the way + NOTE: scenarios are "normalized" with empty/no-op elements before returning + to the test generation to facilitate brevity when writing scenarios by hand. + NOTE: the main block driver builds a block for the **next** slot, so + the slot transitions are offset by -1 to target certain boundaries. + """ + # go forward 0 or 1 epochs + epochs_set = ( + epoch_transition(n=0), + epoch_transition(n=1), + ) + # within those epochs, go forward to: + slots_set = ( + # the first slot in an epoch (see note in docstring about offsets...) + slot_transition(last_slot_in_epoch), + # the second slot in an epoch + slot_transition(n=0), + # some random number of slots, but not at epoch boundaries + slot_transition(random_slot_in_epoch), + # the last slot in an epoch (see note in docstring about offsets...) + slot_transition(penultimate_slot_in_epoch), + ) + # and produce a block... + blocks_set = ( + transition_with_random_block(block_randomizer), + ) + # build a set of block transitions from combinations of sub-transitions + transitions_generator = ( + itertools.product(epochs_set, slots_set, blocks_set) for + _ in range(BLOCK_TRANSITIONS_COUNT) + ) + block_transitions = zip(*transitions_generator) + + # and preface each set of block transitions with the possible leak transitions + leak_transitions = ( + transition_without_leak, + transition_to_leaking, + ) + scenarios = [ + {"transitions": _flatten(t)} + for t in itertools.product(leak_transitions, block_transitions) + ] + _normalize_scenarios(scenarios) + return scenarios + + +def _id_from_scenario(test_description): + """ + Construct a test name for ``pytest`` infra. + """ + def _to_id_part(prefix, x): + suffix = str(x) + if isinstance(x, Callable): + suffix = x.__name__ + return f"{prefix}{suffix}" + + def _id_from_transition(transition): + return ",".join(( + _to_id_part("epochs:", transition["epochs_to_skip"]), + _to_id_part("slots:", transition["slots_to_skip"]), + _to_id_part("with-block:", transition["block_producer"]) + )) + + return "|".join(map(_id_from_transition, test_description["transitions"])) + + +test_imports_template = """\"\"\" +This module is generated from the ``random`` test generator. +Please do not edit this file manually. +See the README for that generator for more information. +\"\"\" + +from eth2spec.test.helpers.constants import {phase} +from eth2spec.test.context import ( + misc_balances_in_default_range_with_many_validators, + with_phases, + zero_activation_threshold, +) +from eth2spec.test.context import ( + always_bls, + spec_test, + with_custom_state, + single_phase, +) +from eth2spec.test.utils.random import ( + run_generated_randomized_test, +)""" + +test_template = """ +@with_phases([{phase}]) +@with_custom_state( + balances_fn=misc_balances_in_default_range_with_many_validators, + threshold_fn=zero_activation_threshold +) +@spec_test +@single_phase +@always_bls +def test_randomized_{index}(spec, state): + # scenario as high-level, informal text: +{name_as_comment} + scenario = {scenario} + yield from run_generated_randomized_test( + spec, + state, + scenario, + )""" + + +def _to_comment(name, indent_level): + parts = name.split("|") + indentation = " " * indent_level + parts = [ + indentation + "# " + part for part in parts + ] + return "\n".join(parts) + + +def run_generate_tests_to_std_out(phase, state_randomizer, block_randomizer): + scenarios = _generate_randomized_scenarios(block_randomizer) + test_content = {"phase": phase.upper()} + test_imports = test_imports_template.format(**test_content) + test_file = [test_imports] + for index, scenario in enumerate(scenarios): + # required for setup phase + scenario["state_randomizer"] = state_randomizer.__name__ + + # need to pass name, rather than function reference... + transitions = scenario["transitions"] + for transition in transitions: + for name, value in transition.items(): + if isinstance(value, Callable): + transition[name] = value.__name__ + + test_content = test_content.copy() + name = _id_from_scenario(scenario) + test_content["name_as_comment"] = _to_comment(name, 1) + test_content["index"] = index + test_content["scenario"] = scenario + test_instance = test_template.format(**test_content) + test_file.append(test_instance) + print("\n\n".join(test_file)) + + +if __name__ == "__main__": + did_generate = False + if PHASE0 in sys.argv: + did_generate = True + run_generate_tests_to_std_out( + PHASE0, + state_randomizer=randomize_state, + block_randomizer=random_block, + ) + if ALTAIR in sys.argv: + did_generate = True + run_generate_tests_to_std_out( + ALTAIR, + state_randomizer=randomize_state_altair, + block_randomizer=random_block_altair, + ) + if not did_generate: + warnings.warn("no phase given for test generation") diff --git a/tests/generators/random/main.py b/tests/generators/random/main.py new file mode 100644 index 000000000..f6f1b1847 --- /dev/null +++ b/tests/generators/random/main.py @@ -0,0 +1,18 @@ +from eth2spec.test.helpers.constants import PHASE0, ALTAIR +from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators + + +if __name__ == "__main__": + phase_0_mods = {key: 'eth2spec.test.phase0.random.test_' + key for key in [ + 'random', + ]} + altair_mods = {key: 'eth2spec.test.altair.random.test_' + key for key in [ + 'random', + ]} + + all_mods = { + PHASE0: phase_0_mods, + ALTAIR: altair_mods, + } + + run_state_test_generators(runner_name="random", all_mods=all_mods) diff --git a/tests/generators/random/requirements.txt b/tests/generators/random/requirements.txt new file mode 100644 index 000000000..182248686 --- /dev/null +++ b/tests/generators/random/requirements.txt @@ -0,0 +1,2 @@ +pytest>=4.4 +../../../[generator] diff --git a/tests/generators/sanity/main.py b/tests/generators/sanity/main.py index 89e622f1c..8caedc8e5 100644 --- a/tests/generators/sanity/main.py +++ b/tests/generators/sanity/main.py @@ -5,12 +5,10 @@ from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators if __name__ == "__main__": phase_0_mods = {key: 'eth2spec.test.phase0.sanity.test_' + key for key in [ 'blocks', - 'blocks_random', 'slots', ]} altair_mods = {**{key: 'eth2spec.test.altair.sanity.test_' + key for key in [ 'blocks', - 'blocks_random', ]}, **phase_0_mods} # also run the previous phase 0 tests # Altair-specific test cases are ignored, but should be included after the Merge is rebased onto Altair work. From d1f3ec59afba70ee39e5c1bcf15e371248c6189c Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 11:56:19 -0700 Subject: [PATCH 042/122] ensure at least 1 operation when making random block --- .../pyspec/eth2spec/test/helpers/multi_operations.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 10de14253..3d941627b 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -87,7 +87,7 @@ def get_random_attester_slashings(spec, state, rng): def get_random_attestations(spec, state, rng): - num_attestations = rng.randrange(spec.MAX_ATTESTATIONS) + num_attestations = max(1, rng.randrange(spec.MAX_ATTESTATIONS)) attestations = [ get_valid_attestation( @@ -101,13 +101,12 @@ def get_random_attestations(spec, state, rng): def prepare_state_and_get_random_deposits(spec, state, rng): - num_deposits = rng.randrange(spec.MAX_DEPOSITS) + num_deposits = max(1, rng.randrange(spec.MAX_DEPOSITS)) deposit_data_leaves = [spec.DepositData() for _ in range(len(state.validators))] deposits = [] # First build deposit data leaves - root = None for i in range(num_deposits): index = len(state.validators) + i _, root, deposit_data_leaves = build_deposit( @@ -120,9 +119,8 @@ def prepare_state_and_get_random_deposits(spec, state, rng): signed=True, ) - if root: - # NOTE: if ``num_deposits == 0``, ``root`` is never assigned to - state.eth1_data.deposit_root = root + # NOTE: if ``num_deposits == 0``, ``root`` is never assigned to + state.eth1_data.deposit_root = root state.eth1_data.deposit_count += num_deposits # Then for that context, build deposits/proofs @@ -149,7 +147,7 @@ def _eligible_for_exit(spec, state, index): def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): - num_exits = rng.randrange(spec.MAX_VOLUNTARY_EXITS) + num_exits = max(1, rng.randrange(spec.MAX_VOLUNTARY_EXITS)) active_indices = set(spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy()) indices = set( index for index in active_indices From 8e5a34c38a909db63a75057bde62d64b07f234a0 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 12:37:28 -0700 Subject: [PATCH 043/122] adjust helper to account for additional slashings --- .../eth2spec/test/helpers/multi_operations.py | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 3d941627b..cfc2c4a0f 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -64,20 +64,33 @@ def get_random_proposer_slashings(spec, state, rng): return slashings -def get_random_attester_slashings(spec, state, rng): +def get_random_attester_slashings(spec, state, rng, slashed_indices=[]): + """ + Caller can supply ``slashed_indices`` if they are aware of other indices + that will be slashed by other operations in the same block as the one that + contains the output of this function. + """ # ensure at least one attester slashing, the max count # is small so not much room for random inclusion num_slashings = max(1, rng.randrange(spec.MAX_ATTESTER_SLASHINGS)) active_indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() indices = [ index for index in active_indices - if not state.validators[index].slashed + if ( + not state.validators[index].slashed + and index not in slashed_indices + ) ] + sample_upper_bound = 4 + max_slashed_count = num_slashings * sample_upper_bound - 1 + if len(indices) < max_slashed_count: + return [] + slot_range = list(range(state.slot - spec.SLOTS_PER_HISTORICAL_ROOT + 1, state.slot)) slashings = [ get_valid_attester_slashing_by_indices( spec, state, - sorted([indices.pop(rng.randrange(len(indices))) for _ in range(rng.randrange(1, 4))]), + sorted([indices.pop(rng.randrange(len(indices))) for _ in range(rng.randrange(1, sample_upper_bound))]), slot=slot_range.pop(rng.randrange(len(slot_range))), signed_1=True, signed_2=True, ) @@ -164,8 +177,13 @@ def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188)): deposits = prepare_state_and_get_random_deposits(spec, state, rng) block = build_empty_block_for_next_slot(spec, state) - block.body.proposer_slashings = get_random_proposer_slashings(spec, state, rng) - block.body.attester_slashings = get_random_attester_slashings(spec, state, rng) + proposer_slashings = get_random_proposer_slashings(spec, state, rng) + block.body.proposer_slashings = proposer_slashings + slashed_indices = [ + slashing.signed_header_1.message.proposer_index + for slashing in proposer_slashings + ] + block.body.attester_slashings = get_random_attester_slashings(spec, state, rng, slashed_indices) block.body.attestations = get_random_attestations(spec, state, rng) block.body.deposits = deposits From 8a32bef58b186ff35ccf6f1709baf7d3aaadb772 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 13:19:31 -0700 Subject: [PATCH 044/122] update skipped test count when test already exists --- tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py index be5720265..eb72bf211 100644 --- a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py +++ b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py @@ -112,6 +112,7 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): if case_dir.exists(): if not args.force and not incomplete_tag_file.exists(): + skipped_test_count += 1 print(f'Skipping already existing test: {case_dir}') continue else: From 933c1323dd2b51fa1c24df7737df94b281385196 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 14:46:31 -0700 Subject: [PATCH 045/122] lint updates --- .../test/altair/random/test_random.py | 32 +++++++++---------- .../test/phase0/random/test_random.py | 32 +++++++++---------- .../core/pyspec/eth2spec/test/utils/random.py | 1 + tests/generators/random/generate.py | 2 +- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py index 86f8f97b1..c7780925d 100644 --- a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py @@ -38,7 +38,7 @@ def test_randomized_0(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -63,7 +63,7 @@ def test_randomized_1(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -88,7 +88,7 @@ def test_randomized_2(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -113,7 +113,7 @@ def test_randomized_3(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -138,7 +138,7 @@ def test_randomized_4(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -163,7 +163,7 @@ def test_randomized_5(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -188,7 +188,7 @@ def test_randomized_6(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -213,7 +213,7 @@ def test_randomized_7(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -238,7 +238,7 @@ def test_randomized_8(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -263,7 +263,7 @@ def test_randomized_9(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -288,7 +288,7 @@ def test_randomized_10(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -313,7 +313,7 @@ def test_randomized_11(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -338,7 +338,7 @@ def test_randomized_12(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -363,7 +363,7 @@ def test_randomized_13(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -388,7 +388,7 @@ def test_randomized_14(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -413,7 +413,7 @@ def test_randomized_15(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, diff --git a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py index bfa93330f..95dfeaeaf 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py @@ -38,7 +38,7 @@ def test_randomized_0(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -63,7 +63,7 @@ def test_randomized_1(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -88,7 +88,7 @@ def test_randomized_2(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -113,7 +113,7 @@ def test_randomized_3(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -138,7 +138,7 @@ def test_randomized_4(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -163,7 +163,7 @@ def test_randomized_5(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -188,7 +188,7 @@ def test_randomized_6(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -213,7 +213,7 @@ def test_randomized_7(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -238,7 +238,7 @@ def test_randomized_8(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -263,7 +263,7 @@ def test_randomized_9(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -288,7 +288,7 @@ def test_randomized_10(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -313,7 +313,7 @@ def test_randomized_11(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -338,7 +338,7 @@ def test_randomized_12(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -363,7 +363,7 @@ def test_randomized_13(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -388,7 +388,7 @@ def test_randomized_14(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -413,7 +413,7 @@ def test_randomized_15(spec, state): # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} + scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py index b12fca96b..2f727e749 100644 --- a/tests/core/pyspec/eth2spec/test/utils/random.py +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -249,6 +249,7 @@ def _randomized_scenario_setup(state_randomizer): # to resolve this references at runtime, we need a reference to this module: _this_module = sys.modules[__name__] + def _resolve_ref(ref): if isinstance(ref, str): return getattr(_this_module, ref) diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py index b31aac6a3..2f6b306d1 100644 --- a/tests/generators/random/generate.py +++ b/tests/generators/random/generate.py @@ -180,7 +180,7 @@ test_template = """ def test_randomized_{index}(spec, state): # scenario as high-level, informal text: {name_as_comment} - scenario = {scenario} + scenario = {scenario} # noqa: E501 yield from run_generated_randomized_test( spec, state, From f7c0dc36bed1e002c5768459d0cb6b93f1050c55 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 14:57:56 -0700 Subject: [PATCH 046/122] skip running heavy randomized tests in CI --- .../eth2spec/test/altair/random/test_random.py | 17 +++++++++++++++++ tests/core/pyspec/eth2spec/test/context.py | 11 +++++++++++ .../eth2spec/test/phase0/random/test_random.py | 17 +++++++++++++++++ tests/generators/random/generate.py | 2 ++ 4 files changed, 47 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py index c7780925d..d022c2ca1 100644 --- a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py @@ -9,6 +9,7 @@ from eth2spec.test.context import ( misc_balances_in_default_range_with_many_validators, with_phases, zero_activation_threshold, + only_generator, ) from eth2spec.test.context import ( always_bls, @@ -21,6 +22,7 @@ from eth2spec.test.utils.random import ( ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -46,6 +48,7 @@ def test_randomized_0(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -71,6 +74,7 @@ def test_randomized_1(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -96,6 +100,7 @@ def test_randomized_2(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -121,6 +126,7 @@ def test_randomized_3(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -146,6 +152,7 @@ def test_randomized_4(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -171,6 +178,7 @@ def test_randomized_5(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -196,6 +204,7 @@ def test_randomized_6(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -221,6 +230,7 @@ def test_randomized_7(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -246,6 +256,7 @@ def test_randomized_8(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -271,6 +282,7 @@ def test_randomized_9(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -296,6 +308,7 @@ def test_randomized_10(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -321,6 +334,7 @@ def test_randomized_11(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -346,6 +360,7 @@ def test_randomized_12(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -371,6 +386,7 @@ def test_randomized_13(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -396,6 +412,7 @@ def test_randomized_14(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([ALTAIR]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index f6f120d55..346cdc8f1 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -456,6 +456,17 @@ with_altair_and_later = with_phases([ALTAIR, MERGE]) with_merge_and_later = with_phases([MERGE]) # TODO: include sharding when spec stabilizes. +def only_generator(reason): + def _decorator(inner): + def _wrapper(*args, **kwargs): + if is_pytest: + dump_skipping_message(reason) + return None + return inner(*args, **kwargs) + return _wrapper + return _decorator + + def fork_transition_test(pre_fork_name, post_fork_name, fork_epoch=None): """ A decorator to construct a "transition" test from one fork of the eth2 spec diff --git a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py index 95dfeaeaf..5bb8c3791 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py @@ -9,6 +9,7 @@ from eth2spec.test.context import ( misc_balances_in_default_range_with_many_validators, with_phases, zero_activation_threshold, + only_generator, ) from eth2spec.test.context import ( always_bls, @@ -21,6 +22,7 @@ from eth2spec.test.utils.random import ( ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -46,6 +48,7 @@ def test_randomized_0(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -71,6 +74,7 @@ def test_randomized_1(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -96,6 +100,7 @@ def test_randomized_2(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -121,6 +126,7 @@ def test_randomized_3(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -146,6 +152,7 @@ def test_randomized_4(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -171,6 +178,7 @@ def test_randomized_5(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -196,6 +204,7 @@ def test_randomized_6(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -221,6 +230,7 @@ def test_randomized_7(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -246,6 +256,7 @@ def test_randomized_8(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -271,6 +282,7 @@ def test_randomized_9(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -296,6 +308,7 @@ def test_randomized_10(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -321,6 +334,7 @@ def test_randomized_11(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -346,6 +360,7 @@ def test_randomized_12(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -371,6 +386,7 @@ def test_randomized_13(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, @@ -396,6 +412,7 @@ def test_randomized_14(spec, state): ) +@only_generator("randomized test for broad coverage, not point-to-point CI") @with_phases([PHASE0]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py index 2f6b306d1..3f34a6bc0 100644 --- a/tests/generators/random/generate.py +++ b/tests/generators/random/generate.py @@ -157,6 +157,7 @@ from eth2spec.test.context import ( misc_balances_in_default_range_with_many_validators, with_phases, zero_activation_threshold, + only_generator, ) from eth2spec.test.context import ( always_bls, @@ -169,6 +170,7 @@ from eth2spec.test.utils.random import ( )""" test_template = """ +@only_generator(\"randomized test for broad coverage, not point-to-point CI\") @with_phases([{phase}]) @with_custom_state( balances_fn=misc_balances_in_default_range_with_many_validators, From 33c96127dac894f942ed3225400541499fa2ea30 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 16:21:45 -0700 Subject: [PATCH 047/122] fix bug with random sync aggregate helper --- .../pyspec/eth2spec/test/helpers/multi_operations.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index cfc2c4a0f..83494182e 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -217,14 +217,18 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): def get_random_sync_aggregate(spec, state, fraction_participated=1.0, rng=Random(2099)): committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) participant_count = int(len(committee_indices) * fraction_participated) - participants = rng.sample(committee_indices, participant_count) + participant_indices = rng.sample(range(len(committee_indices)), participant_count) + participants = [ + committee_indices[index] + for index in participant_indices + ] signature = compute_aggregate_sync_committee_signature( spec, state, - state.slot, + state.slot - 1, participants, ) return spec.SyncAggregate( - sync_committee_bits=[index in participants for index in committee_indices], + sync_committee_bits=[index in participant_indices for index in range(len(committee_indices))], sync_committee_signature=signature, ) From 7874e8db881fc0a6812d0af8261925c91a62ac56 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 16:25:25 -0700 Subject: [PATCH 048/122] clean up unnecessary comment --- tests/core/pyspec/eth2spec/test/helpers/multi_operations.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 83494182e..c0a58dbca 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -132,7 +132,6 @@ def prepare_state_and_get_random_deposits(spec, state, rng): signed=True, ) - # NOTE: if ``num_deposits == 0``, ``root`` is never assigned to state.eth1_data.deposit_root = root state.eth1_data.deposit_count += num_deposits From 02bc6541d99770a17a3b1127e36870971713a843 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 24 Aug 2021 16:28:13 -0700 Subject: [PATCH 049/122] extend Makefile --- tests/generators/random/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/generators/random/Makefile b/tests/generators/random/Makefile index a3c845243..799001280 100644 --- a/tests/generators/random/Makefile +++ b/tests/generators/random/Makefile @@ -1,4 +1,5 @@ all: + if ! test -d venv; then python3 -m venv venv; fi; . ./venv/bin/activate pip install -r requirements.txt rm -f ../../core/pyspec/eth2spec/test/phase0/random/test_random.py From 4d4f4e89f48aa4d5c14a41159d6bcb021f8ec1a3 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 10:38:01 -0700 Subject: [PATCH 050/122] be specific about which slot we want a sync committee root for --- .../core/pyspec/eth2spec/test/helpers/multi_operations.py | 4 ++-- tests/core/pyspec/eth2spec/test/utils/random.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index c0a58dbca..075b03aa0 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -213,7 +213,7 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): yield 'post', state -def get_random_sync_aggregate(spec, state, fraction_participated=1.0, rng=Random(2099)): +def get_random_sync_aggregate(spec, state, slot, fraction_participated=1.0, rng=Random(2099)): committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) participant_count = int(len(committee_indices) * fraction_participated) participant_indices = rng.sample(range(len(committee_indices)), participant_count) @@ -224,7 +224,7 @@ def get_random_sync_aggregate(spec, state, fraction_participated=1.0, rng=Random signature = compute_aggregate_sync_committee_signature( spec, state, - state.slot - 1, + slot, participants, ) return spec.SyncAggregate( diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py index 2f727e749..d17a3a9b2 100644 --- a/tests/core/pyspec/eth2spec/test/utils/random.py +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -123,7 +123,12 @@ def random_block_altair(spec, state, signed_blocks): block = random_block(spec, state, signed_blocks) fraction_missed = len(signed_blocks) / SYNC_AGGREGATE_PARTICIPATION_BUCKETS fraction_participated = 1.0 - fraction_missed - block.body.sync_aggregate = get_random_sync_aggregate(spec, state, fraction_participated=fraction_participated) + block.body.sync_aggregate = get_random_sync_aggregate( + spec, + state, + block.slot - 1, + fraction_participated=fraction_participated, + ) return block From e72edf07f9e1f35fd3cf7f21970ce85848905841 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 10:40:15 -0700 Subject: [PATCH 051/122] consolidate call to `max` into `randrange` --- .../core/pyspec/eth2spec/test/helpers/multi_operations.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 075b03aa0..73ebedfe0 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -48,7 +48,7 @@ def run_slash_and_exit(spec, state, slash_index, exit_index, valid=True): def get_random_proposer_slashings(spec, state, rng): - num_slashings = max(1, rng.randrange(spec.MAX_PROPOSER_SLASHINGS)) + num_slashings = rng.randrange(1, spec.MAX_PROPOSER_SLASHINGS) active_indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() indices = [ index for index in active_indices @@ -72,7 +72,7 @@ def get_random_attester_slashings(spec, state, rng, slashed_indices=[]): """ # ensure at least one attester slashing, the max count # is small so not much room for random inclusion - num_slashings = max(1, rng.randrange(spec.MAX_ATTESTER_SLASHINGS)) + num_slashings = rng.randrange(1, spec.MAX_ATTESTER_SLASHINGS) active_indices = spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy() indices = [ index for index in active_indices @@ -100,7 +100,7 @@ def get_random_attester_slashings(spec, state, rng, slashed_indices=[]): def get_random_attestations(spec, state, rng): - num_attestations = max(1, rng.randrange(spec.MAX_ATTESTATIONS)) + num_attestations = rng.randrange(1, spec.MAX_ATTESTATIONS) attestations = [ get_valid_attestation( @@ -114,7 +114,7 @@ def get_random_attestations(spec, state, rng): def prepare_state_and_get_random_deposits(spec, state, rng): - num_deposits = max(1, rng.randrange(spec.MAX_DEPOSITS)) + num_deposits = rng.randrange(1, spec.MAX_DEPOSITS) deposit_data_leaves = [spec.DepositData() for _ in range(len(state.validators))] deposits = [] From e575b222be7798ad945669baa9a0b44abd1952a2 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 10:54:55 -0700 Subject: [PATCH 052/122] clarify readme --- tests/generators/random/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/generators/random/README.md b/tests/generators/random/README.md index e1942b7f4..35de22d01 100644 --- a/tests/generators/random/README.md +++ b/tests/generators/random/README.md @@ -1,6 +1,6 @@ # Randomized tests -Randomized tests in the format of `sanity` tests, with randomized operations. +Randomized tests in the format of `sanity` blocks tests, with randomized operations. Information on the format of the tests can be found in the [sanity test formats documentation](../../formats/sanity/README.md). From 81971a89573804d0570fb8ef5cb5fc6d3fd90270 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 11:01:26 -0700 Subject: [PATCH 053/122] update readme for pytest --- tests/generators/random/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/generators/random/README.md b/tests/generators/random/README.md index 35de22d01..fd1728441 100644 --- a/tests/generators/random/README.md +++ b/tests/generators/random/README.md @@ -16,7 +16,9 @@ The generated files are committed to the repo so you should not need to do this. # To run tests -Use the usual `pytest` mechanics used elsewhere in this repo. +Each of the generated test does produce a `pytest` test instance but by default is +currently skipped. Running the test via the generator (see next) will trigger any errors +that would arise during the running of `pytest`. # To generate spec tests (from the generated files) From 0da1fe947dbea4ce6c9272630cc7d19df286bc54 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 11:09:35 -0700 Subject: [PATCH 054/122] clarify how the random block generator works --- tests/core/pyspec/eth2spec/test/utils/random.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/random.py index d17a3a9b2..d0fde4565 100644 --- a/tests/core/pyspec/eth2spec/test/utils/random.py +++ b/tests/core/pyspec/eth2spec/test/utils/random.py @@ -100,6 +100,15 @@ def random_block(spec, state, _signed_blocks): to produce a block over ``BLOCK_ATTEMPTS`` slots in order to find a valid block in the event that the proposer has already been slashed. """ + # NOTE: ``state`` has been "randomized" at this point and so will likely + # contain a large number of slashed validators. This function needs to return + # a valid block so it needs to check that the proposer of the next slot is not + # slashed. + # To do this, generate a ``temp_state`` to use for checking the propser in the next slot. + # This ensures no accidental mutations happen to the ``state`` the caller expects to get back + # after this function returns. + # Using a copy of the state for proposer sampling is also sound as any inputs used for the + # shuffling are fixed a few epochs prior to ``spec.get_current_epoch(state)``. temp_state = state.copy() next_slot(spec, temp_state) for _ in range(BLOCK_ATTEMPTS): From a6f8870e18598431716d69e8eaa199cdea25dded Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 11:15:27 -0700 Subject: [PATCH 055/122] update makefile to use correct python version --- tests/generators/random/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/generators/random/Makefile b/tests/generators/random/Makefile index 799001280..1b518bfde 100644 --- a/tests/generators/random/Makefile +++ b/tests/generators/random/Makefile @@ -1,8 +1,8 @@ all: if ! test -d venv; then python3 -m venv venv; fi; . ./venv/bin/activate - pip install -r requirements.txt + pip3 install -r requirements.txt rm -f ../../core/pyspec/eth2spec/test/phase0/random/test_random.py rm -f ../../core/pyspec/eth2spec/test/altair/random/test_random.py - python generate.py phase0 > ../../core/pyspec/eth2spec/test/phase0/random/test_random.py - python generate.py altair > ../../core/pyspec/eth2spec/test/altair/random/test_random.py + python3 generate.py phase0 > ../../core/pyspec/eth2spec/test/phase0/random/test_random.py + python3 generate.py altair > ../../core/pyspec/eth2spec/test/altair/random/test_random.py From 14518d4d642d2ca7f94e709dc155256b0c568a81 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 11:15:59 -0700 Subject: [PATCH 056/122] update name of utility module to be more specific --- tests/core/pyspec/eth2spec/test/altair/random/test_random.py | 2 +- tests/core/pyspec/eth2spec/test/phase0/random/test_random.py | 2 +- .../test/utils/{random.py => randomized_block_tests.py} | 0 tests/generators/random/generate.py | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename tests/core/pyspec/eth2spec/test/utils/{random.py => randomized_block_tests.py} (100%) diff --git a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py index d022c2ca1..b581659fe 100644 --- a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py @@ -17,7 +17,7 @@ from eth2spec.test.context import ( with_custom_state, single_phase, ) -from eth2spec.test.utils.random import ( +from eth2spec.test.utils.randomized_block_tests import ( run_generated_randomized_test, ) diff --git a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py index 5bb8c3791..abf74e43f 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py @@ -17,7 +17,7 @@ from eth2spec.test.context import ( with_custom_state, single_phase, ) -from eth2spec.test.utils.random import ( +from eth2spec.test.utils.randomized_block_tests import ( run_generated_randomized_test, ) diff --git a/tests/core/pyspec/eth2spec/test/utils/random.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py similarity index 100% rename from tests/core/pyspec/eth2spec/test/utils/random.py rename to tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py index 3f34a6bc0..d6215bb1f 100644 --- a/tests/generators/random/generate.py +++ b/tests/generators/random/generate.py @@ -13,7 +13,7 @@ import warnings from typing import Callable import itertools -from eth2spec.test.utils.random import ( +from eth2spec.test.utils.randomized_block_tests import ( no_block, no_op_validation, randomize_state, @@ -165,7 +165,7 @@ from eth2spec.test.context import ( with_custom_state, single_phase, ) -from eth2spec.test.utils.random import ( +from eth2spec.test.utils.randomized_block_tests import ( run_generated_randomized_test, )""" From 377797fd0dfcd7d60ca688760779a2a44be13768 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 11:20:17 -0700 Subject: [PATCH 057/122] code layout change --- .../eth2spec/test/helpers/multi_operations.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 73ebedfe0..bbfc9ffc6 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -171,6 +171,26 @@ def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): return prepare_signed_exits(spec, state, exit_indices) +def get_random_sync_aggregate(spec, state, slot, fraction_participated=1.0, rng=Random(2099)): + committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + participant_count = int(len(committee_indices) * fraction_participated) + participant_indices = rng.sample(range(len(committee_indices)), participant_count) + participants = [ + committee_indices[index] + for index in participant_indices + ] + signature = compute_aggregate_sync_committee_signature( + spec, + state, + slot, + participants, + ) + return spec.SyncAggregate( + sync_committee_bits=[index in participant_indices for index in range(len(committee_indices))], + sync_committee_signature=signature, + ) + + def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188)): # prepare state for deposits before building block deposits = prepare_state_and_get_random_deposits(spec, state, rng) @@ -211,23 +231,3 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): yield 'blocks', [signed_block] yield 'post', state - - -def get_random_sync_aggregate(spec, state, slot, fraction_participated=1.0, rng=Random(2099)): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) - participant_count = int(len(committee_indices) * fraction_participated) - participant_indices = rng.sample(range(len(committee_indices)), participant_count) - participants = [ - committee_indices[index] - for index in participant_indices - ] - signature = compute_aggregate_sync_committee_signature( - spec, - state, - slot, - participants, - ) - return spec.SyncAggregate( - sync_committee_bits=[index in participant_indices for index in range(len(committee_indices))], - sync_committee_signature=signature, - ) From 961953ac15df9246edc3e36c7bf2ad436911b06f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 13:10:41 -0700 Subject: [PATCH 058/122] update parameter name --- .../eth2spec/test/utils/randomized_block_tests.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index d0fde4565..4b25fb5ac 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -283,19 +283,19 @@ def _iter_temporal(spec, description): yield i -def run_generated_randomized_test(spec, state, test_description): - if "setup" not in test_description: - state_randomizer = _resolve_ref(test_description.get("state_randomizer", randomize_state)) - test_description["setup"] = _randomized_scenario_setup(state_randomizer) +def run_generated_randomized_test(spec, state, scenario): + if "setup" not in scenario: + state_randomizer = _resolve_ref(scenario.get("state_randomizer", randomize_state)) + scenario["setup"] = _randomized_scenario_setup(state_randomizer) - for mutation, validation in test_description["setup"]: + for mutation, validation in scenario["setup"]: mutation(spec, state) validation(spec, state) yield "pre", state blocks = [] - for transition in test_description["transitions"]: + for transition in scenario["transitions"]: epochs_to_skip = _iter_temporal(spec, transition["epochs_to_skip"]) for _ in epochs_to_skip: next_epoch(spec, state) From 047ff5b09910c8b6fec54f56af2e748c1e4348ef Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 14:16:39 -0700 Subject: [PATCH 059/122] unify visibility on names for doc purposes --- .../test/utils/randomized_block_tests.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index 4b25fb5ac..63c242782 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -39,7 +39,7 @@ def randomize_state_altair(spec, state): # epochs -def _epochs_until_leak(spec): +def epochs_until_leak(spec): """ State is "leaking" if the current epoch is at least this value after the last finalized epoch. @@ -47,7 +47,7 @@ def _epochs_until_leak(spec): return spec.MIN_EPOCHS_TO_INACTIVITY_PENALTY + 1 -def _epochs_for_shard_committee_period(spec): +def epochs_for_shard_committee_period(spec): return spec.config.SHARD_COMMITTEE_PERIOD @@ -147,24 +147,24 @@ def no_op_validation(spec, state): return True -def _validate_is_leaking(spec, state): +def validate_is_leaking(spec, state): return spec.is_in_inactivity_leak(state) -def _validate_is_not_leaking(spec, state): - return not _validate_is_leaking(spec, state) +def validate_is_not_leaking(spec, state): + return not validate_is_leaking(spec, state) # transitions -def _with_validation(transition, validation): +def with_validation(transition, validation): if isinstance(transition, Callable): transition = transition() transition["validation"] = validation return transition -def _no_op_transition(): +def no_op_transition(): return {} @@ -182,12 +182,12 @@ def slot_transition(n=0): def transition_to_leaking(): return { - "epochs_to_skip": _epochs_until_leak, - "validation": _validate_is_leaking, + "epochs_to_skip": epochs_until_leak, + "validation": validate_is_leaking, } -transition_without_leak = _with_validation(_no_op_transition, _validate_is_not_leaking) +transition_without_leak = with_validation(no_op_transition, validate_is_not_leaking) # block transitions @@ -250,7 +250,7 @@ def _randomized_scenario_setup(state_randomizer): return ( # NOTE: the block randomization function assumes at least 1 shard committee period # so advance the state before doing anything else. - (_skip_epochs(_epochs_for_shard_committee_period), no_op_validation), + (_skip_epochs(epochs_for_shard_committee_period), no_op_validation), (_simulate_honest_execution, no_op_validation), (state_randomizer, ensure_state_has_validators_across_lifecycle), ) From e2dc9f9ec2f5643c833af500e1edf18e7c31b8de Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 14:42:41 -0700 Subject: [PATCH 060/122] update generation of randomized scenarios for more variability --- .../test/altair/random/test_random.py | 120 +++++++++--------- .../test/phase0/random/test_random.py | 120 +++++++++--------- tests/generators/random/generate.py | 19 ++- 3 files changed, 136 insertions(+), 123 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py index b581659fe..d00da3f9e 100644 --- a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py @@ -35,12 +35,12 @@ def test_randomized_0(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -60,13 +60,13 @@ def test_randomized_0(spec, state): def test_randomized_1(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -87,12 +87,12 @@ def test_randomized_2(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -113,12 +113,12 @@ def test_randomized_3(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -142,9 +142,9 @@ def test_randomized_4(spec, state): # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -164,13 +164,13 @@ def test_randomized_4(spec, state): def test_randomized_5(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block - # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -191,12 +191,12 @@ def test_randomized_6(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -217,12 +217,12 @@ def test_randomized_7(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -241,14 +241,14 @@ def test_randomized_7(spec, state): @always_bls def test_randomized_8(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block_altair + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -267,14 +267,14 @@ def test_randomized_8(spec, state): @always_bls def test_randomized_9(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -293,14 +293,14 @@ def test_randomized_9(spec, state): @always_bls def test_randomized_10(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -319,14 +319,14 @@ def test_randomized_10(spec, state): @always_bls def test_randomized_11(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -345,14 +345,14 @@ def test_randomized_11(spec, state): @always_bls def test_randomized_12(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -371,14 +371,14 @@ def test_randomized_12(spec, state): @always_bls def test_randomized_13(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block - # epochs:1,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -397,14 +397,14 @@ def test_randomized_13(spec, state): @always_bls def test_randomized_14(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -423,14 +423,14 @@ def test_randomized_14(spec, state): @always_bls def test_randomized_15(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, diff --git a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py index abf74e43f..89a457bed 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/random/test_random.py @@ -35,12 +35,12 @@ def test_randomized_0(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -60,13 +60,13 @@ def test_randomized_0(spec, state): def test_randomized_1(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -87,12 +87,12 @@ def test_randomized_2(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -113,12 +113,12 @@ def test_randomized_3(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -142,9 +142,9 @@ def test_randomized_4(spec, state): # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -164,13 +164,13 @@ def test_randomized_4(spec, state): def test_randomized_5(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block - # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -191,12 +191,12 @@ def test_randomized_6(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -217,12 +217,12 @@ def test_randomized_7(spec, state): # scenario as high-level, informal text: # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'validation': '_validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -241,14 +241,14 @@ def test_randomized_7(spec, state): @always_bls def test_randomized_8(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:random_block + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -267,14 +267,14 @@ def test_randomized_8(spec, state): @always_bls def test_randomized_9(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -293,14 +293,14 @@ def test_randomized_9(spec, state): @always_bls def test_randomized_10(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -319,14 +319,14 @@ def test_randomized_10(spec, state): @always_bls def test_randomized_11(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:1,slots:0,with-block:no_block + # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -345,14 +345,14 @@ def test_randomized_11(spec, state): @always_bls def test_randomized_12(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:last_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -371,14 +371,14 @@ def test_randomized_12(spec, state): @always_bls def test_randomized_13(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block - # epochs:1,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:random_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -397,14 +397,14 @@ def test_randomized_13(spec, state): @always_bls def test_randomized_14(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:random_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block + # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -423,14 +423,14 @@ def test_randomized_14(spec, state): @always_bls def test_randomized_15(spec, state): # scenario as high-level, informal text: - # epochs:_epochs_until_leak,slots:0,with-block:no_block + # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block # epochs:1,slots:0,with-block:no_block - # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block + # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:random_block - scenario = {'transitions': [{'epochs_to_skip': '_epochs_until_leak', 'validation': '_validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state'} # noqa: E501 yield from run_generated_randomized_test( spec, state, diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py index d6215bb1f..7f033f957 100644 --- a/tests/generators/random/generate.py +++ b/tests/generators/random/generate.py @@ -9,6 +9,7 @@ NOTE: To add additional scenarios, add test cases below in ``_generate_randomize """ import sys +import random import warnings from typing import Callable import itertools @@ -70,7 +71,11 @@ def _flatten(t): result = [leak_transition] for transition_batch in t[1]: for transition in transition_batch: - result.append(transition) + if isinstance(transition, tuple): + for subtransition in transition: + result.append(subtransition) + else: + result.append(transition) return result @@ -106,10 +111,18 @@ def _generate_randomized_scenarios(block_randomizer): blocks_set = ( transition_with_random_block(block_randomizer), ) + + rng = random.Random(1447) + all_skips = list(itertools.product(epochs_set, slots_set)) + randomized_skips = ( + rng.sample(all_skips, len(all_skips)) + for _ in range(BLOCK_TRANSITIONS_COUNT) + ) + # build a set of block transitions from combinations of sub-transitions transitions_generator = ( - itertools.product(epochs_set, slots_set, blocks_set) for - _ in range(BLOCK_TRANSITIONS_COUNT) + itertools.product(prefix, blocks_set) + for prefix in randomized_skips ) block_transitions = zip(*transitions_generator) From c206a2772aba5a0c129995843e705ed0f7090793 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 14:46:17 -0700 Subject: [PATCH 061/122] update docs via PR feedback --- tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index 63c242782..338f88b6a 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -208,7 +208,7 @@ def transition_with_random_block(block_randomizer): def _randomized_scenario_setup(state_randomizer): """ - Return a sequence of pairs of ("mutator", "validator"), + Return a sequence of pairs of ("mutation", "validation"), a function that accepts (spec, state) arguments and performs some change and a function that accepts (spec, state) arguments and validates some change was made. """ From 5b0d2627c33b2228c92d7efa82139d09da64a2d4 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 15:13:20 -0700 Subject: [PATCH 062/122] apply pr feedback on randrange --- tests/core/pyspec/eth2spec/test/helpers/multi_operations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index bbfc9ffc6..14b281a95 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -159,7 +159,7 @@ def _eligible_for_exit(spec, state, index): def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): - num_exits = max(1, rng.randrange(spec.MAX_VOLUNTARY_EXITS)) + num_exits = rng.randrange(1, spec.MAX_VOLUNTARY_EXITS) active_indices = set(spec.get_active_validator_indices(state, spec.get_current_epoch(state)).copy()) indices = set( index for index in active_indices From 4b3022a76794f9b06e66d319d0163b0f43abb582 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 16:19:46 -0600 Subject: [PATCH 063/122] Update tests/generators/random/generate.py --- tests/generators/random/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py index 7f033f957..825cac128 100644 --- a/tests/generators/random/generate.py +++ b/tests/generators/random/generate.py @@ -141,7 +141,7 @@ def _generate_randomized_scenarios(block_randomizer): def _id_from_scenario(test_description): """ - Construct a test name for ``pytest`` infra. + Construct a name for the scenario based its data. """ def _to_id_part(prefix, x): suffix = str(x) From 874ea80cb8a3c77a321bb29b1979376cbc52a296 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 25 Aug 2021 17:18:02 -0700 Subject: [PATCH 064/122] use more precise name for altair block randomizer and re-gen tests --- .../test/altair/random/test_random.py | 96 +++++++++---------- .../test/utils/randomized_block_tests.py | 7 +- tests/generators/random/generate.py | 4 +- 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py index d00da3f9e..2250101bd 100644 --- a/tests/core/pyspec/eth2spec/test/altair/random/test_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/random/test_random.py @@ -36,11 +36,11 @@ def test_randomized_0(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -62,11 +62,11 @@ def test_randomized_1(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -88,11 +88,11 @@ def test_randomized_2(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -114,11 +114,11 @@ def test_randomized_3(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -140,11 +140,11 @@ def test_randomized_4(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -166,11 +166,11 @@ def test_randomized_5(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -192,11 +192,11 @@ def test_randomized_6(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -218,11 +218,11 @@ def test_randomized_7(spec, state): # epochs:0,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'validation': 'validate_is_not_leaking', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -244,11 +244,11 @@ def test_randomized_8(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -270,11 +270,11 @@ def test_randomized_9(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -296,11 +296,11 @@ def test_randomized_10(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -322,11 +322,11 @@ def test_randomized_11(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -348,11 +348,11 @@ def test_randomized_12(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:last_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'last_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -374,11 +374,11 @@ def test_randomized_13(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:random_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'random_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -400,11 +400,11 @@ def test_randomized_14(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:0,slots:0,with-block:no_block # epochs:0,slots:penultimate_slot_in_epoch,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 0, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 'penultimate_slot_in_epoch', 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, @@ -426,11 +426,11 @@ def test_randomized_15(spec, state): # epochs:epochs_until_leak,slots:0,with-block:no_block # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation # epochs:1,slots:0,with-block:no_block # epochs:0,slots:0,with-block:no_block - # epochs:0,slots:0,with-block:random_block_altair - scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 + # epochs:0,slots:0,with-block:random_block_altair_with_cycling_sync_committee_participation + scenario = {'transitions': [{'epochs_to_skip': 'epochs_until_leak', 'validation': 'validate_is_leaking', 'slots_to_skip': 0, 'block_producer': 'no_block'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}, {'epochs_to_skip': 1, 'slots_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'slots_to_skip': 0, 'epochs_to_skip': 0, 'block_producer': 'no_block', 'validation': 'no_op_validation'}, {'block_producer': 'random_block_altair_with_cycling_sync_committee_participation', 'epochs_to_skip': 0, 'slots_to_skip': 0, 'validation': 'no_op_validation'}], 'state_randomizer': 'randomize_state_altair'} # noqa: E501 yield from run_generated_randomized_test( spec, state, diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index 338f88b6a..44dab0e0e 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -128,9 +128,12 @@ def random_block(spec, state, _signed_blocks): SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4 -def random_block_altair(spec, state, signed_blocks): +def random_block_altair_with_cycling_sync_committee_participation(spec, + state, + signed_blocks): block = random_block(spec, state, signed_blocks) - fraction_missed = len(signed_blocks) / SYNC_AGGREGATE_PARTICIPATION_BUCKETS + block_index = len(signed_blocks) % SYNC_AGGREGATE_PARTICIPATION_BUCKETS + fraction_missed = block_index * (1 / SYNC_AGGREGATE_PARTICIPATION_BUCKETS) fraction_participated = 1.0 - fraction_missed block.body.sync_aggregate = get_random_sync_aggregate( spec, diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py index 7f033f957..099be5f35 100644 --- a/tests/generators/random/generate.py +++ b/tests/generators/random/generate.py @@ -20,7 +20,7 @@ from eth2spec.test.utils.randomized_block_tests import ( randomize_state, randomize_state_altair, random_block, - random_block_altair, + random_block_altair_with_cycling_sync_committee_participation, last_slot_in_epoch, random_slot_in_epoch, penultimate_slot_in_epoch, @@ -252,7 +252,7 @@ if __name__ == "__main__": run_generate_tests_to_std_out( ALTAIR, state_randomizer=randomize_state_altair, - block_randomizer=random_block_altair, + block_randomizer=random_block_altair_with_cycling_sync_committee_participation, ) if not did_generate: warnings.warn("no phase given for test generation") From 1f34ef9b565116322acc234fa1b2b8dec9c5e270 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 26 Aug 2021 10:50:50 -0700 Subject: [PATCH 065/122] modularize the random deposit helpers --- .../eth2spec/test/helpers/multi_operations.py | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 14b281a95..18c18194c 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -113,8 +113,12 @@ def get_random_attestations(spec, state, rng): return attestations -def prepare_state_and_get_random_deposits(spec, state, rng): - num_deposits = rng.randrange(1, spec.MAX_DEPOSITS) +def get_random_deposits(spec, state, rng, num_deposits=None): + if not num_deposits: + num_deposits = rng.randrange(1, spec.MAX_DEPOSITS) + + if num_deposits == 0: + return [], b"\x00" * 32 deposit_data_leaves = [spec.DepositData() for _ in range(len(state.validators))] deposits = [] @@ -132,15 +136,19 @@ def prepare_state_and_get_random_deposits(spec, state, rng): signed=True, ) - state.eth1_data.deposit_root = root - state.eth1_data.deposit_count += num_deposits - # Then for that context, build deposits/proofs for i in range(num_deposits): index = len(state.validators) + i deposit, _, _ = deposit_from_context(spec, deposit_data_leaves, index) deposits.append(deposit) + return deposits, root + + +def prepare_state_and_get_random_deposits(spec, state, rng, num_deposits=None): + deposits, root = get_random_deposits(spec, state, rng, num_deposits=num_deposits) + state.eth1_data.deposit_root = root + state.eth1_data.deposit_count += len(deposits) return deposits @@ -191,10 +199,7 @@ def get_random_sync_aggregate(spec, state, slot, fraction_participated=1.0, rng= ) -def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188)): - # prepare state for deposits before building block - deposits = prepare_state_and_get_random_deposits(spec, state, rng) - +def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188), deposits=None): block = build_empty_block_for_next_slot(spec, state) proposer_slashings = get_random_proposer_slashings(spec, state, rng) block.body.proposer_slashings = proposer_slashings @@ -204,7 +209,8 @@ def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188)): ] block.body.attester_slashings = get_random_attester_slashings(spec, state, rng, slashed_indices) block.body.attestations = get_random_attestations(spec, state, rng) - block.body.deposits = deposits + if deposits: + block.body.deposits = deposits # cannot include to be slashed indices as exits slashed_indices = set([ @@ -223,7 +229,9 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - block = build_random_block_from_state_for_next_slot(spec, state, rng) + # prepare state for deposits before building block + deposits = prepare_state_and_get_random_deposits(spec, state, rng) + block = build_random_block_from_state_for_next_slot(spec, state, rng, deposits=deposits) yield 'pre', state From b45601f44cc3ed6685795dc6545c715757dce2f3 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 26 Aug 2021 11:50:24 -0700 Subject: [PATCH 066/122] add timing information to spec test generation in particular, warn if any particular operation takes longer than some threshold, e.g. 1.0 second. --- .../eth2spec/gen_helpers/gen_base/gen_runner.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py index eb72bf211..765fc501b 100644 --- a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py +++ b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py @@ -1,4 +1,5 @@ import os +import time import shutil import argparse from pathlib import Path @@ -22,6 +23,9 @@ from .gen_typing import TestProvider context.is_pytest = False +TIME_THRESHOLD_TO_PRINT = 1.0 # seconds + + def validate_output_dir(path_str): path = Path(path_str) @@ -98,6 +102,7 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): generated_test_count = 0 skipped_test_count = 0 + provider_start = time.time() for tprov in test_providers: # runs anything that we don't want to repeat for every test case. tprov.prepare() @@ -122,6 +127,7 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): shutil.rmtree(case_dir) print(f'Generating test: {case_dir}') + test_start = time.time() written_part = False @@ -179,9 +185,18 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): generated_test_count += 1 # Only remove `INCOMPLETE` tag file os.remove(incomplete_tag_file) + test_end = time.time() + span = round(test_end - test_start, 2) + if span > TIME_THRESHOLD_TO_PRINT: + print(f' - generated in {span} seconds') + + provider_end = time.time() + span = round(provider_end - provider_start, 2) summary_message = f"completed generation of {generator_name} with {generated_test_count} tests" summary_message += f" ({skipped_test_count} skipped tests)" + if span > TIME_THRESHOLD_TO_PRINT: + summary_message += f" in {span} seconds" print(summary_message) From 9474f0a051aaf25c4fa119b8fb1651ff6a2828a1 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 26 Aug 2021 10:52:02 -0700 Subject: [PATCH 067/122] construct and supply scenario-wide state to facilitate deposit processing --- .../test/utils/randomized_block_tests.py | 93 +++++++++++++++---- 1 file changed, 74 insertions(+), 19 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index 44dab0e0e..f9d68221c 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -10,6 +10,7 @@ from typing import Callable from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state_for_next_slot, get_random_sync_aggregate, + prepare_state_and_get_random_deposits, ) from eth2spec.test.helpers.inactivity_scores import ( randomize_inactivity_scores, @@ -28,13 +29,35 @@ from eth2spec.test.helpers.state import ( # state -def randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1): +def _randomize_deposit_state(spec, state, stats): + """ + To introduce valid, randomized deposits, the ``state`` deposit sub-state + must be coordinated with the data that will ultimately go into blocks. + + This function randomizes the ``state`` in a way that can signal downstream to + the block constructors how they should (or should not) make some randomized deposits. + """ + rng = Random(999) + block_count = stats.get("block_count", 0) + deposits = [] + if block_count > 0: + num_deposits = rng.randrange(1, block_count * spec.MAX_DEPOSITS) + deposits = prepare_state_and_get_random_deposits(spec, state, rng, num_deposits=num_deposits) + return { + "deposits": deposits, + } + + +def randomize_state(spec, state, stats, exit_fraction=0.1, slash_fraction=0.1): randomize_state_helper(spec, state, exit_fraction=exit_fraction, slash_fraction=slash_fraction) + scenario_state = _randomize_deposit_state(spec, state, stats) + return scenario_state -def randomize_state_altair(spec, state): - randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) +def randomize_state_altair(spec, state, stats): + scenario_state = randomize_state(spec, state, stats, exit_fraction=0.1, slash_fraction=0.1) randomize_inactivity_scores(spec, state) + return scenario_state # epochs @@ -67,7 +90,7 @@ def penultimate_slot_in_epoch(spec): # blocks -def no_block(_spec, _pre_state, _signed_blocks): +def no_block(_spec, _pre_state, _signed_blocks, _scenario_state): return None @@ -77,9 +100,10 @@ BLOCK_ATTEMPTS = 32 def _warn_if_empty_operations(block): - if len(block.body.deposits) == 0: - warnings.warn(f"deposits missing in block at slot {block.slot}") - + """ + NOTE: a block may be missing deposits depending on how many were created + and already inserted into existing blocks in a given scenario. + """ if len(block.body.proposer_slashings) == 0: warnings.warn(f"proposer slashings missing in block at slot {block.slot}") @@ -93,7 +117,13 @@ def _warn_if_empty_operations(block): warnings.warn(f"voluntary exits missing in block at slot {block.slot}") -def random_block(spec, state, _signed_blocks): +def _pull_deposits_from_scenario_state(spec, scenario_state, existing_block_count): + all_deposits = scenario_state.get("deposits", []) + start = existing_block_count * spec.MAX_DEPOSITS + return all_deposits[start:start + spec.MAX_DEPOSITS] + + +def random_block(spec, state, signed_blocks, scenario_state): """ Produce a random block. NOTE: this helper may mutate state, as it will attempt @@ -118,7 +148,8 @@ def random_block(spec, state, _signed_blocks): next_slot(spec, state) next_slot(spec, temp_state) else: - block = build_random_block_from_state_for_next_slot(spec, state) + deposits_for_block = _pull_deposits_from_scenario_state(spec, scenario_state, len(signed_blocks)) + block = build_random_block_from_state_for_next_slot(spec, state, deposits=deposits_for_block) _warn_if_empty_operations(block) return block else: @@ -130,8 +161,9 @@ SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4 def random_block_altair_with_cycling_sync_committee_participation(spec, state, - signed_blocks): - block = random_block(spec, state, signed_blocks) + signed_blocks, + scenario_state): + block = random_block(spec, state, signed_blocks, scenario_state) block_index = len(signed_blocks) % SYNC_AGGREGATE_PARTICIPATION_BUCKETS fraction_missed = block_index * (1 / SYNC_AGGREGATE_PARTICIPATION_BUCKETS) fraction_participated = 1.0 - fraction_missed @@ -146,7 +178,7 @@ def random_block_altair_with_cycling_sync_committee_participation(spec, # validations -def no_op_validation(spec, state): +def no_op_validation(_spec, _state): return True @@ -211,12 +243,20 @@ def transition_with_random_block(block_randomizer): def _randomized_scenario_setup(state_randomizer): """ - Return a sequence of pairs of ("mutation", "validation"), - a function that accepts (spec, state) arguments and performs some change - and a function that accepts (spec, state) arguments and validates some change was made. + Return a sequence of pairs of ("mutation", "validation"). + A "mutation" is a function that accepts (``spec``, ``state``, ``stats``) arguments and + allegedly performs some change to the state. + A "validation" is a function that accepts (spec, state) arguments and validates some change was made. + + The "mutation" may return some state that should be available to any down-stream transitions + across the **entire** scenario. + + The ``stats`` parameter reflects a summary of actions in a given scenario like + how many blocks will be produced. This data can be useful to construct a valid + pre-state and so is provided at the setup stage. """ def _skip_epochs(epoch_producer): - def f(spec, state): + def f(spec, state, _stats): """ The unoptimized spec implementation is too slow to advance via ``next_epoch``. Instead, just overwrite the ``state.slot`` and continue... @@ -226,7 +266,7 @@ def _randomized_scenario_setup(state_randomizer): state.slot += slots_to_skip return f - def _simulate_honest_execution(spec, state): + def _simulate_honest_execution(spec, state, _stats): """ Want to start tests not in a leak state; the finality data may not reflect this condition with prior (arbitrary) mutations, @@ -286,14 +326,29 @@ def _iter_temporal(spec, description): yield i +def _compute_statistics(scenario): + block_count = 0 + for transition in scenario["transitions"]: + block_producer = _resolve_ref(transition.get("block_producer", None)) + if block_producer and block_producer != no_block: + block_count += 1 + return { + "block_count": block_count, + } + + def run_generated_randomized_test(spec, state, scenario): + stats = _compute_statistics(scenario) if "setup" not in scenario: state_randomizer = _resolve_ref(scenario.get("state_randomizer", randomize_state)) scenario["setup"] = _randomized_scenario_setup(state_randomizer) + scenario_state = {} for mutation, validation in scenario["setup"]: - mutation(spec, state) + additional_state = mutation(spec, state, stats) validation(spec, state) + if additional_state: + scenario_state.update(additional_state) yield "pre", state @@ -307,7 +362,7 @@ def run_generated_randomized_test(spec, state, scenario): next_slot(spec, state) block_producer = _resolve_ref(transition["block_producer"]) - block = block_producer(spec, state, blocks) + block = block_producer(spec, state, blocks, scenario_state) if block: signed_block = state_transition_and_sign_block(spec, state, block) blocks.append(signed_block) From 74fcf67cf45d0c80472bb6a177ff055ab6e171f9 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 26 Aug 2021 13:42:12 -0700 Subject: [PATCH 068/122] Fix a performance bug with the randomized block tests from #2560 --- tests/core/pyspec/eth2spec/test/helpers/multi_operations.py | 3 ++- .../core/pyspec/eth2spec/test/utils/randomized_block_tests.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 14b281a95..7528c4f0b 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -171,7 +171,7 @@ def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): return prepare_signed_exits(spec, state, exit_indices) -def get_random_sync_aggregate(spec, state, slot, fraction_participated=1.0, rng=Random(2099)): +def get_random_sync_aggregate(spec, state, slot, block_root=None, fraction_participated=1.0, rng=Random(2099)): committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) participant_count = int(len(committee_indices) * fraction_participated) participant_indices = rng.sample(range(len(committee_indices)), participant_count) @@ -184,6 +184,7 @@ def get_random_sync_aggregate(spec, state, slot, fraction_participated=1.0, rng= state, slot, participants, + block_root=block_root, ) return spec.SyncAggregate( sync_committee_bits=[index in participant_indices for index in range(len(committee_indices))], diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index 44dab0e0e..e055285d6 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -135,10 +135,12 @@ def random_block_altair_with_cycling_sync_committee_participation(spec, block_index = len(signed_blocks) % SYNC_AGGREGATE_PARTICIPATION_BUCKETS fraction_missed = block_index * (1 / SYNC_AGGREGATE_PARTICIPATION_BUCKETS) fraction_participated = 1.0 - fraction_missed + previous_root = block.parent_root block.body.sync_aggregate = get_random_sync_aggregate( spec, state, block.slot - 1, + block_root=previous_root, fraction_participated=fraction_participated, ) return block From 0bd3e0286b6917f744211a45b81275839db4e4e5 Mon Sep 17 00:00:00 2001 From: "Sam.An" <56215891+sammiee5311@users.noreply.github.com> Date: Fri, 27 Aug 2021 10:12:19 +0900 Subject: [PATCH 069/122] Clean up startswith method in setup.py `value.startswith(("uint", "Bytes", "ByteList", "Union"))` --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ccc3afbe4..281e292dc 100644 --- a/setup.py +++ b/setup.py @@ -223,7 +223,7 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str]) -> if not _is_constant_id(name): # Check for short type declarations - if value.startswith("uint") or value.startswith("Bytes") or value.startswith("ByteList") or value.startswith("Union"): + if value.startswith(("uint", "Bytes", "ByteList", "Union")): custom_types[name] = value continue From c097bdd89ba7f0773da6aea3abf4b0c93e4abfea Mon Sep 17 00:00:00 2001 From: Fredrik Svantes Date: Sat, 28 Aug 2021 01:30:41 +0200 Subject: [PATCH 070/122] Creating SECURITY.txt --- SECURITY.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..4c79f0872 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,11 @@ +# Security Policy + +## Supported Versions + +Please see [Releases](https://github.com/ethereum/consensus-specs/releases/). We recommend using the [most recently released version](https://github.com/ethereum/consensus-specs/releases/latest). + +## Reporting a Vulnerability + +**Please do not file a public ticket** mentioning the vulnerability. + +To find out how to disclose a vulnerability in the Ethereum Consensus Layer visit [https://eth2bounty.ethereum.org](https://eth2bounty.ethereum.org) or email eth2bounty@ethereum.org. Please read the [disclosure page](https://eth2bounty.ethereum.org) for more information about publically disclosed security vulnerabilities. From 5a84224d1a7f0be6f3391f1ac4a5af4cb8355c05 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Mon, 30 Aug 2021 18:23:25 +0600 Subject: [PATCH 071/122] Change transition_td to terminal_td in the merge spec --- specs/merge/fork-choice.md | 6 +++--- specs/merge/fork.md | 6 +++--- specs/merge/validator.md | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index 15ef1c301..de82b17fa 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -73,7 +73,7 @@ def finalize_block(self: ExecutionEngine, block_hash: Hash32) -> bool: ```python @dataclass class TransitionStore(object): - transition_total_difficulty: uint256 + terminal_total_difficulty: uint256 ``` ### `PowBlock` @@ -101,8 +101,8 @@ Used by fork-choice handler, `on_block`. ```python def is_valid_terminal_pow_block(transition_store: TransitionStore, block: PowBlock, parent: PowBlock) -> bool: - is_total_difficulty_reached = block.total_difficulty >= transition_store.transition_total_difficulty - is_parent_total_difficulty_valid = parent.total_difficulty < transition_store.transition_total_difficulty + is_total_difficulty_reached = block.total_difficulty >= transition_store.terminal_total_difficulty + is_parent_total_difficulty_valid = parent.total_difficulty < transition_store.terminal_total_difficulty return block.is_valid and is_total_difficulty_reached and is_parent_total_difficulty_valid ``` diff --git a/specs/merge/fork.md b/specs/merge/fork.md index 0a1271d82..f16be0574 100644 --- a/specs/merge/fork.md +++ b/specs/merge/fork.md @@ -108,7 +108,7 @@ If `state.slot % SLOTS_PER_EPOCH == 0` and `compute_epoch_at_slot(state.slot) == Transition store initialization occurs after the state has been modified by corresponding `upgrade_to_merge` function. ```python -def compute_transition_total_difficulty(anchor_pow_block: PowBlock) -> uint256: +def compute_terminal_total_difficulty(anchor_pow_block: PowBlock) -> uint256: seconds_per_voting_period = EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH * SECONDS_PER_SLOT pow_blocks_per_voting_period = seconds_per_voting_period // SECONDS_PER_ETH1_BLOCK pow_blocks_to_merge = TARGET_SECONDS_TO_MERGE // SECONDS_PER_ETH1_BLOCK @@ -119,8 +119,8 @@ def compute_transition_total_difficulty(anchor_pow_block: PowBlock) -> uint256: def get_transition_store(anchor_pow_block: PowBlock) -> TransitionStore: - transition_total_difficulty = compute_transition_total_difficulty(anchor_pow_block) - return TransitionStore(transition_total_difficulty=transition_total_difficulty) + terminal_total_difficulty = compute_terminal_total_difficulty(anchor_pow_block) + return TransitionStore(terminal_total_difficulty=terminal_total_difficulty) def initialize_transition_store(state: BeaconState) -> TransitionStore: diff --git a/specs/merge/validator.md b/specs/merge/validator.md index 84207e49c..efeeca061 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -95,7 +95,7 @@ def get_execution_payload(state: BeaconState, execution_engine: ExecutionEngine, pow_chain: Sequence[PowBlock]) -> ExecutionPayload: if not is_merge_complete(state): - terminal_pow_block = get_pow_block_at_total_difficulty(transition_store.transition_total_difficulty, pow_chain) + terminal_pow_block = get_pow_block_at_total_difficulty(transition_store.terminal_total_difficulty, pow_chain) if terminal_pow_block is None: # Pre-merge, empty payload return ExecutionPayload() From 387113b2f4011c27d0cfc2beb57afb7666ce0c69 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 30 Aug 2021 13:36:01 -0700 Subject: [PATCH 072/122] add "collect only" mode to spec test generator --- .../gen_helpers/gen_base/gen_runner.py | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py index 765fc501b..6850af188 100644 --- a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py +++ b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py @@ -77,6 +77,13 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): required=False, help="specify presets to run with. Allows all if no preset names are specified.", ) + parser.add_argument( + "-c", + "--collect-only", + action="store_true", + default=False, + help="if set only print tests to generate, do not actually run the test and dump the target data", + ) args = parser.parse_args() output_dir = args.output_dir @@ -100,12 +107,15 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): if len(presets) != 0: print(f"Filtering test-generator runs to only include presets: {', '.join(presets)}") + collect_only = args.collect_only + collected_test_count = 0 generated_test_count = 0 skipped_test_count = 0 provider_start = time.time() for tprov in test_providers: - # runs anything that we don't want to repeat for every test case. - tprov.prepare() + if not collect_only: + # runs anything that we don't want to repeat for every test case. + tprov.prepare() for test_case in tprov.make_cases(): case_dir = ( @@ -115,6 +125,11 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): ) incomplete_tag_file = case_dir / "INCOMPLETE" + collected_test_count += 1 + if collect_only: + print(f"Collected test at: {case_dir}") + continue + if case_dir.exists(): if not args.force and not incomplete_tag_file.exists(): skipped_test_count += 1 @@ -193,11 +208,14 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]): provider_end = time.time() span = round(provider_end - provider_start, 2) - summary_message = f"completed generation of {generator_name} with {generated_test_count} tests" - summary_message += f" ({skipped_test_count} skipped tests)" - if span > TIME_THRESHOLD_TO_PRINT: - summary_message += f" in {span} seconds" - print(summary_message) + if collect_only: + print(f"Collected {collected_test_count} tests in total") + else: + summary_message = f"completed generation of {generator_name} with {generated_test_count} tests" + summary_message += f" ({skipped_test_count} skipped tests)" + if span > TIME_THRESHOLD_TO_PRINT: + summary_message += f" in {span} seconds" + print(summary_message) def dump_yaml_fn(data: Any, name: str, file_mode: str, yaml_encoder: YAML): From 2477deaf1312539cc0e429452ffe3e2d608e6b28 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 30 Aug 2021 13:53:05 -0700 Subject: [PATCH 073/122] Allow test driver to batch test cases under one handler name with a list --- .../gen_helpers/gen_from_tests/gen.py | 25 +++++++++++-------- tests/generators/operations/main.py | 6 ++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py b/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py index db3f9e949..88bc6d601 100644 --- a/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py +++ b/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py @@ -1,6 +1,6 @@ from importlib import import_module from inspect import getmembers, isfunction -from typing import Any, Callable, Dict, Iterable, Optional +from typing import Any, Callable, Dict, Iterable, Optional, List, Union from eth2spec.utils import bls from eth2spec.test.helpers.constants import ALL_PRESETS, TESTGEN_FORKS @@ -59,8 +59,10 @@ def generate_from_tests(runner_name: str, handler_name: str, src: Any, def get_provider(create_provider_fn: Callable[[SpecForkName, PresetBaseName, str, str], TestProvider], fork_name: SpecForkName, preset_name: PresetBaseName, - all_mods: Dict[str, Dict[str, str]]) -> Iterable[TestProvider]: + all_mods: Dict[str, Dict[str, Union[List[str], str]]]) -> Iterable[TestProvider]: for key, mod_name in all_mods[fork_name].items(): + if not isinstance(mod_name, List): + mod_name = [mod_name] yield create_provider_fn( fork_name=fork_name, preset_name=preset_name, @@ -75,16 +77,17 @@ def get_create_provider_fn(runner_name: str) -> Callable[[SpecForkName, str, str return def create_provider(fork_name: SpecForkName, preset_name: PresetBaseName, - handler_name: str, tests_src_mod_name: str) -> TestProvider: + handler_name: str, tests_src_mod_name: List[str]) -> TestProvider: def cases_fn() -> Iterable[TestCase]: - tests_src = import_module(tests_src_mod_name) - return generate_from_tests( - runner_name=runner_name, - handler_name=handler_name, - src=tests_src, - fork_name=fork_name, - preset_name=preset_name, - ) + for mod_name in tests_src_mod_name: + tests_src = import_module(mod_name) + yield from generate_from_tests( + runner_name=runner_name, + handler_name=handler_name, + src=tests_src, + fork_name=fork_name, + preset_name=preset_name, + ) return TestProvider(prepare=prepare_fn, make_cases=cases_fn) return create_provider diff --git a/tests/generators/operations/main.py b/tests/generators/operations/main.py index d2653d87d..0f4da69a5 100644 --- a/tests/generators/operations/main.py +++ b/tests/generators/operations/main.py @@ -12,9 +12,9 @@ if __name__ == "__main__": 'voluntary_exit', ]} altair_mods = { - **{key: 'eth2spec.test.altair.block_processing.sync_aggregate.test_process_' + key for key in [ - 'sync_aggregate', - 'sync_aggregate_random', + **{'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 From 58e667b3d5b579668bf859335f0b96d1c4331ee3 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 30 Aug 2021 16:29:41 -0600 Subject: [PATCH 074/122] spelling --- SECURITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SECURITY.md b/SECURITY.md index 4c79f0872..e46fab4de 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -8,4 +8,4 @@ Please see [Releases](https://github.com/ethereum/consensus-specs/releases/). We **Please do not file a public ticket** mentioning the vulnerability. -To find out how to disclose a vulnerability in the Ethereum Consensus Layer visit [https://eth2bounty.ethereum.org](https://eth2bounty.ethereum.org) or email eth2bounty@ethereum.org. Please read the [disclosure page](https://eth2bounty.ethereum.org) for more information about publically disclosed security vulnerabilities. +To find out how to disclose a vulnerability in the Ethereum Consensus Layer visit [https://eth2bounty.ethereum.org](https://eth2bounty.ethereum.org) or email eth2bounty@ethereum.org. Please read the [disclosure page](https://eth2bounty.ethereum.org) for more information about publicly disclosed security vulnerabilities. From 189a9d4ae993ce29ec1088ba2f50610819e14ca8 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 31 Aug 2021 12:10:37 +0800 Subject: [PATCH 075/122] Add the missed on_tick output and remove the useless on_tick call --- .../eth2spec/test/phase0/fork_choice/test_on_block.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py index 634610fe7..457eef7ff 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py @@ -483,7 +483,8 @@ def test_new_justified_is_later_than_store_justified(spec, state): assert fork_2_state.finalized_checkpoint.epoch == 0 assert fork_2_state.current_justified_checkpoint.epoch == 5 # Check SAFE_SLOTS_TO_UPDATE_JUSTIFIED - spec.on_tick(store, store.genesis_time + fork_2_state.slot * spec.config.SECONDS_PER_SLOT) + time = store.genesis_time + fork_2_state.slot * spec.config.SECONDS_PER_SLOT + on_tick_and_append_step(spec, store, time, test_steps) assert spec.compute_slots_since_epoch_start(spec.get_current_slot(store)) >= spec.SAFE_SLOTS_TO_UPDATE_JUSTIFIED # Run on_block yield from add_block(spec, store, signed_block, test_steps) @@ -526,7 +527,8 @@ def test_new_justified_is_later_than_store_justified(spec, state): # # Apply blocks of `fork_3_state` to `store` # for block in all_blocks: # if store.time < spec.compute_time_at_slot(fork_2_state, block.message.slot): - # spec.on_tick(store, store.genesis_time + block.message.slot * spec.config.SECONDS_PER_SLOT) + # time = store.genesis_time + block.message.slot * spec.config.SECONDS_PER_SLOT + # on_tick_and_append_step(spec, store, time, test_steps) # # valid_attestations=False because the attestations are outdated (older than previous epoch) # yield from add_block(spec, store, block, test_steps, allow_invalid_attestations=False) @@ -643,7 +645,6 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state): # Process state next_epoch(spec, state) - spec.on_tick(store, store.genesis_time + state.slot * spec.config.SECONDS_PER_SLOT) state, store, _ = yield from apply_next_epoch_with_attestations( spec, state, store, False, True, test_steps=test_steps) From da8d22c7541d78774b2a1179dca225d63b8e24e2 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 31 Aug 2021 13:16:19 +0800 Subject: [PATCH 076/122] Update `checks` Checkpoint fields --- .../eth2spec/test/helpers/fork_choice.py | 15 ++++++-- tests/formats/fork_choice/README.md | 36 +++++++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py index ec5793af5..65d6975f2 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py +++ b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py @@ -156,9 +156,18 @@ def add_block(spec, store, signed_block, test_steps, valid=True, allow_invalid_a 'checks': { 'time': int(store.time), 'head': get_formatted_head_output(spec, store), - 'justified_checkpoint_root': encode_hex(store.justified_checkpoint.root), - 'finalized_checkpoint_root': encode_hex(store.finalized_checkpoint.root), - 'best_justified_checkpoint': encode_hex(store.best_justified_checkpoint.root), + 'justified_checkpoint': { + 'epoch': int(store.justified_checkpoint.epoch), + 'root': encode_hex(store.justified_checkpoint.root), + }, + 'finalized_checkpoint': { + 'epoch': int(store.finalized_checkpoint.epoch), + 'root': encode_hex(store.finalized_checkpoint.root), + }, + 'best_justified_checkpoint': { + 'epoch': int(store.best_justified_checkpoint.epoch), + 'root': encode_hex(store.best_justified_checkpoint.root), + }, } }) diff --git a/tests/formats/fork_choice/README.md b/tests/formats/fork_choice/README.md index 90c0aafc7..cfc86776d 100644 --- a/tests/formats/fork_choice/README.md +++ b/tests/formats/fork_choice/README.md @@ -80,26 +80,34 @@ checks: {: value} -- the assertions. `` is the field member or property of [`Store`](../../../specs/phase0/fork-choice.md#store) object that maintained by client implementation. Currently, the possible fields included: ```yaml -head: { -- Encoded 32-byte value from get_head(store) - slot: slot, - root: string, +head: { + slot: int, + root: string, -- Encoded 32-byte value from get_head(store) +} +time: int -- store.time +genesis_time: int -- store.genesis_time +justified_checkpoint: { + epoch: int, -- Integer value from store.justified_checkpoint.epoch + root: string, -- Encoded 32-byte value from store.justified_checkpoint.root +} +finalized_checkpoint: { + epoch: int, -- Integer value from store.finalized_checkpoint.epoch + root: string, -- Encoded 32-byte value from store.finalized_checkpoint.root +} +best_justified_checkpoint: { + epoch: int, -- Integer value from store.best_justified_checkpoint.epoch + root: string, -- Encoded 32-byte value from store.best_justified_checkpoint.root } -time: int -- store.time -genesis_time: int -- store.genesis_time -justified_checkpoint_root: string -- Encoded 32-byte value from store.justified_checkpoint.root -finalized_checkpoint_root: string -- Encoded 32-byte value from store.finalized_checkpoint.root -best_justified_checkpoint_root: string -- Encoded 32-byte value from store.best_justified_checkpoint.root ``` For example: ```yaml - checks: - time: 144 - genesis_time: 0 - head: {slot: 17, root: '0xd2724c86002f7e1f8656ab44a341a409ad80e6e70a5225fd94835566deebb66f'} - justified_checkpoint_root: '0xcea6ecd3d3188e32ebf611f960eebd45b6c6f477a7cff242fa567a42653bfc7c' - finalized_checkpoint_root: '0xcea6ecd3d3188e32ebf611f960eebd45b6c6f477a7cff242fa567a42653bfc7c' - best_justified_checkpoint: '0xcea6ecd3d3188e32ebf611f960eebd45b6c6f477a7cff242fa567a42653bfc7c' + time: 192 + head: {slot: 32, root: '0xdaa1d49d57594ced0c35688a6da133abb086d191a2ebdfd736fad95299325aeb'} + justified_checkpoint: {epoch: 3, root: '0xc25faab4acab38d3560864ca01e4d5cc4dc2cd473da053fbc03c2669143a2de4'} + finalized_checkpoint: {epoch: 2, root: '0x40d32d6283ec11c53317a46808bc88f55657d93b95a1af920403187accf48f4f'} + best_justified_checkpoint: {epoch: 3, root: '0xc25faab4acab38d3560864ca01e4d5cc4dc2cd473da053fbc03c2669143a2de4'} ``` *Note*: Each `checks` step may include one or multiple items. Each item has to be checked against the current store. From 9b065c78167d1288e58913b56868e742207cd85e Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 31 Aug 2021 17:42:10 +0800 Subject: [PATCH 077/122] To avoid using non-genesis anchor state, rewrite `test_on_block_finalized_skip_slots_not_in_skip_chain` --- .../test/phase0/fork_choice/test_on_block.py | 83 +++++++++++-------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py index 457eef7ff..0a3802338 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py @@ -26,7 +26,6 @@ from eth2spec.test.helpers.state import ( next_epoch, next_slots, state_transition_and_sign_block, - transition_to, ) @@ -191,6 +190,10 @@ def test_on_block_before_finalized(spec, state): @spec_state_test @with_presets([MINIMAL], reason="too slow") def test_on_block_finalized_skip_slots(spec, state): + """ + Test case was originally from https://github.com/ethereum/consensus-specs/pull/1579 + And then rewrote largely. + """ test_steps = [] # Initialization store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -200,21 +203,28 @@ def test_on_block_finalized_skip_slots(spec, state): on_tick_and_append_step(spec, store, current_time, test_steps) assert store.time == current_time - # Create a finalized chain - for _ in range(4): + # Fill epoch 0 and the first slot of epoch 1 + state, store, _ = yield from apply_next_slots_with_attestations( + spec, state, store, spec.SLOTS_PER_EPOCH, True, False, test_steps) + + # Skip the rest slots of epoch 1 and the first slot of epoch 2 + next_slots(spec, state, spec.SLOTS_PER_EPOCH) + + # Fill epoch 3 and 4 + for _ in range(2): state, store, _ = yield from apply_next_epoch_with_attestations( - spec, state, store, True, False, test_steps=test_steps) - assert store.finalized_checkpoint.epoch == 2 + spec, state, store, True, True, test_steps=test_steps) - # Another chain - another_state = store.block_states[store.finalized_checkpoint.root].copy() - # Build block that includes the skipped slots up to finality in chain - block = build_empty_block(spec, - another_state, - spec.compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + 2) - block.body.graffiti = b'\x12' * 32 - signed_block = state_transition_and_sign_block(spec, another_state, block) + # Now we get finalized epoch 1, where compute_start_slot_at_epoch(1) is a skipped slot + assert state.finalized_checkpoint.epoch == store.finalized_checkpoint.epoch == 2 + assert store.finalized_checkpoint.root == spec.get_block_root(state, 1) == spec.get_block_root(state, 2) + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + assert store.justified_checkpoint == state.current_justified_checkpoint + # Now build a block at later slot than finalized *epoch* + # Includes finalized block in chain and the skipped slots + block = build_empty_block_for_next_slot(spec, state) + signed_block = state_transition_and_sign_block(spec, state, block) yield from tick_and_add_block(spec, store, signed_block, test_steps) yield 'steps', test_steps @@ -224,36 +234,43 @@ def test_on_block_finalized_skip_slots(spec, state): @spec_state_test @with_presets([MINIMAL], reason="too slow") def test_on_block_finalized_skip_slots_not_in_skip_chain(spec, state): + """ + Test case was originally from https://github.com/ethereum/consensus-specs/pull/1579 + And then rewrote largely. + """ test_steps = [] # Initialization - transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH - 1) - block = build_empty_block_for_next_slot(spec, state) - transition_unsigned_block(spec, state, block) - block.state_root = state.hash_tree_root() - store = spec.get_forkchoice_store(state, block) + store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) yield 'anchor_state', state - yield 'anchor_block', block - + yield 'anchor_block', anchor_block current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) assert store.time == current_time - pre_finalized_checkpoint_epoch = store.finalized_checkpoint.epoch + # Fill epoch 0 and the first slot of epoch 1 + state, store, _ = yield from apply_next_slots_with_attestations( + spec, state, store, spec.SLOTS_PER_EPOCH, True, False, test_steps) - # Finalized - for _ in range(3): + # Skip the rest slots of epoch 1 and the first slot of epoch 2 + next_slots(spec, state, spec.SLOTS_PER_EPOCH) + + # Fill epoch 3 and 4 + for _ in range(2): state, store, _ = yield from apply_next_epoch_with_attestations( - spec, state, store, True, False, test_steps=test_steps) - assert store.finalized_checkpoint.epoch == pre_finalized_checkpoint_epoch + 1 + spec, state, store, True, True, test_steps=test_steps) - # Now build a block at later slot than finalized epoch - # Includes finalized block in chain, but not at appropriate skip slot - pre_state = store.block_states[block.hash_tree_root()].copy() - block = build_empty_block(spec, - state=pre_state, - slot=spec.compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + 2) - block.body.graffiti = b'\x12' * 32 - signed_block = sign_block(spec, pre_state, block) + # Now we get finalized epoch 1, where compute_start_slot_at_epoch(1) is a skipped slot + assert state.finalized_checkpoint.epoch == store.finalized_checkpoint.epoch == 2 + assert store.finalized_checkpoint.root == spec.get_block_root(state, 1) == spec.get_block_root(state, 2) + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + assert store.justified_checkpoint == state.current_justified_checkpoint + + # Now build a block after the block of the finalized **root** + # Includes finalized block in chain, but does not include finalized skipped slots + another_state = store.block_states[store.finalized_checkpoint.root].copy() + assert another_state.slot == spec.compute_start_slot_at_epoch(store.finalized_checkpoint.epoch - 1) + block = build_empty_block_for_next_slot(spec, another_state) + signed_block = state_transition_and_sign_block(spec, another_state, block) yield from tick_and_add_block(spec, store, signed_block, test_steps, valid=False) yield 'steps', test_steps From 085045a8605f33f5a19398a651fd5e8f5e0fccdb Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 31 Aug 2021 18:00:41 +0800 Subject: [PATCH 078/122] Since merge spec was rebased, make `merge_mods` base on `altair_mods` instead of `phase_0_mods` --- tests/generators/epoch_processing/main.py | 3 +-- tests/generators/finality/main.py | 2 +- tests/generators/fork_choice/main.py | 4 ++-- tests/generators/operations/main.py | 2 +- tests/generators/rewards/main.py | 2 +- tests/generators/sanity/main.py | 6 ++---- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/generators/epoch_processing/main.py b/tests/generators/epoch_processing/main.py index 7203bac93..4c1a68d0a 100644 --- a/tests/generators/epoch_processing/main.py +++ b/tests/generators/epoch_processing/main.py @@ -25,8 +25,7 @@ if __name__ == "__main__": } # 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. - # TODO: rebase onto Altair testing later. - merge_mods = phase_0_mods + merge_mods = altair_mods # TODO Custody Game testgen is disabled for now # custody_game_mods = {**{key: 'eth2spec.test.custody_game.epoch_processing.test_process_' + key for key in [ diff --git a/tests/generators/finality/main.py b/tests/generators/finality/main.py index b4c8da39a..dbc58a809 100644 --- a/tests/generators/finality/main.py +++ b/tests/generators/finality/main.py @@ -5,7 +5,7 @@ from eth2spec.test.helpers.constants import PHASE0, ALTAIR, MERGE if __name__ == "__main__": phase_0_mods = {'finality': 'eth2spec.test.phase0.finality.test_finality'} altair_mods = phase_0_mods # No additional Altair specific finality tests - merge_mods = phase_0_mods # No additional Merge specific finality tests + merge_mods = altair_mods # No additional Merge specific finality tests all_mods = { PHASE0: phase_0_mods, diff --git a/tests/generators/fork_choice/main.py b/tests/generators/fork_choice/main.py index 0ebdbf2c0..148174120 100644 --- a/tests/generators/fork_choice/main.py +++ b/tests/generators/fork_choice/main.py @@ -9,8 +9,8 @@ if __name__ == "__main__": ]} # No additional Altair specific finality tests, yet. altair_mods = phase_0_mods - # No specific Merge tests yet. TODO: rebase onto Altair testing later. - merge_mods = phase_0_mods + # No specific Merge tests yet. + merge_mods = altair_mods all_mods = { PHASE0: phase_0_mods, diff --git a/tests/generators/operations/main.py b/tests/generators/operations/main.py index d2653d87d..cc578d3ef 100644 --- a/tests/generators/operations/main.py +++ b/tests/generators/operations/main.py @@ -23,7 +23,7 @@ if __name__ == "__main__": **{key: 'eth2spec.test.merge.block_processing.test_process_' + key for key in [ 'execution_payload', ]}, - **phase_0_mods, # TODO: runs phase0 tests. Rebase to include `altair_mods` testing later. + **altair_mods, } # TODO Custody Game testgen is disabled for now diff --git a/tests/generators/rewards/main.py b/tests/generators/rewards/main.py index a3072daca..6b6a7bc6f 100644 --- a/tests/generators/rewards/main.py +++ b/tests/generators/rewards/main.py @@ -14,7 +14,7 @@ if __name__ == "__main__": # No additional merge specific rewards tests, yet. # Note: Block rewards are non-epoch rewards and are tested as part of block processing tests. # Transaction fees are part of the execution-layer. - merge_mods = phase_0_mods + merge_mods = altair_mods all_mods = { PHASE0: phase_0_mods, diff --git a/tests/generators/sanity/main.py b/tests/generators/sanity/main.py index 8caedc8e5..f5a6ccb41 100644 --- a/tests/generators/sanity/main.py +++ b/tests/generators/sanity/main.py @@ -9,12 +9,10 @@ if __name__ == "__main__": ]} altair_mods = {**{key: 'eth2spec.test.altair.sanity.test_' + key for key in [ 'blocks', - ]}, **phase_0_mods} # also run the previous phase 0 tests - - # Altair-specific test cases are ignored, but should be included after the Merge is rebased onto Altair work. + ]}, **phase_0_mods} merge_mods = {**{key: 'eth2spec.test.merge.sanity.test_' + key for key in [ 'blocks', - ]}, **phase_0_mods} # TODO: Merge inherits phase0 tests for now. + ]}, **altair_mods} all_mods = { PHASE0: phase_0_mods, From b23ed05eee5f499d3ff41f8356c19bd07b01e0ca Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 31 Aug 2021 18:40:26 +0800 Subject: [PATCH 079/122] [`test_on_block_finalized_skip_slots`] Make target state right after skipped slots --- .../eth2spec/test/phase0/fork_choice/test_on_block.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py index 0a3802338..8227c4cfb 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py @@ -210,6 +210,9 @@ def test_on_block_finalized_skip_slots(spec, state): # Skip the rest slots of epoch 1 and the first slot of epoch 2 next_slots(spec, state, spec.SLOTS_PER_EPOCH) + # The state after the skipped slots + target_state = state.copy() + # Fill epoch 3 and 4 for _ in range(2): state, store, _ = yield from apply_next_epoch_with_attestations( @@ -223,8 +226,8 @@ def test_on_block_finalized_skip_slots(spec, state): # Now build a block at later slot than finalized *epoch* # Includes finalized block in chain and the skipped slots - block = build_empty_block_for_next_slot(spec, state) - signed_block = state_transition_and_sign_block(spec, state, block) + block = build_empty_block_for_next_slot(spec, target_state) + signed_block = state_transition_and_sign_block(spec, target_state, block) yield from tick_and_add_block(spec, store, signed_block, test_steps) yield 'steps', test_steps From 4c34518edf54f041824f114ac2ddba4383cf92b7 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 1 Sep 2021 00:23:42 +0800 Subject: [PATCH 080/122] Call Altair and Merge operations in `process_and_sign_block_without_header_validations` --- .../pyspec/eth2spec/test/phase0/sanity/test_blocks.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index a79ed94d2..78b91ea91 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -19,6 +19,7 @@ from eth2spec.test.helpers.attester_slashings import ( from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing, check_proposer_slashing_effect from eth2spec.test.helpers.attestations import get_valid_attestation from eth2spec.test.helpers.deposits import prepare_state_and_deposit +from eth2spec.test.helpers.execution_payload import build_empty_execution_payload from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits from eth2spec.test.helpers.multi_operations import ( run_slash_and_exit, @@ -38,6 +39,7 @@ from eth2spec.test.context import ( with_custom_state, large_validator_set, is_post_altair, + is_post_merge, ) @@ -146,6 +148,11 @@ def process_and_sign_block_without_header_validations(spec, state, block): spec.process_randao(state, block.body) spec.process_eth1_data(state, block.body) spec.process_operations(state, block.body) + if is_post_altair(spec): + spec.process_sync_aggregate(state, block.body.sync_aggregate) + if is_post_merge(spec): + if spec.is_execution_enabled(state, block.body): + spec.process_execution_payload(state, block.body.execution_payload, spec.EXECUTION_ENGINE) # Insert post-state rot block.state_root = state.hash_tree_root() @@ -188,6 +195,10 @@ def test_parent_from_same_slot(spec, state): child_block = parent_block.copy() child_block.parent_root = state.latest_block_header.hash_tree_root() + if is_post_merge(spec): + randao_mix = spec.compute_randao_mix(state, child_block.body.randao_reveal) + child_block.body.execution_payload = build_empty_execution_payload(spec, state, randao_mix) + # Show that normal path through transition fails failed_state = state.copy() expect_assertion_error( From 9bf8ad91306a055e251d83017252f9d751a0e2f3 Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Thu, 2 Sep 2021 11:00:51 +0200 Subject: [PATCH 081/122] Update test_process_sync_aggregate.py --- .../sync_aggregate/test_process_sync_aggregate.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index 4be6737e2..58acdbdde 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -23,7 +23,6 @@ from eth2spec.test.context import ( always_bls, ) - @with_altair_and_later @spec_state_test @always_bls @@ -33,9 +32,8 @@ def test_invalid_signature_bad_domain(spec, state): random_participant = rng.choice(committee_indices) block = build_empty_block_for_next_slot(spec, state) - # Exclude one participant whose signature was included. block.body.sync_aggregate = spec.SyncAggregate( - sync_committee_bits=[index != random_participant for index in committee_indices], + sync_committee_bits= committee_indices, sync_committee_signature=compute_aggregate_sync_committee_signature( spec, state, From 2d736139d51cb8204cc10cb6522784f9b8177346 Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Thu, 2 Sep 2021 11:19:58 +0200 Subject: [PATCH 082/122] Update test_process_sync_aggregate.py --- .../sync_aggregate/test_process_sync_aggregate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index 58acdbdde..fdb872d6e 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -33,7 +33,7 @@ def test_invalid_signature_bad_domain(spec, state): block = build_empty_block_for_next_slot(spec, state) block.body.sync_aggregate = spec.SyncAggregate( - sync_committee_bits= committee_indices, + sync_committee_bits=committee_indices, sync_committee_signature=compute_aggregate_sync_committee_signature( spec, state, From 2206a583351a4e1bd8b27e230241b912e91f321f Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Thu, 2 Sep 2021 11:33:12 +0200 Subject: [PATCH 083/122] Update test_process_sync_aggregate.py --- .../sync_aggregate/test_process_sync_aggregate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index fdb872d6e..840d1d63d 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -23,6 +23,7 @@ from eth2spec.test.context import ( always_bls, ) + @with_altair_and_later @spec_state_test @always_bls From 5f1a444e70ef6c597bff1781ec1ab39d319fef36 Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Thu, 2 Sep 2021 11:34:42 +0200 Subject: [PATCH 084/122] Update test_process_sync_aggregate.py --- .../sync_aggregate/test_process_sync_aggregate.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index 840d1d63d..95e0284d2 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -29,8 +29,6 @@ from eth2spec.test.context import ( @always_bls def test_invalid_signature_bad_domain(spec, state): committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) - rng = random.Random(2020) - random_participant = rng.choice(committee_indices) block = build_empty_block_for_next_slot(spec, state) block.body.sync_aggregate = spec.SyncAggregate( From ae8c0447efbd89004107d4e15ca07b103f648737 Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Thu, 2 Sep 2021 14:57:47 +0200 Subject: [PATCH 085/122] Update tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py Co-authored-by: Alex Stokes --- .../sync_aggregate/test_process_sync_aggregate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index 95e0284d2..bd52ce727 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -32,7 +32,7 @@ def test_invalid_signature_bad_domain(spec, state): block = build_empty_block_for_next_slot(spec, state) block.body.sync_aggregate = spec.SyncAggregate( - sync_committee_bits=committee_indices, + sync_committee_bits=[True] * len(committee_indices), sync_committee_signature=compute_aggregate_sync_committee_signature( spec, state, From e341f4e1f858ac678ab9f9c052b01588d67612cc Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 31 Aug 2021 12:45:47 -0700 Subject: [PATCH 086/122] refactor "leaking patch" helper --- .../pyspec/eth2spec/test/helpers/random.py | 30 +++++++++++++++++++ .../test/utils/randomized_block_tests.py | 19 ++---------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/random.py b/tests/core/pyspec/eth2spec/test/helpers/random.py index 8f095aebb..0bb2a6672 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/random.py +++ b/tests/core/pyspec/eth2spec/test/helpers/random.py @@ -128,3 +128,33 @@ def randomize_state(spec, state, rng=Random(8020), exit_fraction=None, slash_fra exit_random_validators(spec, state, rng, fraction=exit_fraction) slash_random_validators(spec, state, rng, fraction=slash_fraction) randomize_attestation_participation(spec, state, rng) + + +def patch_state_to_non_leaking(spec, state): + """ + This function performs an irregular state transition so that: + 1. the current justified checkpoint references the previous epoch + 2. the previous justified checkpoint references the epoch before previous + 3. the finalized checkpoint matches the previous justified checkpoint + + The effects of this function are intended to offset randomization side effects + performed by other functionality in this module so that if the ``state`` was leaking, + then the ``state`` is not leaking after. + """ + state.justification_bits = (True, True, True, True) + previous_epoch = spec.get_previous_epoch(state) + previous_root = spec.get_block_root(state, previous_epoch) + previous_previous_epoch = max(spec.GENESIS_EPOCH, spec.Epoch(previous_epoch - 1)) + previous_previous_root = spec.get_block_root(state, previous_previous_epoch) + state.previous_justified_checkpoint = spec.Checkpoint( + epoch=previous_previous_epoch, + root=previous_previous_root, + ) + state.current_justified_checkpoint = spec.Checkpoint( + epoch=previous_epoch, + root=previous_root, + ) + state.finalized_checkpoint = spec.Checkpoint( + epoch=previous_previous_epoch, + root=previous_previous_root, + ) diff --git a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py index ce99c1053..02a5464f7 100644 --- a/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py @@ -17,6 +17,7 @@ from eth2spec.test.helpers.inactivity_scores import ( ) from eth2spec.test.helpers.random import ( randomize_state as randomize_state_helper, + patch_state_to_non_leaking, ) from eth2spec.test.helpers.state import ( next_slot, @@ -274,23 +275,7 @@ def _randomized_scenario_setup(state_randomizer): may not reflect this condition with prior (arbitrary) mutations, so this mutator addresses that fact. """ - state.justification_bits = (True, True, True, True) - previous_epoch = spec.get_previous_epoch(state) - previous_root = spec.get_block_root(state, previous_epoch) - previous_previous_epoch = max(spec.GENESIS_EPOCH, spec.Epoch(previous_epoch - 1)) - previous_previous_root = spec.get_block_root(state, previous_previous_epoch) - state.previous_justified_checkpoint = spec.Checkpoint( - epoch=previous_previous_epoch, - root=previous_previous_root, - ) - state.current_justified_checkpoint = spec.Checkpoint( - epoch=previous_epoch, - root=previous_root, - ) - state.finalized_checkpoint = spec.Checkpoint( - epoch=previous_previous_epoch, - root=previous_previous_root, - ) + patch_state_to_non_leaking(spec, state) return ( # NOTE: the block randomization function assumes at least 1 shard committee period From 7cb5901ee62d2ec99ff05537c079db2d3f055402 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 31 Aug 2021 12:46:00 -0700 Subject: [PATCH 087/122] add spec test case for rewards with exited validators and _no_ leak --- tests/core/pyspec/eth2spec/test/helpers/rewards.py | 14 +++++++++++++- .../eth2spec/test/phase0/rewards/test_random.py | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/rewards.py b/tests/core/pyspec/eth2spec/test/helpers/rewards.py index 1867db08f..ec617bda9 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/rewards.py +++ b/tests/core/pyspec/eth2spec/test/helpers/rewards.py @@ -255,7 +255,19 @@ def run_get_inactivity_penalty_deltas(spec, state): else: assert penalties[index] > base_penalty else: - assert penalties[index] == 0 + if not is_post_altair(spec): + assert penalties[index] == 0 + continue + else: + # post altair, this penalty is derived from the inactivity score + # regardless if the state is leaking or not... + if index in matching_attesting_indices: + assert penalties[index] == 0 + else: + # copied from spec: + penalty_numerator = state.validators[index].effective_balance * state.inactivity_scores[index] + penalty_denominator = spec.config.INACTIVITY_SCORE_BIAS * spec.INACTIVITY_PENALTY_QUOTIENT_ALTAIR + assert penalties[index] == penalty_numerator // penalty_denominator def transition_state_to_leak(spec, state, epochs=None): diff --git a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py index 1184a6617..78c6846ae 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py @@ -9,6 +9,7 @@ from eth2spec.test.context import ( low_balances, misc_balances, ) import eth2spec.test.helpers.rewards as rewards_helpers +from eth2spec.test.helpers.random import randomize_state, patch_state_to_non_leaking @with_all_phases @@ -57,3 +58,14 @@ def test_full_random_low_balances_1(spec, state): @single_phase def test_full_random_misc_balances(spec, state): yield from rewards_helpers.run_test_full_random(spec, state, rng=Random(7070)) + + +@with_all_phases +@spec_state_test +def test_full_random_without_leak_0(spec, state): + rng = Random(1010) + randomize_state(spec, state, rng) + assert spec.is_in_inactivity_leak(state) + patch_state_to_non_leaking(spec, state) + assert not spec.is_in_inactivity_leak(state) + yield from rewards_helpers.run_deltas(spec, state) From cf23cd00ab2c5bf4fe5addfed5df1be06402bf2a Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 1 Sep 2021 14:38:02 -0700 Subject: [PATCH 088/122] ensure the test covers exited, unslashed validators --- tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py | 7 +++++++ .../pyspec/eth2spec/test/phase0/rewards/test_random.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py b/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py index 73d4598b3..55ea0b5b0 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py +++ b/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py @@ -34,6 +34,13 @@ def get_exited_validators(spec, state): return [index for (index, validator) in enumerate(state.validators) if validator.exit_epoch <= current_epoch] +def get_unslashed_exited_validators(spec, state): + return [ + index for index in get_exited_validators(spec, state) + if not state.validators[index].slashed + ] + + def exit_validators(spec, state, validator_count, rng=None): if rng is None: rng = Random(1337) diff --git a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py index 78c6846ae..f158f3cf8 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py @@ -10,6 +10,7 @@ from eth2spec.test.context import ( ) import eth2spec.test.helpers.rewards as rewards_helpers from eth2spec.test.helpers.random import randomize_state, patch_state_to_non_leaking +from eth2spec.test.helpers.voluntary_exits import get_unslashed_exited_validators @with_all_phases @@ -68,4 +69,6 @@ def test_full_random_without_leak_0(spec, state): assert spec.is_in_inactivity_leak(state) patch_state_to_non_leaking(spec, state) assert not spec.is_in_inactivity_leak(state) + target_validators = get_unslashed_exited_validators(spec, state) + assert len(target_validators) != 0 yield from rewards_helpers.run_deltas(spec, state) From 0cc5f9cd59369ead4088b07580817fb66a5fc6e0 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 1 Sep 2021 14:43:11 -0700 Subject: [PATCH 089/122] modify helper for more precision on exited validators --- tests/core/pyspec/eth2spec/test/helpers/state.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index b4c9e1d67..d8fda3754 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -1,6 +1,6 @@ from eth2spec.test.context import expect_assertion_error, is_post_altair from eth2spec.test.helpers.block import apply_empty_block, sign_block, transition_unsigned_block -from eth2spec.test.helpers.voluntary_exits import get_exited_validators +from eth2spec.test.helpers.voluntary_exits import get_unslashed_exited_validators def get_balance(state, index): @@ -142,7 +142,7 @@ def ensure_state_has_validators_across_lifecycle(spec, state): for each of the following lifecycle states: 1. Pending / deposited 2. Active - 3. Exited + 3. Exited (but not slashed) 4. Slashed """ has_pending = any(filter(spec.is_eligible_for_activation_queue, state.validators)) @@ -150,7 +150,7 @@ def ensure_state_has_validators_across_lifecycle(spec, state): current_epoch = spec.get_current_epoch(state) has_active = any(filter(lambda v: spec.is_active_validator(v, current_epoch), state.validators)) - has_exited = any(get_exited_validators(spec, state)) + has_exited = any(get_unslashed_exited_validators(spec, state)) has_slashed = any(filter(lambda v: v.slashed, state.validators)) From 58c0da9059844e879593f2aff5ee081d01587c01 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 1 Sep 2021 14:44:06 -0700 Subject: [PATCH 090/122] ensure rewards spec test with exited validators --- .../eth2spec/test/phase0/rewards/test_random.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py index f158f3cf8..68a6a3279 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py @@ -37,6 +37,20 @@ def test_full_random_3(spec, state): yield from rewards_helpers.run_test_full_random(spec, state, rng=Random(4040)) +@with_all_phases +@spec_state_test +def test_full_random_4(spec, state): + """ + Ensure a rewards test with some exited (but not slashed) validators. + """ + rng = Random(5050) + randomize_state(spec, state, rng) + assert spec.is_in_inactivity_leak(state) + target_validators = get_unslashed_exited_validators(spec, state) + assert len(target_validators) != 0 + yield from rewards_helpers.run_deltas(spec, state) + + @with_all_phases @with_custom_state(balances_fn=low_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) @spec_test From df8976377736c2d9121cb63454345cdb6011eaa0 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 1 Sep 2021 15:46:40 -0700 Subject: [PATCH 091/122] ensure balance differential as a sanity check --- tests/core/pyspec/eth2spec/test/helpers/state.py | 12 ++++++++++++ .../eth2spec/test/phase0/rewards/test_random.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index d8fda3754..327bebaf8 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -155,3 +155,15 @@ def ensure_state_has_validators_across_lifecycle(spec, state): has_slashed = any(filter(lambda v: v.slashed, state.validators)) return has_pending and has_active and has_exited and has_slashed + + +def has_active_balance_differential(spec, state): + """ + Ensure there is a difference between the total balance of + all _active_ validators and _all_ validators. + """ + epoch = spec.get_current_epoch(state) + active_indices = spec.get_active_validator_indices(state, epoch) + active_balance = spec.get_total_balance(state, set(active_indices)) + total_balance = spec.get_total_balance(state, set(range(len(state.validators)))) + return active_balance // spec.EFFECTIVE_BALANCE_INCREMENT != total_balance // spec.EFFECTIVE_BALANCE_INCREMENT diff --git a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py index 68a6a3279..44f22270b 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py @@ -10,6 +10,7 @@ from eth2spec.test.context import ( ) import eth2spec.test.helpers.rewards as rewards_helpers from eth2spec.test.helpers.random import randomize_state, patch_state_to_non_leaking +from eth2spec.test.helpers.state import has_active_balance_differential from eth2spec.test.helpers.voluntary_exits import get_unslashed_exited_validators @@ -48,6 +49,7 @@ def test_full_random_4(spec, state): assert spec.is_in_inactivity_leak(state) target_validators = get_unslashed_exited_validators(spec, state) assert len(target_validators) != 0 + assert has_active_balance_differential(spec, state) yield from rewards_helpers.run_deltas(spec, state) @@ -85,4 +87,5 @@ def test_full_random_without_leak_0(spec, state): assert not spec.is_in_inactivity_leak(state) target_validators = get_unslashed_exited_validators(spec, state) assert len(target_validators) != 0 + assert has_active_balance_differential(spec, state) yield from rewards_helpers.run_deltas(spec, state) From ad076697f424a84c0e9b07e1d9316c3cd5906ee6 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 1 Sep 2021 15:47:05 -0700 Subject: [PATCH 092/122] add test case for active/exited difference for sync rewards processing --- .../test_process_sync_aggregate.py | 21 +++---- .../test_process_sync_aggregate_random.py | 62 ++++++++++++++++--- .../eth2spec/test/helpers/sync_committee.py | 26 ++------ 3 files changed, 67 insertions(+), 42 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index bd52ce727..0eaddbb88 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -12,7 +12,6 @@ from eth2spec.test.helpers.constants import ( from eth2spec.test.helpers.sync_committee import ( compute_aggregate_sync_committee_signature, compute_committee_indices, - get_committee_indices, run_sync_committee_processing, run_successful_sync_committee_test, ) @@ -28,7 +27,7 @@ from eth2spec.test.context import ( @spec_state_test @always_bls def test_invalid_signature_bad_domain(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + committee_indices = compute_committee_indices(spec, state) block = build_empty_block_for_next_slot(spec, state) block.body.sync_aggregate = spec.SyncAggregate( @@ -48,7 +47,7 @@ def test_invalid_signature_bad_domain(spec, state): @spec_state_test @always_bls def test_invalid_signature_missing_participant(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + committee_indices = compute_committee_indices(spec, state) rng = random.Random(2020) random_participant = rng.choice(committee_indices) @@ -111,7 +110,7 @@ def test_invalid_signature_infinite_signature_with_single_participant(spec, stat @spec_state_test @always_bls def test_invalid_signature_extra_participant(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + committee_indices = compute_committee_indices(spec, state) rng = random.Random(3030) random_participant = rng.choice(committee_indices) @@ -134,7 +133,7 @@ def test_invalid_signature_extra_participant(spec, state): @with_presets([MINIMAL], reason="to create nonduplicate committee") @spec_state_test def test_sync_committee_rewards_nonduplicate_committee(spec, state): - committee_indices = get_committee_indices(spec, state, duplicates=False) + committee_indices = compute_committee_indices(spec, state) committee_size = len(committee_indices) committee_bits = [True] * committee_size active_validator_count = len(spec.get_active_validator_indices(state, spec.get_current_epoch(state))) @@ -150,7 +149,7 @@ def test_sync_committee_rewards_nonduplicate_committee(spec, state): @with_presets([MAINNET], reason="to create duplicate committee") @spec_state_test def test_sync_committee_rewards_duplicate_committee_no_participation(spec, state): - committee_indices = get_committee_indices(spec, state, duplicates=True) + committee_indices = compute_committee_indices(spec, state) committee_size = len(committee_indices) committee_bits = [False] * committee_size active_validator_count = len(spec.get_active_validator_indices(state, spec.get_current_epoch(state))) @@ -166,7 +165,7 @@ def test_sync_committee_rewards_duplicate_committee_no_participation(spec, state @with_presets([MAINNET], reason="to create duplicate committee") @spec_state_test def test_sync_committee_rewards_duplicate_committee_half_participation(spec, state): - committee_indices = get_committee_indices(spec, state, duplicates=True) + committee_indices = compute_committee_indices(spec, state) committee_size = len(committee_indices) committee_bits = [True] * (committee_size // 2) + [False] * (committee_size // 2) assert len(committee_bits) == committee_size @@ -183,7 +182,7 @@ def test_sync_committee_rewards_duplicate_committee_half_participation(spec, sta @with_presets([MAINNET], reason="to create duplicate committee") @spec_state_test def test_sync_committee_rewards_duplicate_committee_full_participation(spec, state): - committee_indices = get_committee_indices(spec, state, duplicates=True) + committee_indices = compute_committee_indices(spec, state) committee_size = len(committee_indices) committee_bits = [True] * committee_size active_validator_count = len(spec.get_active_validator_indices(state, spec.get_current_epoch(state))) @@ -199,7 +198,7 @@ def test_sync_committee_rewards_duplicate_committee_full_participation(spec, sta @spec_state_test @always_bls def test_sync_committee_rewards_not_full_participants(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + committee_indices = compute_committee_indices(spec, state) rng = random.Random(1010) committee_bits = [rng.choice([True, False]) for _ in committee_indices] @@ -210,7 +209,7 @@ def test_sync_committee_rewards_not_full_participants(spec, state): @spec_state_test @always_bls def test_sync_committee_rewards_empty_participants(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + committee_indices = compute_committee_indices(spec, state) committee_bits = [False for _ in committee_indices] yield from run_successful_sync_committee_test(spec, state, committee_indices, committee_bits) @@ -220,7 +219,7 @@ def test_sync_committee_rewards_empty_participants(spec, state): @spec_state_test @always_bls def test_invalid_signature_past_block(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + committee_indices = compute_committee_indices(spec, state) for _ in range(2): # NOTE: need to transition twice to move beyond the degenerate case at genesis diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py index 75845e060..436e4d04b 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py @@ -2,10 +2,19 @@ import random from eth2spec.test.helpers.constants import ( MAINNET, MINIMAL, ) +from eth2spec.test.helpers.random import ( + randomize_state +) +from eth2spec.test.helpers.state import ( + has_active_balance_differential, +) from eth2spec.test.helpers.sync_committee import ( - get_committee_indices, + compute_committee_indices, run_successful_sync_committee_test, ) +from eth2spec.test.helpers.voluntary_exits import ( + get_unslashed_exited_validators, +) from eth2spec.test.context import ( with_altair_and_later, spec_state_test, @@ -18,8 +27,8 @@ from eth2spec.test.context import ( ) -def _test_harness_for_randomized_test_case(spec, state, duplicates=False, participation_fn=None): - committee_indices = get_committee_indices(spec, state, duplicates=duplicates) +def _test_harness_for_randomized_test_case(spec, state, expect_duplicates=False, participation_fn=None): + committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) if participation_fn: participating_indices = participation_fn(committee_indices) @@ -28,7 +37,7 @@ def _test_harness_for_randomized_test_case(spec, state, duplicates=False, partic committee_bits = [index in participating_indices for index in committee_indices] committee_size = len(committee_indices) - if duplicates: + if expect_duplicates: assert committee_size > len(set(committee_indices)) else: assert committee_size == len(set(committee_indices)) @@ -44,7 +53,7 @@ def test_random_only_one_participant_with_duplicates(spec, state): yield from _test_harness_for_randomized_test_case( spec, state, - duplicates=True, + expect_duplicates=True, participation_fn=lambda comm: [rng.choice(comm)], ) @@ -57,7 +66,7 @@ def test_random_low_participation_with_duplicates(spec, state): yield from _test_harness_for_randomized_test_case( spec, state, - duplicates=True, + expect_duplicates=True, participation_fn=lambda comm: rng.sample(comm, int(len(comm) * 0.25)), ) @@ -70,7 +79,7 @@ def test_random_high_participation_with_duplicates(spec, state): yield from _test_harness_for_randomized_test_case( spec, state, - duplicates=True, + expect_duplicates=True, participation_fn=lambda comm: rng.sample(comm, int(len(comm) * 0.75)), ) @@ -83,7 +92,7 @@ def test_random_all_but_one_participating_with_duplicates(spec, state): yield from _test_harness_for_randomized_test_case( spec, state, - duplicates=True, + expect_duplicates=True, participation_fn=lambda comm: rng.sample(comm, len(comm) - 1), ) @@ -98,7 +107,25 @@ def test_random_misc_balances_and_half_participation_with_duplicates(spec, state yield from _test_harness_for_randomized_test_case( spec, state, - duplicates=True, + expect_duplicates=True, + participation_fn=lambda comm: rng.sample(comm, len(comm) // 2), + ) + + +@with_altair_and_later +@with_presets([MAINNET], reason="to create duplicate committee") +@spec_state_test +@single_phase +def test_random_with_exits_with_duplicates(spec, state): + rng = random.Random(1402) + randomize_state(spec, state, rng=rng, exit_fraction=0.1, slash_fraction=0.0) + target_validators = get_unslashed_exited_validators(spec, state) + assert len(target_validators) != 0 + assert has_active_balance_differential(spec, state) + yield from _test_harness_for_randomized_test_case( + spec, + state, + expect_duplicates=True, participation_fn=lambda comm: rng.sample(comm, len(comm) // 2), ) @@ -163,3 +190,20 @@ def test_random_misc_balances_and_half_participation_without_duplicates(spec, st state, participation_fn=lambda comm: rng.sample(comm, len(comm) // 2), ) + + +@with_altair_and_later +@with_presets([MINIMAL], reason="to create nonduplicate committee") +@spec_state_test +@single_phase +def test_random_with_exits_without_duplicates(spec, state): + rng = random.Random(1502) + randomize_state(spec, state, rng=rng, exit_fraction=0.1, slash_fraction=0.0) + target_validators = get_unslashed_exited_validators(spec, state) + assert len(target_validators) != 0 + assert has_active_balance_differential(spec, state) + yield from _test_harness_for_randomized_test_case( + spec, + state, + participation_fn=lambda comm: rng.sample(comm, len(comm) // 2), + ) diff --git a/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py b/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py index e59f679e1..417802ece 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py +++ b/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py @@ -9,7 +9,6 @@ from eth2spec.test.helpers.block import ( ) from eth2spec.test.helpers.block_processing import run_block_processing_to from eth2spec.utils import bls -from eth2spec.utils.hash_function import hash def compute_sync_committee_signature(spec, state, slot, privkey, block_root=None, domain_type=None): @@ -75,10 +74,12 @@ def compute_sync_committee_proposer_reward(spec, state, committee_indices, commi return spec.Gwei(participant_reward * participant_number) -def compute_committee_indices(spec, state, committee): +def compute_committee_indices(spec, state, committee=None): """ Given a ``committee``, calculate and return the related indices """ + if committee is None: + committee = state.current_sync_committee all_pubkeys = [v.pubkey for v in state.validators] return [all_pubkeys.index(pubkey) for pubkey in committee.pubkeys] @@ -153,6 +154,7 @@ def _build_block_for_next_slot_with_sync_participation(spec, state, committee_in state, block.slot - 1, [index for index, bit in zip(committee_indices, committee_bits) if bit], + block_root=block.parent_root, ) ) return block @@ -161,23 +163,3 @@ def _build_block_for_next_slot_with_sync_participation(spec, state, committee_in def run_successful_sync_committee_test(spec, state, committee_indices, committee_bits): block = _build_block_for_next_slot_with_sync_participation(spec, state, committee_indices, committee_bits) yield from run_sync_committee_processing(spec, state, block) - - -def get_committee_indices(spec, state, duplicates=False): - """ - This utility function allows the caller to ensure there are or are not - duplicate validator indices in the returned committee based on - the boolean ``duplicates``. - """ - state = state.copy() - current_epoch = spec.get_current_epoch(state) - randao_index = (current_epoch + 1) % spec.EPOCHS_PER_HISTORICAL_VECTOR - while True: - committee = spec.get_next_sync_committee_indices(state) - if duplicates: - if len(committee) != len(set(committee)): - return committee - else: - if len(committee) == len(set(committee)): - return committee - state.randao_mixes[randao_index] = hash(state.randao_mixes[randao_index]) From bd38587a1e4491f66174a7bc7314e17f34c53e8e Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 1 Sep 2021 15:53:08 -0700 Subject: [PATCH 093/122] add active/exited balances test for `process_slashings` --- .../test_process_slashings.py | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_slashings.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_slashings.py index e336ebef7..1b977640d 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_slashings.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_slashings.py @@ -1,7 +1,11 @@ +from random import Random from eth2spec.test.context import spec_state_test, with_all_phases, is_post_altair from eth2spec.test.helpers.epoch_processing import ( run_epoch_processing_with, run_epoch_processing_to ) +from eth2spec.test.helpers.random import randomize_state +from eth2spec.test.helpers.state import has_active_balance_differential +from eth2spec.test.helpers.voluntary_exits import get_unslashed_exited_validators from eth2spec.test.helpers.state import next_epoch @@ -22,6 +26,9 @@ def slash_validators(spec, state, indices, out_epochs): spec.get_current_epoch(state) % spec.EPOCHS_PER_SLASHINGS_VECTOR ] = total_slashed_balance + # verify some slashings happened... + assert total_slashed_balance != 0 + def get_slashing_multiplier(spec): if is_post_altair(spec): @@ -30,9 +37,7 @@ def get_slashing_multiplier(spec): return spec.PROPORTIONAL_SLASHING_MULTIPLIER -@with_all_phases -@spec_state_test -def test_max_penalties(spec, state): +def _setup_process_slashings_test(spec, state, not_slashable_set=set()): # Slashed count to ensure that enough validators are slashed to induce maximum penalties slashed_count = min( (len(state.validators) // get_slashing_multiplier(spec)) + 1, @@ -41,14 +46,23 @@ def test_max_penalties(spec, state): ) out_epoch = spec.get_current_epoch(state) + (spec.EPOCHS_PER_SLASHINGS_VECTOR // 2) - slashed_indices = list(range(slashed_count)) - slash_validators(spec, state, slashed_indices, [out_epoch] * slashed_count) + eligible_indices = set(range(slashed_count)) + slashed_indices = eligible_indices.difference(not_slashable_set) + slash_validators(spec, state, sorted(slashed_indices), [out_epoch] * slashed_count) total_balance = spec.get_total_active_balance(state) total_penalties = sum(state.slashings) assert total_balance // get_slashing_multiplier(spec) <= total_penalties + return slashed_indices + + +@with_all_phases +@spec_state_test +def test_max_penalties(spec, state): + slashed_indices = _setup_process_slashings_test(spec, state) + yield from run_process_slashings(spec, state) for i in slashed_indices: @@ -171,3 +185,28 @@ def test_scaled_penalties(spec, state): * spec.EFFECTIVE_BALANCE_INCREMENT ) assert state.balances[i] == pre_slash_balances[i] - expected_penalty + + +@with_all_phases +@spec_state_test +def test_slashings_with_random_state(spec, state): + rng = Random(9998) + randomize_state(spec, state, rng) + + pre_balances = state.balances.copy() + + target_validators = get_unslashed_exited_validators(spec, state) + assert len(target_validators) != 0 + assert has_active_balance_differential(spec, state) + + slashed_indices = _setup_process_slashings_test(spec, state, not_slashable_set=target_validators) + + # ensure no accidental slashings of protected set... + current_target_validators = get_unslashed_exited_validators(spec, state) + assert len(current_target_validators) != 0 + assert current_target_validators == target_validators + + yield from run_process_slashings(spec, state) + + for i in slashed_indices: + assert state.balances[i] < pre_balances[i] From d834b6e800eacea1961682e5abad701c5fb17c34 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 2 Sep 2021 12:37:11 -0700 Subject: [PATCH 094/122] add active/exited balances test for justification --- ..._process_justification_and_finalization.py | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py index 9db6076f8..1dfc07188 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py @@ -1,8 +1,10 @@ +from random import Random from eth2spec.test.context import is_post_altair, spec_state_test, with_all_phases from eth2spec.test.helpers.epoch_processing import ( run_epoch_processing_with, ) -from eth2spec.test.helpers.state import transition_to +from eth2spec.test.helpers.state import transition_to, next_epoch_via_block, next_slot +from eth2spec.test.helpers.voluntary_exits import get_unslashed_exited_validators def run_process_just_and_fin(spec, state): @@ -300,3 +302,75 @@ def test_12_ok_support_messed_target(spec, state): @spec_state_test def test_12_poor_support(spec, state): yield from finalize_on_12(spec, state, 3, False, False) + + +@with_all_phases +@spec_state_test +def test_balance_threshold_with_exited_validators(spec, state): + """ + This test exercises a very specific failure mode where + exited validators are incorrectly included in the total active balance + when weighing justification. + """ + rng = Random(133333) + # move past genesis conditions + for _ in range(3): + next_epoch_via_block(spec, state) + + # mock attestation helper requires last slot of epoch + for _ in range(spec.SLOTS_PER_EPOCH - 1): + next_slot(spec, state) + + # Step 1: Exit ~1/2 vals in current epoch + epoch = spec.get_current_epoch(state) + for index in spec.get_active_validator_indices(state, epoch): + if rng.choice([True, False]): + continue + + validator = state.validators[index] + validator.exit_epoch = epoch + validator.withdrawable_epoch = epoch + 1 + + exited_validators = get_unslashed_exited_validators(spec, state) + assert len(exited_validators) != 0 + + source = state.current_justified_checkpoint + target = spec.Checkpoint( + epoch=epoch, + root=spec.get_block_root(state, epoch) + ) + add_mock_attestations( + spec, + state, + epoch, + source, + target, + sufficient_support=False, + ) + + if not is_post_altair(spec): + current_attestations = spec.get_matching_target_attestations(state, epoch) + total_active_balance = spec.get_total_active_balance(state) + current_target_balance = spec.get_attesting_balance(state, current_attestations) + # Check we will not justify the current checkpoint + does_justify = current_target_balance * 3 >= total_active_balance * 2 + assert not does_justify + # Ensure we would have justified the current checkpoint w/ the exited validators + current_exited_balance = spec.get_total_balance(state, exited_validators) + does_justify = (current_target_balance + current_exited_balance) * 3 >= total_active_balance * 2 + assert does_justify + else: + current_indices = spec.get_unslashed_participating_indices(state, spec.TIMELY_TARGET_FLAG_INDEX, epoch) + total_active_balance = spec.get_total_active_balance(state) + current_target_balance = spec.get_total_balance(state, current_indices) + # Check we will not justify the current checkpoint + does_justify = current_target_balance * 3 >= total_active_balance * 2 + assert not does_justify + # Ensure we would have justified the current checkpoint w/ the exited validators + current_exited_balance = spec.get_total_balance(state, exited_validators) + does_justify = (current_target_balance + current_exited_balance) * 3 >= total_active_balance * 2 + assert does_justify + + yield from run_process_just_and_fin(spec, state) + + assert state.current_justified_checkpoint.epoch != epoch From 30596fb8a1c47b8d14c8619ae3e1c4ccb068b313 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 2 Sep 2021 15:35:15 -0600 Subject: [PATCH 095/122] Update tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py --- .../sync_aggregate/test_process_sync_aggregate_random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py index 436e4d04b..d38c3fadf 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py @@ -28,7 +28,7 @@ from eth2spec.test.context import ( def _test_harness_for_randomized_test_case(spec, state, expect_duplicates=False, participation_fn=None): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + committee_indices = compute_committee_indices(spec, state) if participation_fn: participating_indices = participation_fn(committee_indices) From 4168943ecf0f3465fdea74f3d9bdc2d21f567153 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 2 Sep 2021 15:38:52 -0600 Subject: [PATCH 096/122] Update tests/core/pyspec/eth2spec/test/helpers/random.py --- tests/core/pyspec/eth2spec/test/helpers/random.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/random.py b/tests/core/pyspec/eth2spec/test/helpers/random.py index 0bb2a6672..b24d3c8c7 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/random.py +++ b/tests/core/pyspec/eth2spec/test/helpers/random.py @@ -141,7 +141,8 @@ def patch_state_to_non_leaking(spec, state): performed by other functionality in this module so that if the ``state`` was leaking, then the ``state`` is not leaking after. """ - state.justification_bits = (True, True, True, True) + state.justification_bits[0] = True + state.justification_bits[1] = True previous_epoch = spec.get_previous_epoch(state) previous_root = spec.get_block_root(state, previous_epoch) previous_previous_epoch = max(spec.GENESIS_EPOCH, spec.Epoch(previous_epoch - 1)) From 25c290474f3cd0ab5c6b59366ff320c8a4a0c02e Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 2 Sep 2021 15:50:26 -0700 Subject: [PATCH 097/122] fix test filtering on eth1 voting spec test --- .../pyspec/eth2spec/test/phase0/sanity/test_blocks.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index a79ed94d2..81b0cca7b 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -974,12 +974,9 @@ def test_historical_batch(spec, state): @with_all_phases +@with_presets([MINIMAL], reason="suffices to test eth1 data voting without long voting period") @spec_state_test def test_eth1_data_votes_consensus(spec, state): - if spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 2: - return dump_skipping_message("Skip test if config with longer `EPOCHS_PER_ETH1_VOTING_PERIOD` for saving time." - " Minimal config suffice to cover the target-of-test.") - voting_period_slots = spec.EPOCHS_PER_ETH1_VOTING_PERIOD * spec.SLOTS_PER_EPOCH offset_block = build_empty_block(spec, state, slot=voting_period_slots - 1) @@ -1018,12 +1015,9 @@ def test_eth1_data_votes_consensus(spec, state): @with_all_phases +@with_presets([MINIMAL], reason="suffices to test eth1 data voting without long voting period") @spec_state_test def test_eth1_data_votes_no_consensus(spec, state): - if spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 2: - return dump_skipping_message("Skip test if config with longer `EPOCHS_PER_ETH1_VOTING_PERIOD` for saving time." - " Minimal config suffice to cover the target-of-test.") - voting_period_slots = spec.EPOCHS_PER_ETH1_VOTING_PERIOD * spec.SLOTS_PER_EPOCH pre_eth1_hash = state.eth1_data.block_hash From fb4a4f669460fba812715501dfdd0be40fac4f81 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 7 Sep 2021 13:09:23 -0600 Subject: [PATCH 098/122] Update tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py Co-authored-by: Danny Ryan --- .../sync_aggregate/test_process_sync_aggregate_random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py index d38c3fadf..903df4081 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py @@ -3,7 +3,7 @@ from eth2spec.test.helpers.constants import ( MAINNET, MINIMAL, ) from eth2spec.test.helpers.random import ( - randomize_state + randomize_state, ) from eth2spec.test.helpers.state import ( has_active_balance_differential, From 064b489d18504e796adc4661cd4d641456dfd0a8 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 7 Sep 2021 12:23:57 -0700 Subject: [PATCH 099/122] Use spec function for total active balance --- tests/core/pyspec/eth2spec/test/helpers/state.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index 327bebaf8..6f1923e54 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -162,8 +162,6 @@ def has_active_balance_differential(spec, state): Ensure there is a difference between the total balance of all _active_ validators and _all_ validators. """ - epoch = spec.get_current_epoch(state) - active_indices = spec.get_active_validator_indices(state, epoch) - active_balance = spec.get_total_balance(state, set(active_indices)) + active_balance = spec.get_total_active_balance(state) total_balance = spec.get_total_balance(state, set(range(len(state.validators)))) return active_balance // spec.EFFECTIVE_BALANCE_INCREMENT != total_balance // spec.EFFECTIVE_BALANCE_INCREMENT From 14f71ffb4bb49f436dff5262cebed2720e0bdef7 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 7 Sep 2021 12:25:09 -0700 Subject: [PATCH 100/122] Use realistic `withdrawable_epoch` in spec test --- .../test_process_justification_and_finalization.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py index 1dfc07188..1d3197ba6 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_justification_and_finalization.py @@ -330,6 +330,7 @@ def test_balance_threshold_with_exited_validators(spec, state): validator = state.validators[index] validator.exit_epoch = epoch validator.withdrawable_epoch = epoch + 1 + validator.withdrawable_epoch = validator.exit_epoch + spec.config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY exited_validators = get_unslashed_exited_validators(spec, state) assert len(exited_validators) != 0 From 43e79a7ee03d89568371c25e3c7e5d2b9cc049c3 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 7 Sep 2021 20:34:28 -0600 Subject: [PATCH 101/122] add process_registry_updates tests for scaled churn limit --- configs/minimal.yaml | 4 +- tests/core/pyspec/eth2spec/test/context.py | 11 ++ .../test_process_registry_updates.py | 175 ++++++++++++++---- 3 files changed, 147 insertions(+), 43 deletions(-) diff --git a/configs/minimal.yaml b/configs/minimal.yaml index 37a428b50..b067f222f 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -58,8 +58,8 @@ INACTIVITY_SCORE_RECOVERY_RATE: 16 EJECTION_BALANCE: 16000000000 # 2**2 (= 4) MIN_PER_EPOCH_CHURN_LIMIT: 4 -# 2**16 (= 65,536) -CHURN_LIMIT_QUOTIENT: 65536 +# [customized] scale queue churn at much lower validator counts for testing +CHURN_LIMIT_QUOTIENT: 32 # Deposit contract diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index 346cdc8f1..ef92efade 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -126,6 +126,17 @@ def default_balances(spec): return [spec.MAX_EFFECTIVE_BALANCE] * num_validators +def scaled_churn_balances(spec): + """ + Helper method to create enough validators to scale the churn limit. + (This is *firmly* over the churn limit -- thus the +2 instead of just +1) + See the second argument of ``max`` in ``get_validator_churn_limit``. + Usage: `@with_custom_state(balances_fn=scaled_churn_balances, ...)` + """ + num_validators = spec.config.CHURN_LIMIT_QUOTIENT * (2 + spec.config.MIN_PER_EPOCH_CHURN_LIMIT) + return [spec.MAX_EFFECTIVE_BALANCE] * num_validators + + with_state = with_custom_state(default_balances, default_activation_threshold) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index 6e7784aa9..e3f1f2093 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -1,6 +1,11 @@ from eth2spec.test.helpers.deposits import mock_deposit from eth2spec.test.helpers.state import next_epoch, next_slots -from eth2spec.test.context import spec_state_test, with_all_phases +from eth2spec.test.context import ( + spec_test, spec_state_test, + with_all_phases, single_phase, + with_custom_state, + scaled_churn_balances, +) from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with @@ -112,9 +117,7 @@ def test_activation_queue_sorting(spec, state): assert state.validators[churn_limit - 1].activation_epoch != spec.FAR_FUTURE_EPOCH -@with_all_phases -@spec_state_test -def test_activation_queue_efficiency(spec, state): +def run_test_activation_queue_efficiency(spec, state): churn_limit = spec.get_validator_churn_limit(state) mock_activations = churn_limit * 2 @@ -128,23 +131,43 @@ def test_activation_queue_efficiency(spec, state): state.finalized_checkpoint.epoch = epoch + 1 + # Churn limit could have changed given the active vals removed via `mock_deposit` + churn_limit_0 = spec.get_validator_churn_limit(state) + # Run first registry update. Do not yield test vectors for _ in run_process_registry_updates(spec, state): pass # Half should churn in first run of registry update for i in range(mock_activations): - if i < mock_activations // 2: + if i < churn_limit_0: assert state.validators[i].activation_epoch < spec.FAR_FUTURE_EPOCH else: assert state.validators[i].activation_epoch == spec.FAR_FUTURE_EPOCH # Second half should churn in second run of registry update + churn_limit_1 = spec.get_validator_churn_limit(state) yield from run_process_registry_updates(spec, state) - for i in range(mock_activations): + for i in range(churn_limit_0 + churn_limit_1): assert state.validators[i].activation_epoch < spec.FAR_FUTURE_EPOCH +@with_all_phases +@spec_state_test +def test_activation_queue_efficiency_min(spec, state): + assert spec.get_validator_churn_limit(state) == spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_activation_queue_efficiency(spec, state) + + +@with_all_phases +@spec_test +@with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@single_phase +def test_activation_queue_efficiency_scaled(spec, state): + assert spec.get_validator_churn_limit(state) > spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_activation_queue_efficiency(spec, state) + + @with_all_phases @spec_state_test def test_ejection(spec, state): @@ -165,9 +188,7 @@ def test_ejection(spec, state): ) -@with_all_phases -@spec_state_test -def test_ejection_past_churn_limit(spec, state): +def run_test_ejection_past_churn_limit(spec, state): churn_limit = spec.get_validator_churn_limit(state) # try to eject more than per-epoch churn limit @@ -184,58 +205,130 @@ def test_ejection_past_churn_limit(spec, state): # first third ejected in normal speed if i < mock_ejections // 3: assert state.validators[i].exit_epoch == expected_ejection_epoch - # second thirdgets delayed by 1 epoch + # second third gets delayed by 1 epoch elif mock_ejections // 3 <= i < mock_ejections * 2 // 3: assert state.validators[i].exit_epoch == expected_ejection_epoch + 1 - # second thirdgets delayed by 2 epochs + # final third gets delayed by 2 epochs else: assert state.validators[i].exit_epoch == expected_ejection_epoch + 2 @with_all_phases @spec_state_test -def test_activation_queue_activation_and_ejection(spec, state): +def test_ejection_past_churn_limit_min(spec, state): + assert spec.get_validator_churn_limit(state) == spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_ejection_past_churn_limit(spec, state) + + +@with_all_phases +@spec_test +@with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@single_phase +def test_ejection_past_churn_limit_scaled(spec, state): + assert spec.get_validator_churn_limit(state) > spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_ejection_past_churn_limit(spec, state) + + +def run_test_activation_queue_activation_and_ejection(spec, state, num_per_status): # move past first two irregular epochs wrt finality next_epoch(spec, state) next_epoch(spec, state) # ready for entrance into activation queue - activation_queue_index = 0 - mock_deposit(spec, state, activation_queue_index) + activation_queue_start_index = 0 + activation_queue_indices = list(range(activation_queue_start_index, activation_queue_start_index + num_per_status)) + for validator_index in activation_queue_indices: + mock_deposit(spec, state, validator_index) # ready for activation - activation_index = 1 - mock_deposit(spec, state, activation_index) state.finalized_checkpoint.epoch = spec.get_current_epoch(state) - 1 - state.validators[activation_index].activation_eligibility_epoch = state.finalized_checkpoint.epoch + activation_start_index = num_per_status + activation_indices = list(range(activation_start_index, activation_start_index + num_per_status)) + for validator_index in activation_indices: + mock_deposit(spec, state, validator_index) + state.validators[validator_index].activation_eligibility_epoch = state.finalized_checkpoint.epoch # ready for ejection - ejection_index = 2 - state.validators[ejection_index].effective_balance = spec.config.EJECTION_BALANCE + ejection_start_index = num_per_status * 2 + ejection_indices = list(range(ejection_start_index, ejection_start_index + num_per_status)) + for validator_index in ejection_indices: + state.validators[validator_index].effective_balance = spec.config.EJECTION_BALANCE + churn_limit = spec.get_validator_churn_limit(state) yield from run_process_registry_updates(spec, state) - # validator moved into activation queue - validator = state.validators[activation_queue_index] - assert validator.activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH - assert validator.activation_epoch == spec.FAR_FUTURE_EPOCH - assert not spec.is_active_validator(validator, spec.get_current_epoch(state)) + # all eligible validators moved into activation queue + for validator_index in activation_queue_indices: + validator = state.validators[validator_index] + assert validator.activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH + assert validator.activation_epoch == spec.FAR_FUTURE_EPOCH + assert not spec.is_active_validator(validator, spec.get_current_epoch(state)) - # validator activated for future epoch - validator = state.validators[activation_index] - assert validator.activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH - assert validator.activation_epoch != spec.FAR_FUTURE_EPOCH - assert not spec.is_active_validator(validator, spec.get_current_epoch(state)) - assert spec.is_active_validator( - validator, - spec.compute_activation_exit_epoch(spec.get_current_epoch(state)) - ) + # up to churn limit validators get activated for future epoch from the queue + for validator_index in activation_indices[:churn_limit]: + validator = state.validators[validator_index] + assert validator.activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH + assert validator.activation_epoch != spec.FAR_FUTURE_EPOCH + assert not spec.is_active_validator(validator, spec.get_current_epoch(state)) + assert spec.is_active_validator( + validator, + spec.compute_activation_exit_epoch(spec.get_current_epoch(state)) + ) - # validator ejected for future epoch - validator = state.validators[ejection_index] - assert validator.exit_epoch != spec.FAR_FUTURE_EPOCH - assert spec.is_active_validator(validator, spec.get_current_epoch(state)) - assert not spec.is_active_validator( - validator, - spec.compute_activation_exit_epoch(spec.get_current_epoch(state)) - ) + # any remaining validators do not exit the activation queue + for validator_index in activation_indices[churn_limit:]: + validator = state.validators[validator_index] + assert validator.activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH + assert validator.activation_epoch == spec.FAR_FUTURE_EPOCH + + # all ejection balance validators ejected for a future epoch + for i, validator_index in enumerate(ejection_indices): + validator = state.validators[validator_index] + assert validator.exit_epoch != spec.FAR_FUTURE_EPOCH + assert spec.is_active_validator(validator, spec.get_current_epoch(state)) + queue_offset = i // churn_limit + assert not spec.is_active_validator( + validator, + spec.compute_activation_exit_epoch(spec.get_current_epoch(state)) + queue_offset + ) + + +@with_all_phases +@spec_state_test +def test_activation_queue_activation_and_ejection__1(spec, state): + yield from run_test_activation_queue_activation_and_ejection(spec, state, 1) + + +@with_all_phases +@spec_state_test +def test_activation_queue_activation_and_ejection__churn_limit(spec, state): + num_validators_per_status= spec.get_validator_churn_limit(state) + yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status) + + +@with_all_phases +@spec_state_test +def test_activation_queue_activation_and_ejection__exceed_churn_limit(spec, state): + num_validators_per_status = spec.get_validator_churn_limit(state) + 1 + yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status) + + +@with_all_phases +@spec_test +@with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@single_phase +def test_activation_queue_activation_and_ejection__scaled_churn_limit(spec, state): + churn_limit = spec.get_validator_churn_limit(state) + assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_activation_queue_activation_and_ejection(spec, state, churn_limit) + + +@with_all_phases +@spec_test +@with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@single_phase +def test_activation_queue_activation_and_ejection__exceed_scaled_churn_limit(spec, state): + churn_limit = spec.get_validator_churn_limit(state) + assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT + num_validators_per_status = churn_limit * 2 + yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status) From 6784025d645f71fd16e54cb77983e608ac918776 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 7 Sep 2021 20:49:54 -0600 Subject: [PATCH 102/122] add scaled churn limit tests for voluntary exits --- .../test_process_voluntary_exit.py | 36 ++++++++++++++----- .../test_process_registry_updates.py | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py index f713d1792..1b6b40580 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py @@ -1,4 +1,9 @@ -from eth2spec.test.context import spec_state_test, expect_assertion_error, always_bls, with_all_phases +from eth2spec.test.context import ( + spec_state_test, expect_assertion_error, + always_bls, with_all_phases, + spec_test, single_phase, + with_custom_state, scaled_churn_balances, +) from eth2spec.test.helpers.keys import pubkey_to_privkey from eth2spec.test.helpers.voluntary_exits import sign_voluntary_exit @@ -68,9 +73,7 @@ def test_invalid_signature(spec, state): yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, False) -@with_all_phases -@spec_state_test -def test_success_exit_queue(spec, state): +def run_test_success_exit_queue(spec, state): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH @@ -106,10 +109,27 @@ def test_success_exit_queue(spec, state): # when processing an additional exit, it results in an exit in a later epoch yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit) - assert ( - state.validators[validator_index].exit_epoch == - state.validators[initial_indices[0]].exit_epoch + 1 - ) + for index in initial_indices: + assert ( + state.validators[validator_index].exit_epoch == + state.validators[index].exit_epoch + 1 + ) + + +@with_all_phases +@spec_state_test +def test_success_exit_queue__min_churn(spec, state): + yield from run_test_success_exit_queue(spec, state) + + +@with_all_phases +@spec_test +@with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@single_phase +def test_success_exit_queue__scaled_churn(spec, state): + churn_limit = spec.get_validator_churn_limit(state) + assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_success_exit_queue(spec, state) @with_all_phases diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index e3f1f2093..6b1d7bce9 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -302,7 +302,7 @@ def test_activation_queue_activation_and_ejection__1(spec, state): @with_all_phases @spec_state_test def test_activation_queue_activation_and_ejection__churn_limit(spec, state): - num_validators_per_status= spec.get_validator_churn_limit(state) + num_validators_per_status = spec.get_validator_churn_limit(state) yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status) From 5bc59d8aabcee8930900466dee9fa9af2257622f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 8 Sep 2021 21:22:48 +0800 Subject: [PATCH 103/122] Fix the comments --- .../pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py index 8227c4cfb..c00a91b28 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py @@ -218,7 +218,7 @@ def test_on_block_finalized_skip_slots(spec, state): state, store, _ = yield from apply_next_epoch_with_attestations( spec, state, store, True, True, test_steps=test_steps) - # Now we get finalized epoch 1, where compute_start_slot_at_epoch(1) is a skipped slot + # Now we get finalized epoch 2, where `compute_start_slot_at_epoch(2)` is a skipped slot assert state.finalized_checkpoint.epoch == store.finalized_checkpoint.epoch == 2 assert store.finalized_checkpoint.root == spec.get_block_root(state, 1) == spec.get_block_root(state, 2) assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 @@ -262,7 +262,7 @@ def test_on_block_finalized_skip_slots_not_in_skip_chain(spec, state): state, store, _ = yield from apply_next_epoch_with_attestations( spec, state, store, True, True, test_steps=test_steps) - # Now we get finalized epoch 1, where compute_start_slot_at_epoch(1) is a skipped slot + # Now we get finalized epoch 2, where `compute_start_slot_at_epoch(2)` is a skipped slot assert state.finalized_checkpoint.epoch == store.finalized_checkpoint.epoch == 2 assert store.finalized_checkpoint.root == spec.get_block_root(state, 1) == spec.get_block_root(state, 2) assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 From 8220f7dd44fa983d3d40d8a72d758c8eb3bbc506 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 7 Sep 2021 20:55:47 -0600 Subject: [PATCH 104/122] ensure new dynamic queue tests don't run for mainnet cofig --- .../block_processing/test_process_voluntary_exit.py | 5 ++++- .../epoch_processing/test_process_registry_updates.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py index 1b6b40580..9e209f23e 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py @@ -1,6 +1,7 @@ +from eth2spec.test.helpers.constants import MINIMAL from eth2spec.test.context import ( spec_state_test, expect_assertion_error, - always_bls, with_all_phases, + always_bls, with_all_phases, with_presets, spec_test, single_phase, with_custom_state, scaled_churn_balances, ) @@ -123,6 +124,8 @@ def test_success_exit_queue__min_churn(spec, state): @with_all_phases +@with_presets([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") @spec_test @with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) @single_phase diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index 6b1d7bce9..5bcf3a82b 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -1,9 +1,10 @@ from eth2spec.test.helpers.deposits import mock_deposit from eth2spec.test.helpers.state import next_epoch, next_slots +from eth2spec.test.helpers.constants import MINIMAL from eth2spec.test.context import ( spec_test, spec_state_test, with_all_phases, single_phase, - with_custom_state, + with_custom_state, with_presets, scaled_churn_balances, ) from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with @@ -160,6 +161,8 @@ def test_activation_queue_efficiency_min(spec, state): @with_all_phases +@with_presets([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") @spec_test @with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) @single_phase @@ -221,6 +224,8 @@ def test_ejection_past_churn_limit_min(spec, state): @with_all_phases +@with_presets([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") @spec_test @with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) @single_phase @@ -314,6 +319,8 @@ def test_activation_queue_activation_and_ejection__exceed_churn_limit(spec, stat @with_all_phases +@with_presets([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") @spec_test @with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) @single_phase @@ -324,6 +331,8 @@ def test_activation_queue_activation_and_ejection__scaled_churn_limit(spec, stat @with_all_phases +@with_presets([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") @spec_test @with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) @single_phase From 49d225bb785bba6eb233e306119b7caf6ca3057c Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Wed, 8 Sep 2021 12:34:33 -0700 Subject: [PATCH 105/122] Add new --terminal-total-difficulty-override client_setting --- README.md | 3 ++- specs/merge/client_settings.md | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 specs/merge/client_settings.md diff --git a/README.md b/README.md index bc4ba100b..b5a898d37 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ The merge is still actively in development. The exact specification has not been * [Merge fork](specs/merge/fork.md) * [Fork Choice changes](specs/merge/fork-choice.md) * [Validator additions](specs/merge/validator.md) + * [Client settings](specs/merge/client_settings.md) ### Sharding @@ -53,7 +54,7 @@ Sharding follows the merge, and is divided into three parts: * Sharding base functionality - In early engineering phase * [Beacon Chain changes](specs/sharding/beacon-chain.md) * [P2P Network changes](specs/sharding/p2p-interface.md) -* Custody Game - Ready, dependent on sharding +* Custody Game - Ready, dependent on sharding * [Beacon Chain changes](specs/custody_game/beacon-chain.md) * [Validator custody work](specs/custody_game/validator.md) * Data Availability Sampling - In active R&D diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md new file mode 100644 index 000000000..172617a74 --- /dev/null +++ b/specs/merge/client_settings.md @@ -0,0 +1,14 @@ +# The Merge -- Client Settings + +**Notice**: This document is a work-in-progress for researchers and implementers. + +This document specifies configurable settings that merge clients are expected to ship with. + +### Override terminal total difficulty + +To coordinate changes to [`terminal_total_difficulty`](specs/merge/fork-choice.md#transitionstore), clients +should have a setting `--terminal-total-difficulty-override`. + +If `TransitionStore` has already been initialized, this just changes the value of +`TransitionStore.terminal_total_difficulty`, otherwise it initializes `TransitionStore` with the specified +`terminal_total_difficulty`. From 01fe3cdb083dbf561d08ad2f11db777fe2724811 Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Wed, 8 Sep 2021 12:57:49 -0700 Subject: [PATCH 106/122] Add note about default behavior --- specs/merge/client_settings.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index 172617a74..f1ff8b639 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -12,3 +12,6 @@ should have a setting `--terminal-total-difficulty-override`. If `TransitionStore` has already been initialized, this just changes the value of `TransitionStore.terminal_total_difficulty`, otherwise it initializes `TransitionStore` with the specified `terminal_total_difficulty`. + +By default, this setting is expected to not be used and `terminal_total_difficulty` will be set as defined +[here](specs/merge/fork.md#initializing-transition-store). From 0f7d8e5552c0ed7c4e992e3183a7e19d365c63c4 Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Wed, 8 Sep 2021 13:03:05 -0700 Subject: [PATCH 107/122] Add notes in merge/fork.md --- specs/merge/fork.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/specs/merge/fork.md b/specs/merge/fork.md index f16be0574..0785f577c 100644 --- a/specs/merge/fork.md +++ b/specs/merge/fork.md @@ -97,13 +97,13 @@ def upgrade_to_merge(pre: altair.BeaconState) -> BeaconState: # Execution-layer latest_execution_payload_header=ExecutionPayloadHeader(), ) - + return post ``` ### Initializing transition store -If `state.slot % SLOTS_PER_EPOCH == 0` and `compute_epoch_at_slot(state.slot) == MERGE_FORK_EPOCH`, a transition store is initialized to be further utilized by the transition process of the Merge. +If `state.slot % SLOTS_PER_EPOCH == 0`, `compute_epoch_at_slot(state.slot) == MERGE_FORK_EPOCH`, and the transition store has not already been initialized, a transition store is initialized to be further utilized by the transition process of the Merge. Transition store initialization occurs after the state has been modified by corresponding `upgrade_to_merge` function. @@ -127,3 +127,6 @@ def initialize_transition_store(state: BeaconState) -> TransitionStore: pow_block = get_pow_block(state.eth1_data.block_hash) return get_transition_store(pow_block) ``` + +Note that transition store can also be initialized at client startup by [overriding terminal total +difficulty](specs/merge/client_settings.md#override-terminal-total-difficulty). From a542a07578d5cc3b5c1d41e11a14a071cc0fe7da Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Wed, 8 Sep 2021 13:06:22 -0700 Subject: [PATCH 108/122] Fix links --- specs/merge/client_settings.md | 4 ++-- specs/merge/fork.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index f1ff8b639..520ca1fdf 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -6,7 +6,7 @@ This document specifies configurable settings that merge clients are expected to ### Override terminal total difficulty -To coordinate changes to [`terminal_total_difficulty`](specs/merge/fork-choice.md#transitionstore), clients +To coordinate changes to [`terminal_total_difficulty`](fork-choice.md#transitionstore), clients should have a setting `--terminal-total-difficulty-override`. If `TransitionStore` has already been initialized, this just changes the value of @@ -14,4 +14,4 @@ If `TransitionStore` has already been initialized, this just changes the value o `terminal_total_difficulty`. By default, this setting is expected to not be used and `terminal_total_difficulty` will be set as defined -[here](specs/merge/fork.md#initializing-transition-store). +[here](fork.md#initializing-transition-store). diff --git a/specs/merge/fork.md b/specs/merge/fork.md index 0785f577c..64216a401 100644 --- a/specs/merge/fork.md +++ b/specs/merge/fork.md @@ -129,4 +129,4 @@ def initialize_transition_store(state: BeaconState) -> TransitionStore: ``` Note that transition store can also be initialized at client startup by [overriding terminal total -difficulty](specs/merge/client_settings.md#override-terminal-total-difficulty). +difficulty](client_settings.md#override-terminal-total-difficulty). From 989cd380417930ffe33033a9476c264dbe6ba0a3 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 8 Sep 2021 19:55:41 -0700 Subject: [PATCH 109/122] add rewards spec test with exit in current epoch --- .../test/phase0/rewards/test_random.py | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py index 44f22270b..e6112557a 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py @@ -9,8 +9,12 @@ from eth2spec.test.context import ( low_balances, misc_balances, ) import eth2spec.test.helpers.rewards as rewards_helpers -from eth2spec.test.helpers.random import randomize_state, patch_state_to_non_leaking -from eth2spec.test.helpers.state import has_active_balance_differential +from eth2spec.test.helpers.random import ( + randomize_state, + patch_state_to_non_leaking, + randomize_attestation_participation, +) +from eth2spec.test.helpers.state import has_active_balance_differential, next_epoch from eth2spec.test.helpers.voluntary_exits import get_unslashed_exited_validators @@ -89,3 +93,38 @@ def test_full_random_without_leak_0(spec, state): assert len(target_validators) != 0 assert has_active_balance_differential(spec, state) yield from rewards_helpers.run_deltas(spec, state) + + +@with_all_phases +@spec_state_test +def test_full_random_without_leak_and_current_exit_0(spec, state): + """ + This test specifically ensures a validator exits in the current epoch + to ensure rewards are handled properly in this case. + """ + rng = Random(1011) + randomize_state(spec, state, rng) + assert spec.is_in_inactivity_leak(state) + patch_state_to_non_leaking(spec, state) + assert not spec.is_in_inactivity_leak(state) + target_validators = get_unslashed_exited_validators(spec, state) + assert len(target_validators) != 0 + + # move forward some epochs to process attestations added + # by ``randomize_state`` before we exit validators in + # what will be the current epoch + for _ in range(2): + next_epoch(spec, state) + + current_epoch = spec.get_current_epoch(state) + for index in target_validators: + # patch exited validators to exit in the current epoch + validator = state.validators[index] + validator.exit_epoch = current_epoch + validator.withdrawable_epoch = current_epoch + spec.config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY + + # re-randomize attestation participation for the current epoch + randomize_attestation_participation(spec, state, rng) + + assert has_active_balance_differential(spec, state) + yield from rewards_helpers.run_deltas(spec, state) From 10f4ea4b5122903c28ef9dbb6ec66bba93b9791a Mon Sep 17 00:00:00 2001 From: Lakshman Sankar Date: Thu, 9 Sep 2021 08:36:25 -0700 Subject: [PATCH 110/122] Wording change Co-authored-by: Danny Ryan --- specs/merge/client_settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index 520ca1fdf..8f4ca6367 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -9,7 +9,7 @@ This document specifies configurable settings that merge clients are expected to To coordinate changes to [`terminal_total_difficulty`](fork-choice.md#transitionstore), clients should have a setting `--terminal-total-difficulty-override`. -If `TransitionStore` has already been initialized, this just changes the value of +If `TransitionStore` has already [been initialized](./fork.md#initializing-transition-store), this alters the previously initialized value of `TransitionStore.terminal_total_difficulty`, otherwise it initializes `TransitionStore` with the specified `terminal_total_difficulty`. From de1487564ad02c5201427179d42507971808cccf Mon Sep 17 00:00:00 2001 From: Lakshman Sankar Date: Thu, 9 Sep 2021 08:36:42 -0700 Subject: [PATCH 111/122] Wording change Co-authored-by: Mikhail Kalinin --- specs/merge/fork.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/merge/fork.md b/specs/merge/fork.md index 64216a401..f2547758d 100644 --- a/specs/merge/fork.md +++ b/specs/merge/fork.md @@ -128,5 +128,5 @@ def initialize_transition_store(state: BeaconState) -> TransitionStore: return get_transition_store(pow_block) ``` -Note that transition store can also be initialized at client startup by [overriding terminal total +*Note*: Transition store can also be initialized at client startup by [overriding terminal total difficulty](client_settings.md#override-terminal-total-difficulty). From 385ee12ef0a9d2db1fb57af9549ac9c4a5b42d4c Mon Sep 17 00:00:00 2001 From: Lakshman Sankar Date: Thu, 9 Sep 2021 08:36:54 -0700 Subject: [PATCH 112/122] 'should' -> 'must' Co-authored-by: Danny Ryan --- specs/merge/client_settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index 8f4ca6367..e2a69c538 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -7,7 +7,7 @@ This document specifies configurable settings that merge clients are expected to ### Override terminal total difficulty To coordinate changes to [`terminal_total_difficulty`](fork-choice.md#transitionstore), clients -should have a setting `--terminal-total-difficulty-override`. +must provide `--terminal-total-difficulty-override` as a configurable setting. If `TransitionStore` has already [been initialized](./fork.md#initializing-transition-store), this alters the previously initialized value of `TransitionStore.terminal_total_difficulty`, otherwise it initializes `TransitionStore` with the specified From 771933d1a70ef62c7cd645d3050127c2f5d1fb52 Mon Sep 17 00:00:00 2001 From: Lakshman Sankar Date: Thu, 9 Sep 2021 08:37:27 -0700 Subject: [PATCH 113/122] Stronger language around usage of the setting Co-authored-by: Danny Ryan --- specs/merge/client_settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index e2a69c538..05a13094a 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -13,5 +13,5 @@ If `TransitionStore` has already [been initialized](./fork.md#initializing-trans `TransitionStore.terminal_total_difficulty`, otherwise it initializes `TransitionStore` with the specified `terminal_total_difficulty`. -By default, this setting is expected to not be used and `terminal_total_difficulty` will be set as defined +Except under exceptional scenarios, this setting is expected to not be used, and `terminal_total_difficulty` will operate with [default functionality](./fork.md#initializing-transition-store). Sufficient warning to the user about this exceptional configurable setting should be provided. [here](fork.md#initializing-transition-store). From 252f4ea14ad5a48d7100a38968f636d380e893b2 Mon Sep 17 00:00:00 2001 From: Lakshman Sankar Date: Thu, 9 Sep 2021 08:37:39 -0700 Subject: [PATCH 114/122] Wording change Co-authored-by: Danny Ryan --- specs/merge/client_settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index 05a13094a..6356e8a5b 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -2,7 +2,7 @@ **Notice**: This document is a work-in-progress for researchers and implementers. -This document specifies configurable settings that merge clients are expected to ship with. +This document specifies configurable settings that clients must implement for the Merge. ### Override terminal total difficulty From 83471fe46121760d6fc8b2e150e6590c7f6ad3f7 Mon Sep 17 00:00:00 2001 From: Lakshman Sankar Date: Thu, 9 Sep 2021 08:38:33 -0700 Subject: [PATCH 115/122] Apply suggestions from code review Co-authored-by: Danny Ryan --- specs/merge/client_settings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index 6356e8a5b..3ff897560 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -6,11 +6,11 @@ This document specifies configurable settings that clients must implement for th ### Override terminal total difficulty -To coordinate changes to [`terminal_total_difficulty`](fork-choice.md#transitionstore), clients +To coordinate manual overrides to [`terminal_total_difficulty`](fork-choice.md#transitionstore), clients must provide `--terminal-total-difficulty-override` as a configurable setting. If `TransitionStore` has already [been initialized](./fork.md#initializing-transition-store), this alters the previously initialized value of -`TransitionStore.terminal_total_difficulty`, otherwise it initializes `TransitionStore` with the specified +`TransitionStore.terminal_total_difficulty`, otherwise this setting initializes `TransitionStore` with the specified, bypassing `compute_terminal_total_difficulty` and the use of an `anchor_pow_block`. `terminal_total_difficulty`. Except under exceptional scenarios, this setting is expected to not be used, and `terminal_total_difficulty` will operate with [default functionality](./fork.md#initializing-transition-store). Sufficient warning to the user about this exceptional configurable setting should be provided. From 879a60a1697b72497e5dfb0cd0cc733d51b4ac85 Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Thu, 9 Sep 2021 08:45:21 -0700 Subject: [PATCH 116/122] Run doctoc --- specs/merge/client_settings.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/merge/client_settings.md b/specs/merge/client_settings.md index 3ff897560..a8ca633ff 100644 --- a/specs/merge/client_settings.md +++ b/specs/merge/client_settings.md @@ -1,3 +1,12 @@ + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [The Merge -- Client Settings](#the-merge----client-settings) + - [Override terminal total difficulty](#override-terminal-total-difficulty) + + + # The Merge -- Client Settings **Notice**: This document is a work-in-progress for researchers and implementers. From c0994e6736bac1400cb24fb9456c3e6936f134cb Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 9 Sep 2021 13:24:55 -0700 Subject: [PATCH 117/122] Add sync committee tests with exited and withdrawable members --- .../test_process_sync_aggregate.py | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index 0eaddbb88..933bed1b2 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -5,6 +5,7 @@ from eth2spec.test.helpers.block import ( from eth2spec.test.helpers.state import ( state_transition_and_sign_block, transition_to, + next_epoch_via_block, ) from eth2spec.test.helpers.constants import ( MAINNET, MINIMAL, @@ -15,6 +16,10 @@ from eth2spec.test.helpers.sync_committee import ( run_sync_committee_processing, run_successful_sync_committee_test, ) +from eth2spec.test.helpers.voluntary_exits import ( + prepare_signed_exits, + get_unslashed_exited_validators, +) from eth2spec.test.context import ( with_altair_and_later, with_presets, @@ -402,3 +407,189 @@ def test_proposer_in_committee_with_participation(spec, state): else: state_transition_and_sign_block(spec, state, block) raise AssertionError("failed to find a proposer in the sync committee set; check test setup") + + +@with_altair_and_later +@spec_state_test +@always_bls +def test_sync_committee_with_participating_exited_member(spec, state): + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + # move forward via some blocks + for _ in range(3): + next_epoch_via_block(spec, state) + + committee_indices = compute_committee_indices(spec, state) + rng = random.Random(1010) + + exited_validator_index = rng.sample(committee_indices, 1)[0] + exits = prepare_signed_exits(spec, state, [exited_validator_index]) + assert len(exits) == 1 + voluntary_exit = exits.pop() + spec.process_voluntary_exit(state, voluntary_exit) + + exit_epoch = state.validators[exited_validator_index].exit_epoch + exit_slot = exit_epoch * spec.SLOTS_PER_EPOCH + transition_to(spec, state, exit_slot) + + exited_validator_indices = get_unslashed_exited_validators(spec, state) + assert exited_validator_index in exited_validator_indices + exited_pubkey = state.validators[exited_validator_index].pubkey + assert exited_pubkey in state.current_sync_committee.pubkeys + current_epoch = spec.get_current_epoch(state) + assert current_epoch < state.validators[exited_validator_index].withdrawable_epoch + + block = build_empty_block_for_next_slot(spec, state) + block.body.sync_aggregate = spec.SyncAggregate( + sync_committee_bits=[True] * len(committee_indices), + sync_committee_signature=compute_aggregate_sync_committee_signature( + spec, + state, + block.slot - 1, + committee_indices, # full committee signs + ) + ) + yield from run_sync_committee_processing(spec, state, block) + + +@with_altair_and_later +@spec_state_test +@always_bls +def test_sync_committee_with_nonparticipating_exited_member(spec, state): + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + # move forward via some blocks + for _ in range(3): + next_epoch_via_block(spec, state) + + committee_indices = compute_committee_indices(spec, state) + rng = random.Random(1010) + + exited_validator_index = rng.sample(committee_indices, 1)[0] + exits = prepare_signed_exits(spec, state, [exited_validator_index]) + assert len(exits) == 1 + voluntary_exit = exits.pop() + spec.process_voluntary_exit(state, voluntary_exit) + + exit_epoch = state.validators[exited_validator_index].exit_epoch + exit_slot = exit_epoch * spec.SLOTS_PER_EPOCH + transition_to(spec, state, exit_slot) + + exited_validator_indices = get_unslashed_exited_validators(spec, state) + assert exited_validator_index in exited_validator_indices + exited_pubkey = state.validators[exited_validator_index].pubkey + assert exited_pubkey in state.current_sync_committee.pubkeys + current_epoch = spec.get_current_epoch(state) + assert current_epoch < state.validators[exited_validator_index].withdrawable_epoch + + exited_committee_index = state.current_sync_committee.pubkeys.index(exited_pubkey) + block = build_empty_block_for_next_slot(spec, state) + committee_bits = [i != exited_committee_index for i in committee_indices] + committee_indices.remove(exited_committee_index) + block.body.sync_aggregate = spec.SyncAggregate( + sync_committee_bits=committee_bits, + sync_committee_signature=compute_aggregate_sync_committee_signature( + spec, + state, + block.slot - 1, + committee_indices, # with exited validator removed + ) + ) + yield from run_sync_committee_processing(spec, state, block) + + +@with_altair_and_later +@spec_state_test +@always_bls +def test_sync_committee_with_participating_withdrawable_member(spec, state): + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + # move forward via some blocks + for _ in range(3): + next_epoch_via_block(spec, state) + + committee_indices = compute_committee_indices(spec, state) + rng = random.Random(1010) + + exited_validator_index = rng.sample(committee_indices, 1)[0] + exits = prepare_signed_exits(spec, state, [exited_validator_index]) + assert len(exits) == 1 + voluntary_exit = exits.pop() + spec.process_voluntary_exit(state, voluntary_exit) + + target_validator = state.validators[exited_validator_index] + target_validator.withdrawable_epoch = target_validator.exit_epoch + 1 + + target_slot = (target_validator.withdrawable_epoch + 1) * spec.SLOTS_PER_EPOCH + transition_to(spec, state, target_slot) + + exited_validator_indices = get_unslashed_exited_validators(spec, state) + assert exited_validator_index in exited_validator_indices + exited_pubkey = state.validators[exited_validator_index].pubkey + assert exited_pubkey in state.current_sync_committee.pubkeys + current_epoch = spec.get_current_epoch(state) + assert current_epoch > state.validators[exited_validator_index].withdrawable_epoch + + block = build_empty_block_for_next_slot(spec, state) + block.body.sync_aggregate = spec.SyncAggregate( + sync_committee_bits=[True] * len(committee_indices), + sync_committee_signature=compute_aggregate_sync_committee_signature( + spec, + state, + block.slot - 1, + committee_indices, # full committee signs + ) + ) + yield from run_sync_committee_processing(spec, state, block) + + +@with_altair_and_later +@spec_state_test +@always_bls +def test_sync_committee_with_nonparticipating_withdrawable_member(spec, state): + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + # move forward via some blocks + for _ in range(3): + next_epoch_via_block(spec, state) + + committee_indices = compute_committee_indices(spec, state) + rng = random.Random(1010) + + exited_validator_index = rng.sample(committee_indices, 1)[0] + exits = prepare_signed_exits(spec, state, [exited_validator_index]) + assert len(exits) == 1 + voluntary_exit = exits.pop() + spec.process_voluntary_exit(state, voluntary_exit) + + target_validator = state.validators[exited_validator_index] + target_validator.withdrawable_epoch = target_validator.exit_epoch + 1 + + target_slot = (target_validator.withdrawable_epoch + 1) * spec.SLOTS_PER_EPOCH + transition_to(spec, state, target_slot) + + exited_validator_indices = get_unslashed_exited_validators(spec, state) + assert exited_validator_index in exited_validator_indices + exited_pubkey = state.validators[exited_validator_index].pubkey + assert exited_pubkey in state.current_sync_committee.pubkeys + current_epoch = spec.get_current_epoch(state) + assert current_epoch > state.validators[exited_validator_index].withdrawable_epoch + + target_committee_index = state.current_sync_committee.pubkeys.index(exited_pubkey) + block = build_empty_block_for_next_slot(spec, state) + committee_bits = [i != target_committee_index for i in committee_indices] + committee_indices.remove(target_committee_index) + block.body.sync_aggregate = spec.SyncAggregate( + sync_committee_bits=committee_bits, + sync_committee_signature=compute_aggregate_sync_committee_signature( + spec, + state, + block.slot - 1, + committee_indices, # with withdrawable validator removed + ) + ) + yield from run_sync_committee_processing(spec, state, block) From a47ade3ba6eb96e6b51957cfeb2ecc34910f3740 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 9 Sep 2021 15:05:52 -0600 Subject: [PATCH 118/122] pr feedback --- .../test_process_registry_updates.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index 5bcf3a82b..6539dc92d 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -307,15 +307,17 @@ def test_activation_queue_activation_and_ejection__1(spec, state): @with_all_phases @spec_state_test def test_activation_queue_activation_and_ejection__churn_limit(spec, state): - num_validators_per_status = spec.get_validator_churn_limit(state) - yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status) + churn_limit = spec.get_validator_churn_limit(state) + assert churn_limit == spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_activation_queue_activation_and_ejection(spec, state, churn_limit) @with_all_phases @spec_state_test def test_activation_queue_activation_and_ejection__exceed_churn_limit(spec, state): - num_validators_per_status = spec.get_validator_churn_limit(state) + 1 - yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status) + churn_limit = spec.get_validator_churn_limit(state) + assert churn_limit == spec.config.MIN_PER_EPOCH_CHURN_LIMIT + yield from run_test_activation_queue_activation_and_ejection(spec, state, churn_limit + 1) @with_all_phases @@ -339,5 +341,4 @@ def test_activation_queue_activation_and_ejection__scaled_churn_limit(spec, stat def test_activation_queue_activation_and_ejection__exceed_scaled_churn_limit(spec, state): churn_limit = spec.get_validator_churn_limit(state) assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT - num_validators_per_status = churn_limit * 2 - yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status) + yield from run_test_activation_queue_activation_and_ejection(spec, state, churn_limit * 2) From 5348b9a3b905dc3477c8bd9d3892c928b7d117ab Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 9 Sep 2021 15:56:08 -0600 Subject: [PATCH 119/122] randomize state can result in some exited vals for current epoch --- tests/core/pyspec/eth2spec/test/helpers/random.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/random.py b/tests/core/pyspec/eth2spec/test/helpers/random.py index b24d3c8c7..8448b2424 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/random.py +++ b/tests/core/pyspec/eth2spec/test/helpers/random.py @@ -37,8 +37,8 @@ def exit_random_validators(spec, state, rng, fraction=None): continue validator = state.validators[index] - validator.exit_epoch = rng.choice([current_epoch - 1, current_epoch - 2, current_epoch - 3]) - # ~1/2 are withdrawable + validator.exit_epoch = rng.choice([current_epoch, current_epoch - 1, current_epoch - 2, current_epoch - 3]) + # ~1/2 are withdrawable (note, unnatural span between exit epoch and withdrawable epoch) if rng.choice([True, False]): validator.withdrawable_epoch = current_epoch else: From 0cee5660dba55f6e0ed1745b597b786bf2209c33 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 9 Sep 2021 15:43:42 -0700 Subject: [PATCH 120/122] pr feedback --- .../test_process_sync_aggregate.py | 119 +++++++++--------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index 933bed1b2..474380acd 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -17,7 +17,6 @@ from eth2spec.test.helpers.sync_committee import ( run_successful_sync_committee_test, ) from eth2spec.test.helpers.voluntary_exits import ( - prepare_signed_exits, get_unslashed_exited_validators, ) from eth2spec.test.context import ( @@ -409,6 +408,30 @@ def test_proposer_in_committee_with_participation(spec, state): raise AssertionError("failed to find a proposer in the sync committee set; check test setup") +def _exit_validator_from_committee_and_transition_state(spec, + state, + committee_indices, + rng, + target_epoch_provider, + withdrawable_offset=1): + exited_validator_index = rng.sample(committee_indices, 1)[0] + validator = state.validators[exited_validator_index] + current_epoch = spec.get_current_epoch(state) + validator.exit_epoch = current_epoch + validator.withdrawable_epoch = validator.exit_epoch + withdrawable_offset + + target_epoch = target_epoch_provider(state.validators[exited_validator_index]) + target_slot = target_epoch * spec.SLOTS_PER_EPOCH + transition_to(spec, state, target_slot) + + exited_validator_indices = get_unslashed_exited_validators(spec, state) + assert exited_validator_index in exited_validator_indices + exited_pubkey = state.validators[exited_validator_index].pubkey + assert exited_pubkey in state.current_sync_committee.pubkeys + + return exited_validator_index + + @with_altair_and_later @spec_state_test @always_bls @@ -423,22 +446,16 @@ def test_sync_committee_with_participating_exited_member(spec, state): committee_indices = compute_committee_indices(spec, state) rng = random.Random(1010) - exited_validator_index = rng.sample(committee_indices, 1)[0] - exits = prepare_signed_exits(spec, state, [exited_validator_index]) - assert len(exits) == 1 - voluntary_exit = exits.pop() - spec.process_voluntary_exit(state, voluntary_exit) + exited_index = _exit_validator_from_committee_and_transition_state( + spec, + state, + committee_indices, + rng, + lambda v: v.exit_epoch, + ) - exit_epoch = state.validators[exited_validator_index].exit_epoch - exit_slot = exit_epoch * spec.SLOTS_PER_EPOCH - transition_to(spec, state, exit_slot) - - exited_validator_indices = get_unslashed_exited_validators(spec, state) - assert exited_validator_index in exited_validator_indices - exited_pubkey = state.validators[exited_validator_index].pubkey - assert exited_pubkey in state.current_sync_committee.pubkeys current_epoch = spec.get_current_epoch(state) - assert current_epoch < state.validators[exited_validator_index].withdrawable_epoch + assert current_epoch < state.validators[exited_index].withdrawable_epoch block = build_empty_block_for_next_slot(spec, state) block.body.sync_aggregate = spec.SyncAggregate( @@ -467,22 +484,17 @@ def test_sync_committee_with_nonparticipating_exited_member(spec, state): committee_indices = compute_committee_indices(spec, state) rng = random.Random(1010) - exited_validator_index = rng.sample(committee_indices, 1)[0] - exits = prepare_signed_exits(spec, state, [exited_validator_index]) - assert len(exits) == 1 - voluntary_exit = exits.pop() - spec.process_voluntary_exit(state, voluntary_exit) + exited_index = _exit_validator_from_committee_and_transition_state( + spec, + state, + committee_indices, + rng, + lambda v: v.exit_epoch, + ) + exited_pubkey = state.validators[exited_index].pubkey - exit_epoch = state.validators[exited_validator_index].exit_epoch - exit_slot = exit_epoch * spec.SLOTS_PER_EPOCH - transition_to(spec, state, exit_slot) - - exited_validator_indices = get_unslashed_exited_validators(spec, state) - assert exited_validator_index in exited_validator_indices - exited_pubkey = state.validators[exited_validator_index].pubkey - assert exited_pubkey in state.current_sync_committee.pubkeys current_epoch = spec.get_current_epoch(state) - assert current_epoch < state.validators[exited_validator_index].withdrawable_epoch + assert current_epoch < state.validators[exited_index].withdrawable_epoch exited_committee_index = state.current_sync_committee.pubkeys.index(exited_pubkey) block = build_empty_block_for_next_slot(spec, state) @@ -514,24 +526,16 @@ def test_sync_committee_with_participating_withdrawable_member(spec, state): committee_indices = compute_committee_indices(spec, state) rng = random.Random(1010) - exited_validator_index = rng.sample(committee_indices, 1)[0] - exits = prepare_signed_exits(spec, state, [exited_validator_index]) - assert len(exits) == 1 - voluntary_exit = exits.pop() - spec.process_voluntary_exit(state, voluntary_exit) + exited_index = _exit_validator_from_committee_and_transition_state( + spec, + state, + committee_indices, + rng, + lambda v: v.withdrawable_epoch + 1, + ) - target_validator = state.validators[exited_validator_index] - target_validator.withdrawable_epoch = target_validator.exit_epoch + 1 - - target_slot = (target_validator.withdrawable_epoch + 1) * spec.SLOTS_PER_EPOCH - transition_to(spec, state, target_slot) - - exited_validator_indices = get_unslashed_exited_validators(spec, state) - assert exited_validator_index in exited_validator_indices - exited_pubkey = state.validators[exited_validator_index].pubkey - assert exited_pubkey in state.current_sync_committee.pubkeys current_epoch = spec.get_current_epoch(state) - assert current_epoch > state.validators[exited_validator_index].withdrawable_epoch + assert current_epoch > state.validators[exited_index].withdrawable_epoch block = build_empty_block_for_next_slot(spec, state) block.body.sync_aggregate = spec.SyncAggregate( @@ -560,24 +564,17 @@ def test_sync_committee_with_nonparticipating_withdrawable_member(spec, state): committee_indices = compute_committee_indices(spec, state) rng = random.Random(1010) - exited_validator_index = rng.sample(committee_indices, 1)[0] - exits = prepare_signed_exits(spec, state, [exited_validator_index]) - assert len(exits) == 1 - voluntary_exit = exits.pop() - spec.process_voluntary_exit(state, voluntary_exit) + exited_index = _exit_validator_from_committee_and_transition_state( + spec, + state, + committee_indices, + rng, + lambda v: v.withdrawable_epoch + 1, + ) + exited_pubkey = state.validators[exited_index].pubkey - target_validator = state.validators[exited_validator_index] - target_validator.withdrawable_epoch = target_validator.exit_epoch + 1 - - target_slot = (target_validator.withdrawable_epoch + 1) * spec.SLOTS_PER_EPOCH - transition_to(spec, state, target_slot) - - exited_validator_indices = get_unslashed_exited_validators(spec, state) - assert exited_validator_index in exited_validator_indices - exited_pubkey = state.validators[exited_validator_index].pubkey - assert exited_pubkey in state.current_sync_committee.pubkeys current_epoch = spec.get_current_epoch(state) - assert current_epoch > state.validators[exited_validator_index].withdrawable_epoch + assert current_epoch > state.validators[exited_index].withdrawable_epoch target_committee_index = state.current_sync_committee.pubkeys.index(exited_pubkey) block = build_empty_block_for_next_slot(spec, state) From 8f064d104f656139d1a423d9e1e6c96e0c1a30f6 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 9 Sep 2021 17:11:27 -0600 Subject: [PATCH 121/122] bmp version.txt to 1.1.0-beta-4 --- tests/core/pyspec/eth2spec/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/VERSION.txt b/tests/core/pyspec/eth2spec/VERSION.txt index a0e0952ff..3bec004b5 100644 --- a/tests/core/pyspec/eth2spec/VERSION.txt +++ b/tests/core/pyspec/eth2spec/VERSION.txt @@ -1 +1 @@ -1.1.0-beta.3 \ No newline at end of file +1.1.0-beta.4 \ No newline at end of file From d6b5cbd94c39aafa6199e776a6f672b5c94b113f Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 9 Sep 2021 19:53:30 -0600 Subject: [PATCH 122/122] fix sync agg test for mainnet --- .../test_process_sync_aggregate.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py index 474380acd..8a2deabb1 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py @@ -41,6 +41,7 @@ def test_invalid_signature_bad_domain(spec, state): state, block.slot - 1, committee_indices, # full committee signs + block_root=block.parent_root, domain_type=spec.DOMAIN_BEACON_ATTESTER, # Incorrect domain ) ) @@ -64,6 +65,7 @@ def test_invalid_signature_missing_participant(spec, state): state, block.slot - 1, committee_indices, # full committee signs + block_root=block.parent_root, ) ) yield from run_sync_committee_processing(spec, state, block, expect_exception=True) @@ -127,6 +129,7 @@ def test_invalid_signature_extra_participant(spec, state): state, block.slot - 1, [index for index in committee_indices if index != random_participant], + block_root=block.parent_root, ) ) @@ -236,6 +239,7 @@ def test_invalid_signature_past_block(spec, state): state, block.slot - 1, committee_indices, + block_root=block.parent_root, ) ) @@ -286,6 +290,7 @@ def test_invalid_signature_previous_committee(spec, state): state, block.slot - 1, committee_indices, + block_root=block.parent_root, ) ) @@ -327,6 +332,7 @@ def test_valid_signature_future_committee(spec, state): state, block.slot - 1, committee_indices, + block_root=block.parent_root, ) ) @@ -360,6 +366,7 @@ def test_proposer_in_committee_without_participation(spec, state): state, block.slot - 1, participants, + block_root=block.parent_root, ) ) @@ -396,6 +403,7 @@ def test_proposer_in_committee_with_participation(spec, state): state, block.slot - 1, committee_indices, + block_root=block.parent_root, ) ) @@ -465,6 +473,7 @@ def test_sync_committee_with_participating_exited_member(spec, state): state, block.slot - 1, committee_indices, # full committee signs + block_root=block.parent_root, ) ) yield from run_sync_committee_processing(spec, state, block) @@ -499,7 +508,7 @@ def test_sync_committee_with_nonparticipating_exited_member(spec, state): exited_committee_index = state.current_sync_committee.pubkeys.index(exited_pubkey) block = build_empty_block_for_next_slot(spec, state) committee_bits = [i != exited_committee_index for i in committee_indices] - committee_indices.remove(exited_committee_index) + committee_indices = [index for index in committee_indices if index != exited_committee_index] block.body.sync_aggregate = spec.SyncAggregate( sync_committee_bits=committee_bits, sync_committee_signature=compute_aggregate_sync_committee_signature( @@ -507,6 +516,7 @@ def test_sync_committee_with_nonparticipating_exited_member(spec, state): state, block.slot - 1, committee_indices, # with exited validator removed + block_root=block.parent_root, ) ) yield from run_sync_committee_processing(spec, state, block) @@ -545,6 +555,7 @@ def test_sync_committee_with_participating_withdrawable_member(spec, state): state, block.slot - 1, committee_indices, # full committee signs + block_root=block.parent_root, ) ) yield from run_sync_committee_processing(spec, state, block) @@ -579,7 +590,7 @@ def test_sync_committee_with_nonparticipating_withdrawable_member(spec, state): target_committee_index = state.current_sync_committee.pubkeys.index(exited_pubkey) block = build_empty_block_for_next_slot(spec, state) committee_bits = [i != target_committee_index for i in committee_indices] - committee_indices.remove(target_committee_index) + committee_indices = [index for index in committee_indices if index != target_committee_index] block.body.sync_aggregate = spec.SyncAggregate( sync_committee_bits=committee_bits, sync_committee_signature=compute_aggregate_sync_committee_signature( @@ -587,6 +598,7 @@ def test_sync_committee_with_nonparticipating_withdrawable_member(spec, state): state, block.slot - 1, committee_indices, # with withdrawable validator removed + block_root=block.parent_root, ) ) yield from run_sync_committee_processing(spec, state, block)