make test gen output SSZ in addition to yaml files for SSZ objects

This commit is contained in:
protolambda 2019-07-30 00:40:01 +02:00
parent adb6bff365
commit eb7c3b9651
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,7 @@
from typing import Dict, Any
from eth2spec.debug.encode import encode
from eth2spec.utils.ssz.ssz_typing import SSZValue
from eth2spec.utils.ssz.ssz_impl import serialize
def vector_test(description: str = None):
@ -35,13 +36,22 @@ def vector_test(description: str = None):
continue
# Try to infer the type, but keep it as-is if it's not a SSZ type or bytes.
(key, value) = data
if isinstance(value, (SSZValue, bytes)):
if value is None:
continue
if isinstance(value, SSZValue):
yield key, 'data', encode(value)
# TODO: add SSZ bytes as second output
yield key, 'ssz', serialize(value)
elif isinstance(value, bytes):
yield key, 'data', encode(value)
yield key, 'ssz', value
elif isinstance(value, list) and all([isinstance(el, (SSZValue, bytes)) for el in value]):
for i, el in enumerate(value):
if isinstance(value, SSZValue):
yield f'{key}_{i}', 'data', encode(el)
# TODO: add SSZ bytes as second output
yield f'{key}_{i}', 'ssz', serialize(el)
elif isinstance(value, bytes):
yield f'{key}_{i}', 'data', encode(el)
yield f'{key}_{i}', 'ssz', el
yield f'{key}_count', 'meta', len(value)
else:
# Not a ssz value.