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.
This commit is contained in:
Jamil Lambert, PhD 2025-07-02 13:01:21 +01:00
parent ad40e69a85
commit a2bae3bb0b
No known key found for this signature in database
GPG Key ID: 54DC29234AB5D2C0
1 changed files with 15 additions and 0 deletions

View File

@ -802,6 +802,21 @@ mod tests {
assert!(!format!("{:?}", script).is_empty()); 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] #[test]
fn scriptbuf_display() { fn scriptbuf_display() {
let script_buf = ScriptBuf::from(vec![0x00, 0xa1, 0xb2]); let script_buf = ScriptBuf::from(vec![0x00, 0xa1, 0xb2]);