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:
parent
6ff850539a
commit
dac552b436
|
@ -660,3 +660,31 @@ delegate_index!(
|
||||||
RangeToInclusive<usize>,
|
RangeToInclusive<usize>,
|
||||||
(Bound<usize>, Bound<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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue