From f3338655f153834395ff2486a8f965df4453ceeb Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Thu, 19 Jun 2025 17:14:16 +0100 Subject: [PATCH] Test OutPoint edge case to kill mutant There is a mutant found in `FromStr for OutPoint`. Add a test to check an edge case to kill the mutant. --- primitives/src/transaction.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs index ef322e62b..6dec85fa6 100644 --- a/primitives/src/transaction.rs +++ b/primitives/src/transaction.rs @@ -729,9 +729,20 @@ mod tests { // 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"); + #[test] + #[cfg(feature = "hex")] + fn outpoint_from_str_too_long() { + // Check edge case: length exactly 75 + let mut outpoint_str = "0".repeat(64); + outpoint_str.push_str(":1234567890"); + assert_eq!(outpoint_str.len(), 75); + assert!(outpoint_str.parse::().is_ok()); + + // Check TooLong error (length 76) + outpoint_str.push('0'); + assert_eq!(outpoint_str.len(), 76); let outpoint: Result = outpoint_str.parse(); assert_eq!(outpoint, Err(ParseOutPointError::TooLong)); }