Helping macros and functions for creating test coverage for strict-encoded data.
Testing enum encoding
Enums having assigned primitive 8-bit values (i.e. u8
values) should be
tested with [test_encoding_enum_u8_exhaustive
], which is a macro
performing the most exhaustive testing.
If the enum primitive values are of non-u8
-type, then
[test_encoding_enum_by_values
] should be used. It does not performs
exhaustive tests, but covers tests comparing strict encoding with the actual
primitive value.
If the enum has no primitive values, has associated values (tuple- or
structure-based) or any enum variant defines custom
#[strict_encoding(value = ...)]
attribute, testing should be performed
with [test_encoding_enum
] macro.
Testing structures and unions
If you have an object which encoding you'd like to test, use
[test_object_encoding_roundtrip
] method.
If you have a byte string test vector representing some serialized object,
use [test_vec_decoding_roundtrip
] method.
If you have both an object and an independent test vector, representing its
serialization (which should not be obtained by just encoding the object),
use [test_encoding_roundtrip
] method.
General guidelines
Proper testing should not exercise asset
s and instead propagate errors
returned by test macros and methods to the return of the test case function
with ?
operator:
# extern crate strict_encoding_test;
use *;
;