22 lines
751 B
Python
22 lines
751 B
Python
from eth2spec.utils.ssz.ssz_impl import serialize, hash_tree_root, signing_root
|
|
from eth2spec.debug.encode import encode
|
|
from eth2spec.utils.ssz.ssz_typing import SSZValue, Container
|
|
from typing import Callable
|
|
|
|
|
|
def valid_test_case(value_fn: Callable[[], SSZValue]):
|
|
def case_fn():
|
|
value = value_fn()
|
|
yield "value", "data", encode(value)
|
|
yield "serialized", "ssz", serialize(value)
|
|
yield "root", "meta", '0x' + hash_tree_root(value).hex()
|
|
if isinstance(value, Container):
|
|
yield "signing_root", "meta", '0x' + signing_root(value).hex()
|
|
return case_fn
|
|
|
|
|
|
def invalid_test_case(bytez_fn: Callable[[], bytes]):
|
|
def case_fn():
|
|
yield "serialized", "ssz", bytez_fn()
|
|
return case_fn
|