2019-11-21 22:13:45 +00:00
|
|
|
from eth2spec.utils.ssz.ssz_impl import serialize, hash_tree_root
|
2019-07-27 14:45:30 +00:00
|
|
|
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()
|
|
|
|
return case_fn
|
|
|
|
|
|
|
|
|
|
|
|
def invalid_test_case(bytez_fn: Callable[[], bytes]):
|
|
|
|
def case_fn():
|
|
|
|
yield "serialized", "ssz", bytez_fn()
|
|
|
|
return case_fn
|