diff --git a/test_generators/shuffling/main.py b/test_generators/shuffling/main.py index adfab8cfb..6425c708a 100644 --- a/test_generators/shuffling/main.py +++ b/test_generators/shuffling/main.py @@ -1,54 +1,49 @@ from eth2spec.phase0 import spec as spec -from eth_utils import ( - to_dict, to_tuple -) -from gen_base import gen_runner, gen_suite, gen_typing +from eth_utils import to_tuple +from gen_base import gen_runner, gen_typing from preset_loader import loader +from typing import Iterable + + +def shuffling_case_fn(seed, count): + yield 'mapping', 'data', { + 'seed': '0x' + seed.hex(), + 'count': count, + 'mapping': [int(spec.compute_shuffled_index(i, count, seed)) for i in range(count)] + } -@to_dict def shuffling_case(seed, count): - yield 'seed', '0x' + seed.hex() - yield 'count', count - yield 'shuffled', [int(spec.compute_shuffled_index(i, count, seed)) for i in range(count)] + return f'shuffle_0x{seed.hex()}_{count}', lambda: shuffling_case_fn(seed, count) @to_tuple def shuffling_test_cases(): - 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]: + for seed in [spec.hash(seed_init_value.to_bytes(length=4, byteorder='little')) for seed_init_value in range(30)]: + for count in [0, 1, 2, 3, 5, 10, 33, 100, 1000, 9999]: yield shuffling_case(seed, count) -def mini_shuffling_suite(configs_path: str) -> gen_typing.TestSuiteOutput: - presets = loader.load_presets(configs_path, 'minimal') - spec.apply_constants_preset(presets) +def create_provider(config_name: str) -> gen_typing.TestProvider: - 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", - forks_timeline="testing", - forks=["phase0"], - config="minimal", - runner="shuffling", - handler="core", - test_cases=shuffling_test_cases())) + def prepare_fn(configs_path: str) -> str: + presets = loader.load_presets(configs_path, config_name) + spec.apply_constants_preset(presets) + return config_name + def cases_fn() -> Iterable[gen_typing.TestCase]: + for (case_name, case_fn) in shuffling_test_cases(): + yield gen_typing.TestCase( + fork_name='phase0', + runner_name='shuffling', + handler_name='core', + suite_name='shuffle', + case_name=case_name, + case_fn=case_fn + ) -def full_shuffling_suite(configs_path: str) -> gen_typing.TestSuiteOutput: - presets = loader.load_presets(configs_path, 'mainnet') - spec.apply_constants_preset(presets) - - 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", - forks_timeline="mainnet", - forks=["phase0"], - config="mainnet", - runner="shuffling", - handler="core", - test_cases=shuffling_test_cases())) + return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn) if __name__ == "__main__": - gen_runner.run_generator("shuffling", [mini_shuffling_suite, full_shuffling_suite]) + gen_runner.run_generator("shuffling", [create_provider("minimal"), create_provider("mainnet")])