Skip to content

Commit

Permalink
Add unit test for tapscript function
Browse files Browse the repository at this point in the history
Add a unit test that verifies we correctly remove the annex when getting
the tapscript from the witness stack.

Unit test written by Casey, pulled out of rust-bitcoin#3599.

Co-developed-by: Casey Rodarmor <[email protected]>
  • Loading branch information
tcharding committed Nov 12, 2024
1 parent 195615c commit 1ed3fc9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bitcoin/src/blockdata/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,26 @@ mod test {
assert_eq!(witness_annex.tapscript(), Some(Script::from_bytes(&tapscript[..])));
}

#[test]
fn test_get_tapscript_from_keypath() {
let signature = hex!("deadbeef");
// annex starting with 0x50 causes the branching logic.
let annex = hex!("50");

let witness_vec = vec![signature.clone()];
let witness_vec_annex = vec![signature.clone(), annex];

let witness_serialized: Vec<u8> = serialize(&witness_vec);
let witness_serialized_annex: Vec<u8> = serialize(&witness_vec_annex);

let witness = deserialize::<Witness>(&witness_serialized[..]).unwrap();
let witness_annex = deserialize::<Witness>(&witness_serialized_annex[..]).unwrap();

// With or without annex, no tapscript should be returned.
assert_eq!(witness.tapscript(), None);
assert_eq!(witness_annex.tapscript(), None);
}

#[test]
fn test_get_control_block() {
let tapscript = hex!("deadbeef");
Expand Down

0 comments on commit 1ed3fc9

Please sign in to comment.