From 957be3c978368218508f424e21c5fa2c0714d7e1 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Mon, 10 Feb 2025 14:16:44 +0000 Subject: [PATCH] Add OutPoint test Cargo mutant found mutants in OutPoint. Add a test to kill them. --- primitives/src/transaction.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs index 9744a5ee0..b8d4bbcb6 100644 --- a/primitives/src/transaction.rs +++ b/primitives/src/transaction.rs @@ -643,4 +643,30 @@ mod tests { // Test partial ord assert!(tx > tx_orig); } + + #[test] + fn outpoint_from_str() { + // Check format errors + let mut outpoint_str = "0".repeat(64); // No ":" + let outpoint: Result = outpoint_str.parse(); + assert_eq!(outpoint, Err(ParseOutPointError::Format)); + + outpoint_str.push(':'); // Empty vout + let outpoint: Result = outpoint_str.parse(); + assert_eq!(outpoint, Err(ParseOutPointError::Format)); + + outpoint_str.push('0'); // Correct format + let outpoint: OutPoint = outpoint_str.parse().unwrap(); + assert_eq!(outpoint.txid, Txid::from_byte_array([0; 32])); + assert_eq!(outpoint.vout, 0); + + // Check the number of bytes OutPoint contributes to the transaction is equal to SIZE + let outpoint_size = outpoint.txid.as_byte_array().len() + outpoint.vout.to_le_bytes().len(); + assert_eq!(outpoint_size, OutPoint::SIZE); + + // Check TooLong error + outpoint_str.push_str("0000000000"); + let outpoint: Result = outpoint_str.parse(); + assert_eq!(outpoint, Err(ParseOutPointError::TooLong)); + } }