Skip to content

Commit 44e0550

Browse files
committed
miniscript: add unit test for substitute_raw_pkh
1 parent e31d52b commit 44e0550

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/miniscript/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,12 @@ mod tests {
14311431
#[test]
14321432
fn expr_features() {
14331433
// test that parsing raw hash160 does not work with
1434-
let hash160_str = "e9f171df53e04b270fa6271b42f66b0f4a99c5a2";
1435-
let ms_str = &format!("c:expr_raw_pkh({})", hash160_str);
1434+
let pk = bitcoin::PublicKey::from_str(
1435+
"02c2fd50ceae468857bb7eb32ae9cd4083e6c7e42fbbec179d81134b3e3830586c",
1436+
)
1437+
.unwrap();
1438+
let hash160 = pk.pubkey_hash().to_raw_hash();
1439+
let ms_str = &format!("c:expr_raw_pkh({})", hash160);
14361440
type SegwitMs = Miniscript<bitcoin::PublicKey, Segwitv0>;
14371441

14381442
// Test that parsing raw hash160 from string does not work without extra features
@@ -1445,6 +1449,12 @@ mod tests {
14451449
SegwitMs::parse(&script).unwrap_err();
14461450
SegwitMs::parse_insane(&script).unwrap_err();
14471451
SegwitMs::parse_with_ext(&script, &ExtParams::allow_all()).unwrap();
1452+
1453+
// Try replacing the raw_pkh with a pkh
1454+
let mut map = BTreeMap::new();
1455+
map.insert(hash160, pk);
1456+
let ms_no_raw = ms.substitute_raw_pkh(&map);
1457+
assert_eq!(ms_no_raw.to_string(), format!("pkh({})", pk),);
14481458
}
14491459

14501460
#[test]

0 commit comments

Comments
 (0)