mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-18 22:51:13 +00:00
SSZ format update, to facilitate more efficient parsing
This commit is contained in:
parent
d036b5a87a
commit
3781614f20
@ -9,11 +9,11 @@ This test-format ensures these direct serializations are covered.
|
|||||||
## Test case format
|
## Test case format
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
type_name: string -- string, object name, formatted as in spec. E.g. "BeaconBlock"
|
SomeObjectName: -- key, object name, formatted as in spec. E.g. "BeaconBlock".
|
||||||
value: dynamic -- the YAML-encoded value, of the type specified by type_name.
|
value: dynamic -- the YAML-encoded value, of the type specified by type_name.
|
||||||
serialized: bytes -- string, SSZ-serialized data, hex encoded, with prefix 0x
|
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
|
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
|
signing_root: bytes32 -- string, signing-root of the value, hex encoded, with prefix 0x. Optional, present if type contains ``signature`` field
|
||||||
```
|
```
|
||||||
|
|
||||||
## Condition
|
## Condition
|
||||||
|
@ -18,10 +18,7 @@ MAX_LIST_LENGTH = 10
|
|||||||
|
|
||||||
|
|
||||||
@to_dict
|
@to_dict
|
||||||
def create_test_case(rng: Random, name: str, mode: random_value.RandomizationMode, chaos: bool):
|
def create_test_case_contents(value, typ):
|
||||||
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
|
|
||||||
yield "value", encode.encode(value, typ)
|
yield "value", encode.encode(value, typ)
|
||||||
yield "serialized", '0x' + serialize(value).hex()
|
yield "serialized", '0x' + serialize(value).hex()
|
||||||
yield "root", '0x' + hash_tree_root(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()
|
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
|
@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 type_name in spec.ssz_types:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user