eth2.0-specs/tests/generators/ssz_generic/ssz_test_case.py

20 lines
602 B
Python
Raw Normal View History

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 View
2019-07-27 14:45:30 +00:00
from typing import Callable
def valid_test_case(value_fn: Callable[[], View]):
2019-07-27 14:45:30 +00:00
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