Add unit tests for shortest/longest witness program

Add two unit tests that verify we can correctly determine if a
shortest allowed and longest allowed script is a witness program.

Done in preparation for patching the `witness_version` function.
This commit is contained in:
Tobin C. Harding 2024-03-22 07:03:30 +11:00
parent 6ff850539a
commit dac552b436
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 28 additions and 0 deletions

View File

@ -660,3 +660,31 @@ delegate_index!(
RangeToInclusive<usize>,
(Bound<usize>, Bound<usize>)
);
#[cfg(test)]
mod tests {
use super::*;
use crate::blockdata::script::witness_program::WitnessProgram;
#[test]
fn shortest_witness_program() {
let bytes = [0x00; 2]; // Arbitrary bytes, witprog must be between 2 and 40.
let version = WitnessVersion::V15; // Arbitrary version number, intentionally not 0 or 1.
let p = WitnessProgram::new(version, &bytes).expect("failed to create witness program");
let script = ScriptBuf::new_witness_program(&p);
assert_eq!(script.witness_version(), Some(version));
}
#[test]
fn longest_witness_program() {
let bytes = [0x00; 40]; // Arbitrary bytes, witprog must be between 2 and 40.
let version = WitnessVersion::V16; // Arbitrary version number, intentionally not 0 or 1.
let p = WitnessProgram::new(version, &bytes).expect("failed to create witness program");
let script = ScriptBuf::new_witness_program(&p);
assert_eq!(script.witness_version(), Some(version));
}
}