diff --git a/specs/test_formats/ssz_static/core.md b/specs/test_formats/ssz_static/core.md index 64b09a329..f24a225b0 100644 --- a/specs/test_formats/ssz_static/core.md +++ b/specs/test_formats/ssz_static/core.md @@ -9,11 +9,11 @@ This test-format ensures these direct serializations are covered. ## Test case format ```yaml -type_name: string -- string, object name, formatted as in spec. E.g. "BeaconBlock" -value: dynamic -- the YAML-encoded value, of the type specified by type_name. -serialized: bytes -- string, SSZ-serialized data, hex encoded, with prefix 0x -root: bytes32 -- string, hash-tree-root of the value, hex encoded, with prefix 0x -signing_root: bytes32 -- string, signing-root of the value, hex encoded, with prefix 0x. Optional, present if type contains ``signature`` field +SomeObjectName: -- key, object name, formatted as in spec. E.g. "BeaconBlock". + value: dynamic -- the YAML-encoded value, of the type specified by type_name. + serialized: bytes -- string, SSZ-serialized data, hex encoded, with prefix 0x + root: bytes32 -- string, hash-tree-root of the value, hex encoded, with prefix 0x + signing_root: bytes32 -- string, signing-root of the value, hex encoded, with prefix 0x. Optional, present if type contains ``signature`` field ``` ## Condition diff --git a/test_generators/ssz_static/main.py b/test_generators/ssz_static/main.py index 1234294db..e8995b918 100644 --- a/test_generators/ssz_static/main.py +++ b/test_generators/ssz_static/main.py @@ -18,10 +18,7 @@ MAX_LIST_LENGTH = 10 @to_dict -def create_test_case(rng: Random, name: str, 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) - yield "type_name", name +def create_test_case_contents(value, typ): yield "value", encode.encode(value, typ) yield "serialized", '0x' + serialize(value).hex() yield "root", '0x' + hash_tree_root(value).hex() @@ -29,6 +26,13 @@ def create_test_case(rng: Random, name: str, mode: random_value.RandomizationMod yield "signing_root", '0x' + signing_root(value).hex() +@to_dict +def create_test_case(rng: Random, name: str, 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) + yield name, create_test_case_contents(value, typ) + + @to_tuple def ssz_static_cases(rng: Random, mode: random_value.RandomizationMode, chaos: bool, count: int): for type_name in spec.ssz_types: