Skip to content

Commit

Permalink
Improve script_x_only_key test.
Browse files Browse the repository at this point in the history
Co-authored-by: Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
  • Loading branch information
mplsgrant and dr-orlovsky committed Apr 1, 2022
1 parent 8a042dd commit 936ab1a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/blockdata/script.rs
Expand Up @@ -1124,16 +1124,13 @@ mod test {

#[test]
fn script_x_only_key() {
let mut comp = vec![];
let mut script = Builder::new();
assert_eq!(&script[..], &comp[..]);
// Notice the "20" which prepends the keystr. That 20 is hexidecimal for "32". The Builder automatically adds the 32 opcode
// to our script in order to give a heads up to the script compiler that it should add the next 32 bytes to the stack.
// To mimic the Builder's automatic insertion of the 32 opcode, we manually add it to the Vec and slice it out in the from_str.
// From: https://github.com/bitcoin-core/btcdeb/blob/e8c2750c4a4702768c52d15640ed03bf744d2601/doc/tapscript-example.md?plain=1#L43
let keystr = "209997a497d964fc1a62885b05a51166a65a90df00492c8d7cf61d6accf54803be";
let x_only_key = XOnlyPublicKey::from_str(&keystr[2..]).unwrap();
script = script.push_x_only_key(&x_only_key); comp.extend(Vec::from_hex(keystr).unwrap().iter().cloned()); assert_eq!(&script[..], &comp[..]);
let script = Builder::new().push_x_only_key(&x_only_key);
assert_eq!(&script[..], &Vec::from_hex(keystr).unwrap());
}

#[test]
Expand Down

0 comments on commit 936ab1a

Please sign in to comment.