eth2.0-specs/test_generators/shuffling/main.py

55 lines
1.9 KiB
Python
Raw Normal View History

from eth2spec.phase0 import spec
2019-04-10 15:52:51 +00:00
from eth_utils import (
to_dict, to_tuple
)
from gen_base import gen_runner, gen_suite, gen_typing
from preset_loader import loader
@to_dict
def shuffling_case(seed: spec.Bytes32, count: int):
yield 'seed', '0x' + seed.hex()
yield 'count', count
yield 'shuffled', [spec.get_permuted_index(i, count, seed) for i in range(count)]
2019-04-10 15:52:51 +00:00
@to_tuple
def shuffling_test_cases():
2019-05-07 09:57:41 +00:00
for seed in [spec.hash(spec.int_to_bytes(seed_init_value, length=4)) for seed_init_value in range(30)]:
for count in [0, 1, 2, 3, 5, 10, 33, 100, 1000]:
yield shuffling_case(seed, count)
2019-04-10 15:52:51 +00:00
def mini_shuffling_suite(configs_path: str) -> gen_typing.TestSuiteOutput:
presets = loader.load_presets(configs_path, 'minimal')
spec.apply_constants_preset(presets)
2019-04-10 15:52:51 +00:00
return ("shuffling_minimal", "core", gen_suite.render_suite(
title="Swap-or-Not Shuffling tests with minimal config",
summary="Swap or not shuffling, with minimally configured testing round-count",
2019-04-10 15:52:51 +00:00
forks_timeline="testing",
forks=["phase0"],
config="minimal",
2019-04-14 10:17:22 +00:00
runner="shuffling",
2019-04-10 15:52:51 +00:00
handler="core",
test_cases=shuffling_test_cases()))
2019-04-10 15:52:51 +00:00
def full_shuffling_suite(configs_path: str) -> gen_typing.TestSuiteOutput:
presets = loader.load_presets(configs_path, 'mainnet')
spec.apply_constants_preset(presets)
2019-04-10 15:52:51 +00:00
return ("shuffling_full", "core", gen_suite.render_suite(
title="Swap-or-Not Shuffling tests with mainnet config",
summary="Swap or not shuffling, with normal configured (secure) mainnet round-count",
2019-04-10 15:52:51 +00:00
forks_timeline="mainnet",
forks=["phase0"],
config="mainnet",
2019-04-14 10:17:22 +00:00
runner="shuffling",
2019-04-10 15:52:51 +00:00
handler="core",
test_cases=shuffling_test_cases()))
2019-04-10 15:52:51 +00:00
if __name__ == "__main__":
gen_runner.run_generator("shuffling", [mini_shuffling_suite, full_shuffling_suite])