mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-21 14:58:12 +00:00
move to code-gen under new test generator
This commit is contained in:
parent
505bdba8f8
commit
c27e4d140e
421
tests/core/pyspec/eth2spec/test/altair/random/test_random.py
Normal file
421
tests/core/pyspec/eth2spec/test/altair/random/test_random.py
Normal file
@ -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,
|
||||
)
|
@ -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)
|
421
tests/core/pyspec/eth2spec/test/phase0/random/test_random.py
Normal file
421
tests/core/pyspec/eth2spec/test/phase0/random/test_random.py
Normal file
@ -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,
|
||||
)
|
@ -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)
|
@ -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
|
||||
|
7
tests/generators/random/Makefile
Normal file
7
tests/generators/random/Makefile
Normal file
@ -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
|
29
tests/generators/random/README.md
Normal file
29
tests/generators/random/README.md
Normal file
@ -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
|
||||
```
|
243
tests/generators/random/generate.py
Normal file
243
tests/generators/random/generate.py
Normal file
@ -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")
|
18
tests/generators/random/main.py
Normal file
18
tests/generators/random/main.py
Normal file
@ -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)
|
2
tests/generators/random/requirements.txt
Normal file
2
tests/generators/random/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
pytest>=4.4
|
||||
../../../[generator]
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user