This commit is contained in:
Alex Stokes 2021-08-23 12:40:42 -07:00
parent cc04da8e79
commit d037c6662a
No known key found for this signature in database
GPG Key ID: 99B3D88FD6C55A69
4 changed files with 21 additions and 6 deletions

View File

@ -26,6 +26,7 @@ from eth2spec.test.utils.random import (
SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4 SYNC_AGGREGATE_PARTICIPATION_BUCKETS = 4
def _randomize_altair_state(spec, state): def _randomize_altair_state(spec, state):
randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1) randomize_state(spec, state, exit_fraction=0.1, slash_fraction=0.1)
randomize_inactivity_scores(spec, state) randomize_inactivity_scores(spec, state)

View File

@ -16,6 +16,7 @@ from eth2spec.test.utils.random import (
run_generated_randomized_test, run_generated_randomized_test,
) )
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
""" """
Pytest hook to generate test cases from dynamically computed data Pytest hook to generate test cases from dynamically computed data

View File

@ -3,3 +3,10 @@ from .utils import (
with_meta_tags, with_meta_tags,
build_transition_test, build_transition_test,
) )
__all__ = [ # avoid "unused import" lint error
"vector_test",
"with_meta_tags",
"build_transition_test",
]

View File

@ -21,6 +21,7 @@ from eth2spec.test.helpers.random import (
rng = random.Random(1337) rng = random.Random(1337)
def _warn_if_empty_operations(block): def _warn_if_empty_operations(block):
if len(block.body.deposits) == 0: if len(block.body.deposits) == 0:
warnings.warn(f"deposits missing in block at slot {block.slot}") warnings.warn(f"deposits missing in block at slot {block.slot}")
@ -45,13 +46,14 @@ BLOCK_ATTEMPTS = 32
BLOCK_TRANSITIONS_COUNT = 2 BLOCK_TRANSITIONS_COUNT = 2
# primitives # primitives
## state # state
def randomize_state(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) randomize_state_helper(spec, state, exit_fraction=exit_fraction, slash_fraction=slash_fraction)
## epochs # epochs
def _epochs_until_leak(spec): def _epochs_until_leak(spec):
""" """
@ -65,7 +67,7 @@ def _epochs_for_shard_committee_period(spec):
return spec.config.SHARD_COMMITTEE_PERIOD return spec.config.SHARD_COMMITTEE_PERIOD
## slots # slots
def _last_slot_in_epoch(spec): def _last_slot_in_epoch(spec):
return spec.SLOTS_PER_EPOCH - 1 return spec.SLOTS_PER_EPOCH - 1
@ -81,7 +83,7 @@ def _penultimate_slot_in_epoch(spec):
return spec.SLOTS_PER_EPOCH - 2 return spec.SLOTS_PER_EPOCH - 2
## blocks # blocks
def _no_block(_spec, _pre_state, _signed_blocks): def _no_block(_spec, _pre_state, _signed_blocks):
return None 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") raise AssertionError("could not find a block with an unslashed proposer, check ``state`` input")
## validations # validations
def _no_op_validation(spec, state): def _no_op_validation(spec, state):
return True return True
@ -158,7 +160,8 @@ def _transition_to_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 # block transitions
def _transition_with_random_block(block_randomizer): def _transition_with_random_block(block_randomizer):
""" """
@ -173,6 +176,7 @@ def _transition_with_random_block(block_randomizer):
# setup and test gen # setup and test gen
def _randomized_scenario_setup(state_randomizer): def _randomized_scenario_setup(state_randomizer):
""" """
Return a sequence of pairs of ("mutator", "validator"), 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: # 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 Pytest hook to generate test cases from dynamically computed data
@ -358,6 +363,7 @@ def pytest_generate_tests_adapter(f):
# Run the generated tests: # Run the generated tests:
def _iter_temporal(spec, callable_or_int): def _iter_temporal(spec, callable_or_int):
""" """
Intended to advance some number of {epochs, slots}. Intended to advance some number of {epochs, slots}.