fix ssz-static generator
This commit is contained in:
parent
22f624e12e
commit
d6fd19ce44
|
@ -1,7 +1,10 @@
|
||||||
from random import Random
|
from random import Random
|
||||||
|
|
||||||
|
from inspect import getmembers, isclass
|
||||||
|
|
||||||
from eth2spec.debug import random_value, encode
|
from eth2spec.debug import random_value, encode
|
||||||
from eth2spec.phase0 import spec
|
from eth2spec.phase0 import spec
|
||||||
|
from eth2spec.utils.ssz.ssz_typing import Container
|
||||||
from eth2spec.utils.ssz.ssz_impl import (
|
from eth2spec.utils.ssz.ssz_impl import (
|
||||||
hash_tree_root,
|
hash_tree_root,
|
||||||
signing_root,
|
signing_root,
|
||||||
|
@ -27,17 +30,23 @@ def create_test_case_contents(value, typ):
|
||||||
|
|
||||||
|
|
||||||
@to_dict
|
@to_dict
|
||||||
def create_test_case(rng: Random, name: str, mode: random_value.RandomizationMode, chaos: bool):
|
def create_test_case(rng: Random, name: str, typ, mode: random_value.RandomizationMode, chaos: bool):
|
||||||
typ = spec.get_ssz_type_by_name(name)
|
|
||||||
value = random_value.get_random_ssz_object(rng, typ, MAX_BYTES_LENGTH, MAX_LIST_LENGTH, mode, chaos)
|
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)
|
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
|
@to_tuple
|
||||||
def ssz_static_cases(rng: Random, mode: random_value.RandomizationMode, chaos: bool, count: int):
|
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):
|
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):
|
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))
|
settings.append((seed, "mainnet", random_value.RandomizationMode.mode_random, False, 5))
|
||||||
seed += 1
|
seed += 1
|
||||||
|
|
||||||
print("Settings: %d, SSZ-types: %d" % (len(settings), len(spec.ssz_types)))
|
|
||||||
|
|
||||||
gen_runner.run_generator("ssz_static", [
|
gen_runner.run_generator("ssz_static", [
|
||||||
get_ssz_suite(seed, config_name, mode, chaos, cases_if_random)
|
get_ssz_suite(seed, config_name, mode, chaos, cases_if_random)
|
||||||
for (seed, config_name, mode, chaos, cases_if_random) in settings
|
for (seed, config_name, mode, chaos, cases_if_random) in settings
|
||||||
|
|
Loading…
Reference in New Issue