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}.