pub fn test_object_encoding_roundtrip<T, const MAX: usize>(
    object: &T
) -> Result<Vec<u8>, DataEncodingTestFailure<T>>
Expand description

Test helper performing encode-decode roundtrip for a provided object. Object type must be PartialEq + Clone + Debug.

Returns

If suceeds, encoded byte string representing the object. Otheriwse, DataEncodingTestFailure (see description below)

Error

Errors on:

  • encoding or decoding failures;
  • if the original object is not equivalent to its decoded version;
  • if encoder returns number of bytes that does not match the length of the encoded data.

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_object_encoding_roundtrip(&data).unwrap().len(), 4);