From 44e05502cd23955c537e0f0e0cad9d28e0e24086 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Tue, 20 Aug 2024 16:55:02 +0000 Subject: [PATCH] miniscript: add unit test for substitute_raw_pkh --- src/miniscript/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index 7cb9d61e0..5a48d74a2 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -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; // Test that parsing raw hash160 from string does not work without extra features @@ -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]