fix ssz-static generator

This commit is contained in:
protolambda 2019-06-11 18:30:50 +02:00
parent 22f624e12e
commit d6fd19ce44
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 13 additions and 6 deletions

View File

@ -1,7 +1,10 @@
from random import Random
from inspect import getmembers, isclass
from eth2spec.debug import random_value, encode
from eth2spec.phase0 import spec
from eth2spec.utils.ssz.ssz_typing import Container
from eth2spec.utils.ssz.ssz_impl import (
hash_tree_root,
signing_root,
@ -27,17 +30,23 @@ def create_test_case_contents(value, typ):
@to_dict
def create_test_case(rng: Random, name: str, mode: random_value.RandomizationMode, chaos: bool):
typ = spec.get_ssz_type_by_name(name)
def create_test_case(rng: Random, name: str, typ, mode: random_value.RandomizationMode, chaos: bool):
value = random_value.get_random_ssz_object(rng, typ, MAX_BYTES_LENGTH, MAX_LIST_LENGTH, mode, chaos)
yield name, create_test_case_contents(value, typ)
def get_spec_ssz_types():
return [
(name, value) for (name, value) in getmembers(spec, isclass)
if issubclass(value, Container) and value != Container # only the subclasses, not the imported base class
]
@to_tuple
def ssz_static_cases(rng: Random, mode: random_value.RandomizationMode, chaos: bool, count: int):
for type_name in spec.ssz_types:
for (name, ssz_type) in get_spec_ssz_types():
for i in range(count):
yield create_test_case(rng, type_name, mode, chaos)
yield create_test_case(rng, name, ssz_type, mode, chaos)
def get_ssz_suite(seed: int, config_name: str, mode: random_value.RandomizationMode, chaos: bool, cases_if_random: int):
@ -81,8 +90,6 @@ if __name__ == "__main__":
settings.append((seed, "mainnet", random_value.RandomizationMode.mode_random, False, 5))
seed += 1
print("Settings: %d, SSZ-types: %d" % (len(settings), len(spec.ssz_types)))
gen_runner.run_generator("ssz_static", [
get_ssz_suite(seed, config_name, mode, chaos, cases_if_random)
for (seed, config_name, mode, chaos, cases_if_random) in settings