2019-07-27 00:22:19 +00:00
|
|
|
from eth_utils import to_tuple
|
|
|
|
from typing import Iterable
|
2020-01-25 00:26:10 +00:00
|
|
|
from importlib import reload
|
2020-01-25 21:10:03 +00:00
|
|
|
|
|
|
|
from gen_base import gen_runner, gen_typing
|
|
|
|
|
2020-01-25 00:26:10 +00:00
|
|
|
from eth2spec.config import config_util
|
2020-01-25 21:10:03 +00:00
|
|
|
from eth2spec.phase0 import spec as spec
|
2020-01-25 00:26:10 +00:00
|
|
|
|
2019-07-27 00:22:19 +00:00
|
|
|
|
|
|
|
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)]
|
|
|
|
}
|
2019-04-10 15:52:51 +00:00
|
|
|
|
|
|
|
|
2019-06-11 16:34:49 +00:00
|
|
|
def shuffling_case(seed, count):
|
2019-07-27 00:22:19 +00:00
|
|
|
return f'shuffle_0x{seed.hex()}_{count}', lambda: shuffling_case_fn(seed, count)
|
2019-04-10 15:52:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@to_tuple
|
2019-04-11 08:33:46 +00:00
|
|
|
def shuffling_test_cases():
|
2019-07-27 00:22:19 +00:00
|
|
|
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]:
|
2019-04-11 08:33:46 +00:00
|
|
|
yield shuffling_case(seed, count)
|
2019-04-10 15:52:51 +00:00
|
|
|
|
|
|
|
|
2019-07-27 00:22:19 +00:00
|
|
|
def create_provider(config_name: str) -> gen_typing.TestProvider:
|
2019-04-10 15:52:51 +00:00
|
|
|
|
2019-07-27 00:22:19 +00:00
|
|
|
def prepare_fn(configs_path: str) -> str:
|
2020-01-25 00:26:10 +00:00
|
|
|
config_util.prepare_config(configs_path, config_name)
|
|
|
|
reload(spec)
|
2019-07-27 00:22:19 +00:00
|
|
|
return config_name
|
2019-04-10 15:52:51 +00:00
|
|
|
|
2019-07-27 00:22:19 +00:00
|
|
|
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
|
|
|
|
)
|
2019-04-10 15:52:51 +00:00
|
|
|
|
2019-07-27 00:22:19 +00:00
|
|
|
return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
|
2019-04-10 15:52:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-07-27 00:22:19 +00:00
|
|
|
gen_runner.run_generator("shuffling", [create_provider("minimal"), create_provider("mainnet")])
|