From a2bae3bb0b1598fdc7c5a47965c5b0481bd10fc8 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 2 Jul 2025 13:01:21 +0100 Subject: [PATCH 1/3] Add test for impl Display for Script Match arms in `impl fmt::Display for Script` were untested. Add a regression test for the `OP_PUSHDATAx` match arms. --- primitives/src/script/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs index 012b4f444..5a5e6b60e 100644 --- a/primitives/src/script/mod.rs +++ b/primitives/src/script/mod.rs @@ -802,6 +802,21 @@ mod tests { assert!(!format!("{:?}", script).is_empty()); } + #[test] + fn script_display_pushdata() { + // OP_PUSHDATA1 + let script = Script::from_bytes(&[0x4c, 0x02, 0xab, 0xcd]); + assert_eq!(format!("{}", script), "OP_PUSHDATA1 abcd"); + + // OP_PUSHDATA2 + let script = Script::from_bytes(&[0x4d, 0x02, 0x00, 0x12, 0x34]); + assert_eq!(format!("{}", script), "OP_PUSHDATA2 1234"); + + // OP_PUSHDATA4 + let script = Script::from_bytes(&[0x4e, 0x02, 0x00, 0x00, 0x00, 0x56, 0x78]); + assert_eq!(format!("{}", script), "OP_PUSHDATA4 5678"); + } + #[test] fn scriptbuf_display() { let script_buf = ScriptBuf::from(vec![0x00, 0xa1, 0xb2]); From 4d31b141a857e4c90a417cc5805105f160846842 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 2 Jul 2025 13:29:00 +0100 Subject: [PATCH 2/3] Improve is_too_precise test Two of the match arms in `is_too_precise` were untested. Expand the existing test to check all 4 cases. --- units/src/amount/tests.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/units/src/amount/tests.rs b/units/src/amount/tests.rs index 088497504..933ea5aa5 100644 --- a/units/src/amount/tests.rs +++ b/units/src/amount/tests.rs @@ -52,8 +52,14 @@ fn sanity_check() { #[test] fn check_if_num_is_too_precise() { - assert_eq!(is_too_precise("1234", 3).unwrap(), 3); - assert_eq!(is_too_precise("1234.1234", 3).unwrap(), 3); + // Has decimal, not too precise + assert_eq!(is_too_precise("1234.5678", 4), Some(0)); + // Has decimal, is too precise + assert_eq!(is_too_precise("1234.5678", 3), Some(3)); + // No decimal, not too precise + assert_eq!(is_too_precise("1234", 4), Some(0)); + // No decimal, is too precise + assert_eq!(is_too_precise("1234", 2), Some(3)); } #[test] From f0562504b7f758a439de60fe5fa76ad9ebfaba00 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 2 Jul 2025 13:34:29 +0100 Subject: [PATCH 3/3] Exclude deprecated fn from mutation testing Mutation testing generates mutants for deprecated functions `MedianTimePast::to_consensus_u32` and `Height::to_consensus_u32`. Add the functions to the mutation testing exclude list. --- .cargo/mutants.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.cargo/mutants.toml b/.cargo/mutants.toml index 70a1b8fd3..c2dc71d46 100644 --- a/.cargo/mutants.toml +++ b/.cargo/mutants.toml @@ -25,6 +25,8 @@ exclude_re = [ "SignedAmount::checked_abs", # Deprecated "NumberOfBlocks::value", # Deprecated "NumberOf512Seconds::to_consensus_u32", # Deprecated + "MedianTimePast::to_consensus_u32", # Deprecated + "Height::to_consensus_u32", # Deprecated # primitives "Sequence::from_512_second_intervals", # Mutant from replacing | with ^, this returns the same value since the XOR is taken against the u16 with an all-zero bitmask