fix ssz container recognition for generators

This commit is contained in:
protolambda 2019-06-11 16:42:50 +02:00
parent 94d4e3a944
commit 46d8422510
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 6 additions and 1 deletions

View File

@ -1,5 +1,6 @@
from typing import Dict, Any, Callable, Iterable
from eth2spec.debug.encode import encode
from eth2spec.utils.ssz.ssz_typing import Container
def spectest(description: str = None):
@ -30,9 +31,13 @@ def spectest(description: str = None):
else:
# Otherwise, try to infer the type, but keep it as-is if it's not a SSZ container.
(key, value) = data
if hasattr(value.__class__, 'fields'):
if isinstance(value, Container):
out[key] = encode(value, value.__class__)
else:
# not a ssz value.
# It could be vector or bytes still, but it is a rare case,
# and lists can't be inferred fully (generics lose element type).
# In such cases, explicitly state the type of the yielded value as a third yielded object.
out[key] = value
if has_contents:
return out