Skip to content

Commit 4c6366a

Browse files
committed
add regression test for rust-bitcoin#806
When parsing a descriptor with `Descriptor::parse_descriptor`, we first parse as a string and then parse the keys. We fail to consider parsing errors in the keys, resulting in a panic. Also, clean up the panic message so it's clearer what's going on.
1 parent 4823d86 commit 4c6366a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/descriptor/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,4 +2049,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
20492049
Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err();
20502050
Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap();
20512051
}
2052+
2053+
#[test]
2054+
fn regression_806() {
2055+
let secp = secp256k1::Secp256k1::signing_only();
2056+
type Desc = Descriptor<DescriptorPublicKey>;
2057+
// OK
2058+
Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)")
2059+
.unwrap_err();
2060+
// ERR: crashes in translate_pk
2061+
Desc::parse_descriptor(
2062+
&secp,
2063+
"pkh(111111111111111111111111111111110000008375319363688624584A111111)",
2064+
)
2065+
.unwrap_err();
2066+
}
20522067
}

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,11 @@ impl<E> TranslateErr<E> {
350350
///
351351
/// This function will panic if the Error is OutError.
352352
pub fn expect_translator_err(self, msg: &str) -> E {
353-
if let Self::TranslatorErr(v) = self {
354-
v
355-
} else {
356-
panic!("{}", msg)
353+
match self {
354+
Self::TranslatorErr(v) => v,
355+
Self::OuterError(ref e) => {
356+
panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg)
357+
}
357358
}
358359
}
359360
}

0 commit comments

Comments
 (0)