Merge pull request #3383 from ethereum/fix-pickle
Fix shuffling testgen when multiprocessing
This commit is contained in:
commit
ce5a9fad66
|
@ -1,5 +1,5 @@
|
||||||
from eth_utils import to_tuple
|
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
import random
|
||||||
|
|
||||||
from eth2spec.gen_helpers.gen_base import gen_runner, gen_typing
|
from eth2spec.gen_helpers.gen_base import gen_runner, gen_typing
|
||||||
from eth2spec.test.helpers.typing import PresetBaseName
|
from eth2spec.test.helpers.typing import PresetBaseName
|
||||||
|
@ -8,6 +8,16 @@ from eth2spec.phase0 import mainnet as spec_mainnet, minimal as spec_minimal
|
||||||
from eth2spec.test.helpers.constants import PHASE0, MINIMAL, MAINNET
|
from eth2spec.test.helpers.constants import PHASE0, MINIMAL, MAINNET
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_bytes(rng=random.Random(5566)):
|
||||||
|
random_bytes = bytes(rng.randint(0, 255) for _ in range(32))
|
||||||
|
return random_bytes
|
||||||
|
|
||||||
|
|
||||||
|
# NOTE: somehow the random.Random generated seeds do not have pickle issue.
|
||||||
|
rng = random.Random(1234)
|
||||||
|
seeds = [generate_random_bytes(rng) for i in range(30)]
|
||||||
|
|
||||||
|
|
||||||
def shuffling_case_fn(spec, seed, count):
|
def shuffling_case_fn(spec, seed, count):
|
||||||
yield 'mapping', 'data', {
|
yield 'mapping', 'data', {
|
||||||
'seed': '0x' + seed.hex(),
|
'seed': '0x' + seed.hex(),
|
||||||
|
@ -20,9 +30,8 @@ def shuffling_case(spec, seed, count):
|
||||||
return f'shuffle_0x{seed.hex()}_{count}', lambda: shuffling_case_fn(spec, seed, count)
|
return f'shuffle_0x{seed.hex()}_{count}', lambda: shuffling_case_fn(spec, seed, count)
|
||||||
|
|
||||||
|
|
||||||
@to_tuple
|
|
||||||
def shuffling_test_cases(spec):
|
def shuffling_test_cases(spec):
|
||||||
for seed in [spec.hash(seed_init_value.to_bytes(length=4, byteorder='little')) for seed_init_value in range(30)]:
|
for seed in seeds:
|
||||||
for count in [0, 1, 2, 3, 5, 10, 33, 100, 1000, 9999]:
|
for count in [0, 1, 2, 3, 5, 10, 33, 100, 1000, 9999]:
|
||||||
yield shuffling_case(spec, seed, count)
|
yield shuffling_case(spec, seed, count)
|
||||||
|
|
||||||
|
@ -47,11 +56,13 @@ def create_provider(preset_name: PresetBaseName) -> gen_typing.TestProvider:
|
||||||
handler_name='core',
|
handler_name='core',
|
||||||
suite_name='shuffle',
|
suite_name='shuffle',
|
||||||
case_name=case_name,
|
case_name=case_name,
|
||||||
case_fn=case_fn
|
case_fn=case_fn,
|
||||||
)
|
)
|
||||||
|
|
||||||
return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
|
return gen_typing.TestProvider(prepare=prepare_fn, make_cases=cases_fn)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
gen_runner.run_generator("shuffling", [create_provider(MINIMAL), create_provider(MAINNET)])
|
gen_runner.run_generator("shuffling", [
|
||||||
|
create_provider(MINIMAL), create_provider(MAINNET)]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue