Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transparent tx serialization tests #54

Merged
4 commits merged into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions masp_primitives/src/transaction/components/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Authorized> {
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);
}
}
Loading