pub fn test_vec_decoding_roundtrip<T, const MAX: usize>(
    test_vec: Vec<u8>
) -> Result<T, DataEncodingTestFailure<T>>
Expand description

Test helper performing decode-eecode roundtrip for a provided test vector byte string.

Returns

If suceeds, decoded object, which must have PartialEq + Clone + Debug type. Otheriwse, DataEncodingTestFailure (see description below)

Error

Errors on:

  • encoding or decoding failures;
  • 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]);
assert_eq!(test_vec_decoding_roundtrip(&[0x02, 0x00, 0x01, 0x02]), Ok(data));