Skip to content

Commit 63a0304

Browse files
committed
Add passing unit tests for read_scriptbool
In preparation for refactoring `read_scriptbool` add passing unit tests.
1 parent da3f3eb commit 63a0304

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/blockdata/script.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,5 +1448,23 @@ mod test {
14481448
assert!(instructions.next().is_none());
14491449
assert!(instructions.next().is_none());
14501450
}
1451+
1452+
#[test]
1453+
fn read_scriptbool_zero_is_false() {
1454+
let v: Vec<u8> = vec![0x00, 0x00, 0x00, 0x00];
1455+
assert!(!read_scriptbool(&v));
1456+
1457+
let v: Vec<u8> = vec![0x00, 0x00, 0x00, 0x80]; // With sign bit set.
1458+
assert!(!read_scriptbool(&v));
1459+
}
1460+
1461+
#[test]
1462+
fn read_scriptbool_non_zero_is_true() {
1463+
let v: Vec<u8> = vec![0x01, 0x00, 0x00, 0x00];
1464+
assert!(read_scriptbool(&v));
1465+
1466+
let v: Vec<u8> = vec![0x01, 0x00, 0x00, 0x80]; // With sign bit set.
1467+
assert!(read_scriptbool(&v));
1468+
}
14511469
}
14521470

0 commit comments

Comments
 (0)