Skip to content

Add support for writing integration tests that fail #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tests/setup/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
use bitcoin::secp256k1;
use miniscript::descriptor::{SinglePub, SinglePubKey};
use miniscript::{
Descriptor, DescriptorPublicKey, Miniscript, ScriptContext, TranslatePk, Translator,
Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext, TranslatePk, Translator,
};
use rand::RngCore;

#[derive(Clone, Debug)]
pub struct PubData {
pub pks: Vec<bitcoin::PublicKey>,
Expand Down Expand Up @@ -248,13 +247,15 @@ impl<'a> Translator<String, DescriptorPublicKey, ()> for StrTranslatorLoose<'a>

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

// substitute hash fragments in the string as the per rules
Expand Down
Loading