What changed, and why it matters
This commit simply moves an existing unit test from one file to another within the same project. It does not change any production code, fix a bug, or alter behavior. There is no security relevance.
No action needed; this is a routine test relocation with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch relocates the hex unit test from bitcoin/src/blockdata/script/tests.rs to primitives/src/script/tests.rs, adding a #[cfg(feature = "hex")] attribute because the destination crate requires it. The test body is otherwise identical. No library code is modified.
Changed components
Inspect captured patch +33 / −32
diff --git a/bitcoin/src/blockdata/script/tests.rs b/bitcoin/src/blockdata/script/tests.rs
index 954c6f97..b644417e 100644
--- a/bitcoin/src/blockdata/script/tests.rs
+++ b/bitcoin/src/blockdata/script/tests.rs
@@ -1079,35 +1079,3 @@ fn longest_witness_program() {
assert_eq!(script.witness_version(), Some(version));
}
-
-#[test]
-fn hex() {
- // This test is similar to code in `bitcoin/examples/script.rs` but without
- // touching the `bitcoin::consensus::encode` functions.
- use alloc::format;
-
- let consensus = "04deadbeef";
- let raw = "deadbeef";
-
- // Sanity check - positive case.
- let a = ScriptBuf::from_hex_prefixed(consensus).unwrap();
- let b = ScriptBuf::from_hex_no_length_prefix(raw).unwrap();
- assert_eq!(a, b);
-
- // Sanity check - negative case.
- assert!(ScriptBuf::from_hex_prefixed(raw).is_err()); // Nice API, this misuse fails.
- // But this just puts the length prefix in the script, ouch.
- assert!(ScriptBuf::from_hex_no_length_prefix(consensus).is_ok());
-
- let script = ScriptBuf::from_hex_prefixed(consensus).unwrap();
-
- let got = script.to_hex_string_prefixed();
- assert_eq!(got, consensus);
-
- let got = script.to_hex_string_no_length_prefix();
- assert_eq!(got, raw);
-
- // `LowerHex` is not consensus encoding, this may be surprising?
- let got = format!("{:x}", script);
- assert_eq!(got, raw);
-}
diff --git a/primitives/src/script/tests.rs b/primitives/src/script/tests.rs
index 19e3dd97..546599df 100644
--- a/primitives/src/script/tests.rs
+++ b/primitives/src/script/tests.rs
@@ -486,6 +486,39 @@ fn script_buf_to_hex() {
}
+#[test]
+#[cfg(feature = "hex")]
+fn hex() {
+ // This test is similar to code in `bitcoin/examples/script.rs` but without
+ // touching the `bitcoin::consensus::encode` functions.
+ use alloc::format;
+
+ let consensus = "04deadbeef";
+ let raw = "deadbeef";
+
+ // Sanity check - positive case.
+ let a = ScriptBuf::from_hex_prefixed(consensus).unwrap();
+ let b = ScriptBuf::from_hex_no_length_prefix(raw).unwrap();
+ assert_eq!(a, b);
+
+ // Sanity check - negative case.
+ assert!(ScriptBuf::from_hex_prefixed(raw).is_err()); // Nice API, this misuse fails.
+ // But this just puts the length prefix in the script, ouch.
+ assert!(ScriptBuf::from_hex_no_length_prefix(consensus).is_ok());
+
+ let script = ScriptBuf::from_hex_prefixed(consensus).unwrap();
+
+ let got = script.to_hex_string_prefixed();
+ assert_eq!(got, consensus);
+
+ let got = script.to_hex_string_no_length_prefix();
+ assert_eq!(got, raw);
+
+ // `LowerHex` is not consensus encoding, this may be surprising?
+ let got = format!("{:x}", script);
+ assert_eq!(got, raw);
+}
+
#[test]
fn script_consensus_decode_empty() {
let bytes = vec![0_u8];
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.