Function strict_encoding_test::test_encoding_roundtrip
source · pub fn test_encoding_roundtrip<T, const MAX: usize>(
object: &T,
test_vec: Vec<u8>,
) -> Result<(), DataEncodingTestFailure<T>>
Expand description
Test helper performing double encode-decode roundtrip for an object
and a matching binary encoding test vector. Object type must be
PartialEq + Clone + Debug
.
§Error
Errors on:
- encoding or decoding failures;
- if the original object is not equivalent to its decoded version;
- if the original test vector is not equivalent to its transcoded version;
- if encoder returns number of bytes that does not match the length of the test vector.
§Panics
Function does not panics and instead returns DataEncodingTestFailure
for
each type of test failures.
§Example
ⓘ
#[derive(Clone, PartialEq, Eq, Debug, StrictEncode, StrictDecode)]
struct Data(pub Vec<u8>);
let data = Data(vec![0x01, 0x02]);
test_encoding_roundtrip(&data, &[0x02, 0x00, 0x01, 0x02]).unwrap();