Skip to content

Commit b446ced

Browse files
committed
Add support for writing integration tests that fail
1 parent 0662d2e commit b446ced

File tree

2 files changed

+100
-45
lines changed

2 files changed

+100
-45
lines changed

tests/setup/test_util.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
2525
use bitcoin::secp256k1;
2626
use miniscript::descriptor::{SinglePub, SinglePubKey};
2727
use miniscript::{
28-
Descriptor, DescriptorPublicKey, Miniscript, ScriptContext, TranslatePk, Translator,
28+
Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext, TranslatePk, Translator,
2929
};
3030
use rand::RngCore;
3131

@@ -248,13 +248,15 @@ impl<'a> Translator<String, DescriptorPublicKey, ()> for StrTranslatorLoose<'a>
248248

249249
#[allow(dead_code)]
250250
// https://github.com/rust-lang/rust/issues/46379. The code is pub fn and integration test, but still shows warnings
251-
pub fn parse_test_desc(desc: &str, pubdata: &PubData) -> Descriptor<DescriptorPublicKey> {
251+
pub fn parse_test_desc(
252+
desc: &str,
253+
pubdata: &PubData,
254+
) -> Result<Descriptor<DescriptorPublicKey>, Error> {
252255
let desc = subs_hash_frag(desc, pubdata);
253-
let desc =
254-
Descriptor::<String>::from_str(&desc).expect("only parsing valid and sane descriptors");
256+
let desc = Descriptor::<String>::from_str(&desc)?;
255257
let mut translator = StrDescPubKeyTranslator(0, pubdata);
256258
let desc: Result<_, ()> = desc.translate_pk(&mut translator);
257-
desc.expect("Translate must succeed")
259+
Ok(desc.expect("Translate must succeed"))
258260
}
259261

260262
// substitute hash fragments in the string as the per rules

0 commit comments

Comments
 (0)