Skip to content

Commit f97b239

Browse files
committed
Add support for writing integration tests that fail : src folder
1 parent 981a337 commit f97b239

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
332332
Descriptor::Wpkh(ref wpkh) => Ok(wpkh.address(network)),
333333
Descriptor::Wsh(ref wsh) => Ok(wsh.address(network)),
334334
Descriptor::Sh(ref sh) => Ok(sh.address(network)),
335-
Descriptor::Tr(ref tr) => Ok(tr.address(network)),
335+
Descriptor::Tr(ref tr) => Ok(tr.address(network)?),
336336
}
337337
}
338338

src/descriptor/tr.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
210210
/// If spend data is already computed (i.e it is not `None`), this does not recompute it.
211211
///
212212
/// [`TaprootSpendInfo`] is only required for spending via the script paths.
213-
pub fn spend_info(&self) -> Arc<TaprootSpendInfo>
213+
pub fn spend_info(&self) -> Result<Arc<TaprootSpendInfo>, Error>
214214
where
215215
Pk: ToPublicKey,
216216
{
217217
// If the value is already cache, read it
218218
// read only panics if the lock is poisoned (meaning other thread having a lock panicked)
219219
let read_lock = self.spend_info.lock().expect("Lock poisoned");
220220
if let Some(ref spend_info) = *read_lock {
221-
return Arc::clone(spend_info);
221+
return Ok(Arc::clone(spend_info));
222222
}
223223
drop(read_lock);
224224

@@ -232,9 +232,13 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
232232
let mut builder = TaprootBuilder::new();
233233
for (depth, ms) in self.iter_scripts() {
234234
let script = ms.encode();
235-
builder = builder
236-
.add_leaf(depth, script)
237-
.expect("Computing spend data on a valid Tree should always succeed");
235+
if let Ok(taproot_builder) = builder.add_leaf(depth, script) {
236+
builder = taproot_builder;
237+
} else {
238+
return Err(Error::Unexpected(String::from(
239+
"Computing spend data on a valid Tree should always succeed",
240+
)));
241+
}
238242
}
239243
// Assert builder cannot error here because we have a well formed descriptor
240244
match builder.finalize(&secp, self.internal_key.to_x_only_pubkey()) {
@@ -263,7 +267,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
263267
};
264268
let spend_info = Arc::new(data);
265269
*self.spend_info.lock().expect("Lock poisoned") = Some(Arc::clone(&spend_info));
266-
spend_info
270+
Ok(spend_info)
267271
}
268272

269273
/// Checks whether the descriptor is safe.
@@ -311,7 +315,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
311315
impl<Pk: MiniscriptKey + ToPublicKey> Tr<Pk> {
312316
/// Obtains the corresponding script pubkey for this descriptor.
313317
pub fn script_pubkey(&self) -> Script {
314-
let output_key = self.spend_info().output_key();
318+
let output_key = self.spend_info().unwrap().output_key();
315319
let builder = bitcoin::blockdata::script::Builder::new();
316320
builder
317321
.push_opcode(opcodes::all::OP_PUSHNUM_1)
@@ -320,9 +324,9 @@ impl<Pk: MiniscriptKey + ToPublicKey> Tr<Pk> {
320324
}
321325

322326
/// Obtains the corresponding address for this descriptor.
323-
pub fn address(&self, network: Network) -> Address {
324-
let spend_info = self.spend_info();
325-
Address::p2tr_tweaked(spend_info.output_key(), network)
327+
pub fn address(&self, network: Network) -> Result<Address, Error> {
328+
let spend_info = self.spend_info()?;
329+
Ok(Address::p2tr_tweaked(spend_info.output_key(), network))
326330
}
327331

328332
/// Returns satisfying non-malleable witness and scriptSig with minimum
@@ -630,7 +634,7 @@ where
630634
Pk: ToPublicKey,
631635
S: Satisfier<Pk>,
632636
{
633-
let spend_info = desc.spend_info();
637+
let spend_info = desc.spend_info().unwrap();
634638
// First try the key spend path
635639
if let Some(sig) = satisfier.lookup_tap_key_spend_sig() {
636640
Ok((vec![sig.to_vec()], Script::new()))

src/psbt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ fn update_input_with_descriptor_helper(
10121012

10131013
// NOTE: they will both always be Tr
10141014
if let (Descriptor::Tr(tr_derived), Descriptor::Tr(tr_xpk)) = (&derived, descriptor) {
1015-
let spend_info = tr_derived.spend_info();
1015+
let spend_info = tr_derived.spend_info().unwrap();
10161016
let ik_derived = spend_info.internal_key();
10171017
let ik_xpk = tr_xpk.internal_key();
10181018
input.tap_internal_key = Some(ik_derived);

0 commit comments

Comments
 (0)