Skip to content

Commit

Permalink
miniscript: add unit test for substitute_raw_pkh
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Aug 20, 2024
1 parent e31d52b commit 44e0550
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,12 @@ mod tests {
#[test]
fn expr_features() {
// test that parsing raw hash160 does not work with
let hash160_str = "e9f171df53e04b270fa6271b42f66b0f4a99c5a2";
let ms_str = &format!("c:expr_raw_pkh({})", hash160_str);
let pk = bitcoin::PublicKey::from_str(
"02c2fd50ceae468857bb7eb32ae9cd4083e6c7e42fbbec179d81134b3e3830586c",
)
.unwrap();
let hash160 = pk.pubkey_hash().to_raw_hash();
let ms_str = &format!("c:expr_raw_pkh({})", hash160);
type SegwitMs = Miniscript<bitcoin::PublicKey, Segwitv0>;

// Test that parsing raw hash160 from string does not work without extra features
Expand All @@ -1445,6 +1449,12 @@ mod tests {
SegwitMs::parse(&script).unwrap_err();
SegwitMs::parse_insane(&script).unwrap_err();
SegwitMs::parse_with_ext(&script, &ExtParams::allow_all()).unwrap();

// Try replacing the raw_pkh with a pkh
let mut map = BTreeMap::new();
map.insert(hash160, pk);
let ms_no_raw = ms.substitute_raw_pkh(&map);
assert_eq!(ms_no_raw.to_string(), format!("pkh({})", pk),);
}

#[test]
Expand Down

0 comments on commit 44e0550

Please sign in to comment.