Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add randomized tests for bellatrix #2821

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
438 changes: 438 additions & 0 deletions tests/core/pyspec/eth2spec/test/bellatrix/random/test_random.py

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,22 @@ def randomize_state(spec, state, stats, exit_fraction=0.1, slash_fraction=0.1):
return scenario_state


def randomize_state_altair(spec, state, stats):
scenario_state = randomize_state(spec, state, stats, exit_fraction=0.1, slash_fraction=0.1)
def randomize_state_altair(spec, state, stats, exit_fraction=0.1, slash_fraction=0.1):
scenario_state = randomize_state(spec, state, stats, exit_fraction=exit_fraction, slash_fraction=slash_fraction)
randomize_inactivity_scores(spec, state)
return scenario_state


def randomize_state_bellatrix(spec, state, stats, exit_fraction=0.1, slash_fraction=0.1):
scenario_state = randomize_state_altair(spec,
state,
stats,
exit_fraction=exit_fraction,
slash_fraction=slash_fraction)
# TODO: randomize execution payload, merge status, etc.
return scenario_state


# epochs

def epochs_until_leak(spec):
Expand Down Expand Up @@ -179,6 +189,12 @@ def random_block_altair_with_cycling_sync_committee_participation(spec,
return block


def random_block_bellatrix(spec, state, signed_blocks, scenario_state):
block = random_block_altair_with_cycling_sync_committee_participation(spec, state, signed_blocks, scenario_state)
# TODO: return randomized execution payload
return block


# validations

def no_op_validation(_spec, _state):
Expand Down
2 changes: 2 additions & 0 deletions tests/generators/random/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ all:
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
rm -f ../../core/pyspec/eth2spec/test/bellatrix/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
python3 generate.py bellatrix > ../../core/pyspec/eth2spec/test/bellatrix/random/test_random.py
11 changes: 10 additions & 1 deletion tests/generators/random/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
no_op_validation,
randomize_state,
randomize_state_altair,
randomize_state_bellatrix,
random_block,
random_block_altair_with_cycling_sync_committee_participation,
random_block_bellatrix,
last_slot_in_epoch,
random_slot_in_epoch,
penultimate_slot_in_epoch,
Expand All @@ -30,7 +32,7 @@
transition_to_leaking,
transition_without_leak,
)
from eth2spec.test.helpers.constants import PHASE0, ALTAIR
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, BELLATRIX


# Ensure this many blocks are present in *each* randomized scenario
Expand Down Expand Up @@ -254,5 +256,12 @@ def run_generate_tests_to_std_out(phase, state_randomizer, block_randomizer):
state_randomizer=randomize_state_altair,
block_randomizer=random_block_altair_with_cycling_sync_committee_participation,
)
if BELLATRIX in sys.argv:
did_generate = True
run_generate_tests_to_std_out(
BELLATRIX,
state_randomizer=randomize_state_bellatrix,
block_randomizer=random_block_bellatrix,
)
if not did_generate:
warnings.warn("no phase given for test generation")
6 changes: 5 additions & 1 deletion tests/generators/random/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from eth2spec.test.helpers.constants import PHASE0, ALTAIR
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, BELLATRIX
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators


Expand All @@ -9,10 +9,14 @@
altair_mods = {key: 'eth2spec.test.altair.random.test_' + key for key in [
'random',
]}
bellatrix_mods = {key: 'eth2spec.test.bellatrix.random.test_' + key for key in [
'random',
]}

all_mods = {
PHASE0: phase_0_mods,
ALTAIR: altair_mods,
BELLATRIX: bellatrix_mods,
}

run_state_test_generators(runner_name="random", all_mods=all_mods)