2019-04-18 08:40:11 +00:00
|
|
|
# Test format: SSZ static types
|
|
|
|
|
2019-04-23 17:52:06 +00:00
|
|
|
The goal of this type is to provide clients with a solid reference for how the known SSZ objects should be encoded.
|
2019-05-06 15:30:32 +00:00
|
|
|
Each object described in the Phase 0 spec is covered.
|
2019-04-18 08:40:11 +00:00
|
|
|
This is important, as many of the clients aiming to serialize/deserialize objects directly into structs/classes
|
|
|
|
do not support (or have alternatives for) generic SSZ encoding/decoding.
|
2019-07-30 01:40:25 +00:00
|
|
|
|
2019-04-18 08:40:11 +00:00
|
|
|
This test-format ensures these direct serializations are covered.
|
|
|
|
|
2019-07-30 01:40:25 +00:00
|
|
|
Note that this test suite does not cover the invalid-encoding case:
|
|
|
|
SSZ implementations should be hardened against invalid inputs with the other SSZ tests as guide, along with fuzzing.
|
|
|
|
|
2019-04-18 08:40:11 +00:00
|
|
|
## Test case format
|
|
|
|
|
2019-07-30 01:40:25 +00:00
|
|
|
Each SSZ type is a `handler`, since the format is semantically different: the type of the data is different.
|
|
|
|
|
|
|
|
One can iterate over the handlers, and select the type based on the handler name.
|
|
|
|
Suites are then the same format, but each specialized in one randomization mode.
|
|
|
|
Some randomization modes may only produce a single test case (e.g. the all-zeroes case).
|
|
|
|
|
2019-08-01 20:03:40 +00:00
|
|
|
The output parts are: `roots.yaml`, `serialized.ssz`, `value.yaml`
|
2019-07-30 01:40:25 +00:00
|
|
|
|
2019-08-01 20:03:40 +00:00
|
|
|
### `roots.yaml`
|
2019-07-30 01:40:25 +00:00
|
|
|
|
2019-04-18 08:40:11 +00:00
|
|
|
```yaml
|
2019-07-30 01:40:25 +00:00
|
|
|
root: bytes32 -- string, hash-tree-root of the value, hex encoded, with prefix 0x
|
2019-04-18 08:40:11 +00:00
|
|
|
```
|
|
|
|
|
2019-07-30 01:40:25 +00:00
|
|
|
### `serialized.ssz`
|
|
|
|
|
|
|
|
The raw encoded bytes.
|
|
|
|
|
|
|
|
### `value.yaml`
|
|
|
|
|
|
|
|
The same value as `serialized.ssz`, represented as YAML.
|
|
|
|
|
|
|
|
|
2019-04-18 08:40:11 +00:00
|
|
|
## Condition
|
|
|
|
|
|
|
|
A test-runner can implement the following assertions:
|
2019-08-02 19:43:36 +00:00
|
|
|
- If YAML decoding of SSZ objects is supported by the implementation:
|
|
|
|
- Serialization: After parsing the `value`, SSZ-serialize it: the output should match `serialized`
|
|
|
|
- Deserialization: SSZ-deserialize the `serialized` value, and see if it matches the parsed `value`
|
|
|
|
- If YAML decoding of SSZ objects is not supported by the implementation:
|
|
|
|
- Serialization in 2 steps: deserialize `serialized`, then serialize the result,
|
|
|
|
and verify if the bytes match the original `serialized`.
|
2019-07-30 01:40:25 +00:00
|
|
|
- Hash-tree-root: After parsing the `value` (or deserializing `serialized`), Hash-tree-root it: the output should match `root`
|
2019-04-22 04:01:04 +00:00
|
|
|
|
|
|
|
|
2019-07-30 01:40:25 +00:00
|
|
|
## References
|
2019-04-22 04:01:04 +00:00
|
|
|
|
2020-01-10 18:42:55 +00:00
|
|
|
**`serialized`**—[SSZ serialization](../../../ssz/simple-serialize.md#serialization)
|
|
|
|
**`root`**—[hash_tree_root](../../../ssz/simple-serialize.md#merkleization) function
|