From 0e90fc1db889fcc413cc1443e149eb54da75c14d Mon Sep 17 00:00:00 2001 From: joe <55120843+joebebel@users.noreply.github.com> Date: Wed, 30 Aug 2023 17:46:02 -0700 Subject: [PATCH] transparent tx serialization tests (#54) --- .../src/transaction/components/transparent.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/masp_primitives/src/transaction/components/transparent.rs b/masp_primitives/src/transaction/components/transparent.rs index daee2670..c06c1012 100644 --- a/masp_primitives/src/transaction/components/transparent.rs +++ b/masp_primitives/src/transaction/components/transparent.rs @@ -227,3 +227,41 @@ pub mod testing { } } } + +#[cfg(test)] +mod test_serialization { + use super::*; + + /// Simple test that a serialization round trip is the identity + #[test] + fn test_roundtrip_txin() { + let asset_type = AssetType::new_with_nonce(&[1, 2, 3, 4], 1).expect("Test failed"); + let txin = TxIn:: { + asset_type, + value: MAX_MONEY - 1, + address: TransparentAddress([12u8; 20]), + transparent_sig: (), + }; + + let mut buf = vec![]; + txin.write(&mut buf).expect("Test failed"); + let deserialized = TxIn::read::<&[u8]>(&mut buf.as_ref()).expect("Test failed"); + assert_eq!(deserialized, txin); + } + + /// Simple test that a serialization round trip is the identity + #[test] + fn test_roundtrip_txout() { + let asset_type = AssetType::new_with_nonce(&[1, 2, 3, 4], 1).expect("Test failed"); + let txout = TxOut { + asset_type, + value: MAX_MONEY - 1, + address: TransparentAddress([12u8; 20]), + }; + + let mut buf = vec![]; + txout.write(&mut buf).expect("Test failed"); + let deserialized = TxOut::read::<&[u8]>(&mut buf.as_ref()).expect("Test failed"); + assert_eq!(deserialized, txout); + } +}