What changed, and why it matters
This commit only adds new unit tests for existing script types in the rust-bitcoin library. It does not change any production code, fix bugs, or alter behavior. There is no security relevance.
No action required; this is a routine test-only commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds four new test cases to primitives/src/script/tests.rs: one verifying tuple-based RangeBounds indexing on Script, and three verifying Display/Debug formatting for ScriptPubKey and ScriptPubKeyBuf. No library code is modified; only test coverage is expanded.
Changed components
primitives/src/script/tests.rsInspect captured patch +24 / −0
diff --git a/primitives/src/script/tests.rs b/primitives/src/script/tests.rs
index 2fe6495b..98f48d45 100644
--- a/primitives/src/script/tests.rs
+++ b/primitives/src/script/tests.rs
@@ -2,6 +2,7 @@
use alloc::string::ToString;
use alloc::{format, vec};
+use core::ops::Bound;
use encoding::{Decodable, Decoder as _};
use hashes::{hash160, sha256};
@@ -197,6 +198,13 @@ fn test_index() {
assert_eq!(script[..=2].as_bytes(), &[1, 2, 3]);
}
+#[test]
+fn test_index_bound_tuple() {
+ let script = Script::from_bytes(&[1, 2, 3, 4, 5]);
+
+ assert_eq!(script[(Bound::Included(1), Bound::Excluded(4))].as_bytes(), &[2, 3, 4]);
+}
+
#[test]
fn partial_ord() {
let script_small = Script::from_bytes(&[0x51, 0x52, 0x53]);
@@ -434,6 +442,14 @@ fn script_display() {
assert!(!format!("{:?}", script).is_empty());
}
+#[test]
+fn script_pubkey_display_and_debug() {
+ let script = ScriptPubKey::from_bytes(&[0x00, 0xa1, 0xb2]);
+
+ assert_eq!(format!("{}", script), "OP_0 OP_LESSTHANOREQUAL OP_CSV");
+ assert_eq!(format!("{:?}", script), "Script(OP_0 OP_LESSTHANOREQUAL OP_CSV)");
+}
+
#[test]
fn script_display_pushdata() {
// OP_PUSHDATA1
@@ -462,6 +478,14 @@ fn script_buf_display() {
assert!(!format!("{:?}", script_buf).is_empty());
}
+#[test]
+fn script_pubkey_buf_display_and_debug() {
+ let script_buf = ScriptPubKeyBuf::from(vec![0x00, 0xa1, 0xb2]);
+
+ assert_eq!(format!("{}", script_buf), "OP_0 OP_LESSTHANOREQUAL OP_CSV");
+ assert_eq!(format!("{:?}", script_buf), "Script(OP_0 OP_LESSTHANOREQUAL OP_CSV)");
+}
+
#[test]
fn encode() {
// Consensus encoding includes the length of the encoded data
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.