What changed, and why it matters
This commit only adds new unit tests for the ScriptBuf type. It does not change any production code, fix bugs, or alter behavior. There is no security relevance.
No action required; this is a test-only change with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds three test cases to primitives/src/script/owned.rs: one verifying ScriptBuf::default() produces an empty script, one already-existing test for consensus decoding of an empty script, and a new test (decoder_full_read_limit) exercising the ScriptBuf decoder’s read_limit behavior as bytes are pushed. No library code is modified.
Changed components
primitives/src/script/owned.rs (tests only)Inspect captured patch +24 / −0
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index ffe68bc5..207e1c1a 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -282,6 +282,12 @@ mod tests {
assert!(script.capacity() >= 10);
}
+ #[test]
+ fn script_buf_default() {
+ let script: ScriptBuf = ScriptBuf::default();
+ assert!(script.is_empty());
+ }
+
#[test]
fn script_consensus_decode_empty() {
let bytes = vec![0_u8];
@@ -308,4 +314,22 @@ mod tests {
assert_eq!(got, want);
}
+
+ #[test]
+ fn decoder_full_read_limit() {
+ let mut decoder = ScriptBuf::decoder();
+ // ByteVecDecoder length prefix is CompactSize: needs 1 byte.
+ assert_eq!(decoder.read_limit(), 1);
+
+ // Script length prefix = 32.
+ let mut push = [32_u8].as_slice();
+ decoder.push_bytes(&mut push).unwrap();
+ // Limit is 32 for the script data.
+ assert_eq!(decoder.read_limit(), 32);
+
+ // Provide 1 byte of script data decreasing the read limit by 1.
+ let mut push = [0xAA_u8].as_slice();
+ decoder.push_bytes(&mut push).unwrap();
+ assert_eq!(decoder.read_limit(), 31);
+ }
}
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.