Skip to content

Commit a79be4f

Browse files
committed
Add support for writing integration tests that fail : integration_test folder
1 parent c1bba6f commit a79be4f

File tree

5 files changed

+125
-65
lines changed

5 files changed

+125
-65
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fuzz/hfuzz_workspace
1717

1818
#Vscode project files
1919
.vscode
20+
.metals
2021

2122
#Intergration test files
22-
integration_test/bitcoin-*
23+
integration_test/bitcoin-*

integration_test/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ sleep 3
3131

3232
RPC_URL=http://localhost:12348 \
3333
RPC_COOKIE=${TESTDIR}/1/regtest/.cookie \
34+
RUST_BACKTRACE=1 \
3435
cargo run
3536

3637
RESULT=$?

integration_test/src/main.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,30 @@ fn test_descs(cl: &Client, testdata: &TestData) {
7373
// X!: X-only key with corresponding secret key unknown
7474

7575
// Test 1: Simple spend with internal key
76-
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X)");
76+
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X)").unwrap();
7777
assert!(wit.len() == 1);
7878

7979
// Test 2: Same as above, but with leaves
80-
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X,{pk(X1!),pk(X2!)})");
80+
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X,{pk(X1!),pk(X2!)})").unwrap();
8181
assert!(wit.len() == 1);
8282

8383
// Test 3: Force to spend with script spend. Unknown internal key and only one known script path
8484
// X! -> Internal key unknown
8585
// Leaf 1 -> pk(X1) with X1 known
8686
// Leaf 2-> and_v(v:pk(X2),pk(X3!)) with partial witness only to X2 known
87-
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1),and_v(v:pk(X2),pk(X3!))})");
87+
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1),and_v(v:pk(X2),pk(X3!))})").unwrap();
8888
assert!(wit.len() == 3); // control block, script and signature
8989

9090
// Test 4: Force to spend with script spend. Unknown internal key and multiple script paths
9191
// Should select the one with minimum weight
9292
// X! -> Internal key unknown
9393
// Leaf 1 -> pk(X1!) with X1 unknown
9494
// Leaf 2-> and_v(v:pk(X2),pk(X3)) X2 and X3 known
95-
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1),and_v(v:pk(X2),pk(X3))})");
95+
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1),and_v(v:pk(X2),pk(X3))})").unwrap();
9696
assert!(wit.len() == 3); // control block, script and one signatures
9797

9898
// Test 5: When everything is available, we should select the key spend path
99-
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X,{pk(X1),and_v(v:pk(X2),pk(X3!))})");
99+
let wit = test_desc::test_desc_satisfy(cl, testdata, "tr(X,{pk(X1),and_v(v:pk(X2),pk(X3!))})").unwrap();
100100
assert!(wit.len() == 1); // control block, script and signature
101101

102102
// Test 6: Test the new multi_a opcodes
@@ -110,10 +110,38 @@ fn test_descs(cl: &Client, testdata: &TestData) {
110110

111111
// Test 8: Test script tree of depth 128 is valid, only X129 is known
112112
test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1!),{pk(X2!),{pk(X3!),{pk(X4!),{pk(X5!),{pk(X6!),{pk(X7!),{pk(X8!),{pk(X9!),{pk(X10!),{pk(X11!),{pk(X12!),{pk(X13!),{pk(X14!),{pk(X15!),{pk(X16!),{pk(X17!),{pk(X18!),{pk(X19!),{pk(X20!),{pk(X21!),{pk(X22!),{pk(X23!),{pk(X24!),{pk(X25!),{pk(X26!),{pk(X27!),{pk(X28!),{pk(X29!),{pk(X30!),{pk(X31!),{pk(X32!),{pk(X33!),{pk(X34!),{pk(X35!),{pk(X36!),{pk(X37!),{pk(X38!),{pk(X39!),{pk(X40!),{pk(X41!),{pk(X42!),{pk(X43!),{pk(X44!),{pk(X45!),{pk(X46!),{pk(X47!),{pk(X48!),{pk(X49!),{pk(X50!),{pk(X51!),{pk(X52!),{pk(X53!),{pk(X54!),{pk(X55!),{pk(X56!),{pk(X57!),{pk(X58!),{pk(X59!),{pk(X60!),{pk(X61!),{pk(X62!),{pk(X63!),{pk(X64!),{pk(X65!),{pk(X66!),{pk(X67!),{pk(X68!),{pk(X69!),{pk(X70!),{pk(X71!),{pk(X72!),{pk(X73!),{pk(X74!),{pk(X75!),{pk(X76!),{pk(X77!),{pk(X78!),{pk(X79!),{pk(X80!),{pk(X81!),{pk(X82!),{pk(X83!),{pk(X84!),{pk(X85!),{pk(X86!),{pk(X87!),{pk(X88!),{pk(X89!),{pk(X90!),{pk(X91!),{pk(X92!),{pk(X93!),{pk(X94!),{pk(X95!),{pk(X96!),{pk(X97!),{pk(X98!),{pk(X99!),{pk(X100!),{pk(X101!),{pk(X102!),{pk(X103!),{pk(X104!),{pk(X105!),{pk(X106!),{pk(X107!),{pk(X108!),{pk(X109!),{pk(X110!),{pk(X111!),{pk(X112!),{pk(X113!),{pk(X114!),{pk(X115!),{pk(X116!),{pk(X117!),{pk(X118!),{pk(X119!),{pk(X120!),{pk(X121!),{pk(X122!),{pk(X123!),{pk(X124!),{pk(X125!),{pk(X126!),{pk(X127!),{pk(X128!),pk(X129)}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}})");
113-
113+
114114
// Test 9: Test script complete tree having 128 leaves with depth log(128), only X1 is known
115115
test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{{{{{{{pk(X1),pk(X2!)},{pk(X3!),pk(X4!)}},{{pk(X5!),pk(X6!)},{pk(X7!),pk(X8!)}}},{{{pk(X9!),pk(X10!)},{pk(X11!),pk(X12!)}},{{pk(X13!),pk(X14!)},{pk(X15!),pk(X16!)}}}},{{{{pk(X17!),pk(X18!)},{pk(X19!),pk(X20!)}},{{pk(X21!),pk(X22!)},{pk(X23!),pk(X24!)}}},{{{pk(X25!),pk(X26!)},{pk(X27!),pk(X28!)}},{{pk(X29!),pk(X30!)},{pk(X31!),pk(X32!)}}}}},{{{{{pk(X33!),pk(X34!)},{pk(X35!),pk(X36!)}},{{pk(X37!),pk(X38!)},{pk(X39!),pk(X40!)}}},{{{pk(X41!),pk(X42!)},{pk(X43!),pk(X44!)}},{{pk(X45!),pk(X46!)},{pk(X47!),pk(X48!)}}}},{{{{pk(X49!),pk(X50!)},{pk(X51!),pk(X52!)}},{{pk(X53!),pk(X54!)},{pk(X55!),pk(X56!)}}},{{{pk(X57!),pk(X58!)},{pk(X59!),pk(X60!)}},{{pk(X61!),pk(X62!)},{pk(X63!),pk(X64!)}}}}}},{{{{{{pk(X65!),pk(X66!)},{pk(X67!),pk(X68!)}},{{pk(X69!),pk(X70!)},{pk(X71!),pk(X72!)}}},{{{pk(X73!),pk(X74!)},{pk(X75!),pk(X76!)}},{{pk(X77!),pk(X78!)},{pk(X79!),pk(X80!)}}}},{{{{pk(X81!),pk(X82!)},{pk(X83!),pk(X84!)}},{{pk(X85!),pk(X86!)},{pk(X87!),pk(X88!)}}},{{{pk(X89!),pk(X90!)},{pk(X91!),pk(X92!)}},{{pk(X93!),pk(X94!)},{pk(X95!),pk(X96!)}}}}},{{{{{pk(X97!),pk(X98!)},{pk(X99!),pk(X100!)}},{{pk(X101!),pk(X102!)},{pk(X103!),pk(X104!)}}},{{{pk(X105!),pk(X106!)},{pk(X107!),pk(X108!)}},{{pk(X109!),pk(X110!)},{pk(X111!),pk(X112!)}}}},{{{{pk(X113!),pk(X114!)},{pk(X115!),pk(X116!)}},{{pk(X117!),pk(X118!)},{pk(X119!),pk(X120!)}}},{{{pk(X121!),pk(X122!)},{pk(X123!),pk(X124!)}},{{pk(X125!),pk(X126!)},{pk(X127!),pk(X128!)}}}}}}})");
116116

117+
// Test 10: Test taproot desc with ZERO known keys
118+
let result = test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1!),pk(X2!)})");
119+
match result {
120+
Ok(wit) => (),
121+
Err(error) => println!("taproot desc with ZERO known keys : {}", error)
122+
}
123+
124+
// Test 11: Test taproot with insufficient known keys
125+
let result = test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1!),multi_a(3,X2!,X3,X4)})");
126+
match result {
127+
Ok(wit) => (),
128+
Err(error) => println!("taproot desc with insufficient known keys : {}", error)
129+
}
130+
131+
// Test 12: size exceeds the limit
132+
let result = test_desc::test_desc_satisfy(cl, testdata, "wsh(thresh(1,pk(K1),a:pk(K2),a:pk(K3),a:pk(K4),a:pk(K5),a:pk(K6),a:pk(K7),a:pk(K8),a:pk(K9),a:pk(K10),a:pk(K11),a:pk(K12),a:pk(K13),a:pk(K14),a:pk(K15),a:pk(K16),a:pk(K17),a:pk(K18),a:pk(K19),a:pk(K20),a:pk(K21),a:pk(K22),a:pk(K23),a:pk(K24),a:pk(K25),a:pk(K26),a:pk(K27),a:pk(K28),a:pk(K29),a:pk(K30),a:pk(K31),a:pk(K32),a:pk(K33),a:pk(K34),a:pk(K35),a:pk(K36),a:pk(K37),a:pk(K38),a:pk(K39),a:pk(K40),a:pk(K41),a:pk(K42),a:pk(K43),a:pk(K44),a:pk(K45),a:pk(K46),a:pk(K47),a:pk(K48),a:pk(K49),a:pk(K50),a:pk(K51),a:pk(K52),a:pk(K53),a:pk(K54),a:pk(K55),a:pk(K56),a:pk(K57),a:pk(K58),a:pk(K59),a:pk(K60),a:pk(K61),a:pk(K62),a:pk(K63),a:pk(K64),a:pk(K65),a:pk(K66),a:pk(K67),a:pk(K68),a:pk(K69),a:pk(K70),a:pk(K71),a:pk(K72),a:pk(K73),a:pk(K74),a:pk(K75),a:pk(K76),a:pk(K77),a:pk(K78),a:pk(K79),a:pk(K80),a:pk(K81),a:pk(K82),a:pk(K83),a:pk(K84),a:pk(K85),a:pk(K86),a:pk(K87),a:pk(K88),a:pk(K89),a:pk(K90),a:pk(K91),a:pk(K92),a:pk(K93),a:pk(K94),a:pk(K95),a:pk(K96),a:pk(K97),a:pk(K98),a:pk(K99),a:pk(K100)))");
133+
match result {
134+
Ok(wit) => (),
135+
Err(error) => println!("Witness script size exceeds 3600 bytes : {}", error)
136+
}
137+
138+
// Test 13: Test script tree of depth > 128 is invalid
139+
let result = test_desc::test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1!),{pk(X2!),{pk(X3!),{pk(X4!),{pk(X5!),{pk(X6!),{pk(X7!),{pk(X8!),{pk(X9!),{pk(X10!),{pk(X11!),{pk(X12!),{pk(X13!),{pk(X14!),{pk(X15!),{pk(X16!),{pk(X17!),{pk(X18!),{pk(X19!),{pk(X20!),{pk(X21!),{pk(X22!),{pk(X23!),{pk(X24!),{pk(X25!),{pk(X26!),{pk(X27!),{pk(X28!),{pk(X29!),{pk(X30!),{pk(X31!),{pk(X32!),{pk(X33!),{pk(X34!),{pk(X35!),{pk(X36!),{pk(X37!),{pk(X38!),{pk(X39!),{pk(X40!),{pk(X41!),{pk(X42!),{pk(X43!),{pk(X44!),{pk(X45!),{pk(X46!),{pk(X47!),{pk(X48!),{pk(X49!),{pk(X50!),{pk(X51!),{pk(X52!),{pk(X53!),{pk(X54!),{pk(X55!),{pk(X56!),{pk(X57!),{pk(X58!),{pk(X59!),{pk(X60!),{pk(X61!),{pk(X62!),{pk(X63!),{pk(X64!),{pk(X65!),{pk(X66!),{pk(X67!),{pk(X68!),{pk(X69!),{pk(X70!),{pk(X71!),{pk(X72!),{pk(X73!),{pk(X74!),{pk(X75!),{pk(X76!),{pk(X77!),{pk(X78!),{pk(X79!),{pk(X80!),{pk(X81!),{pk(X82!),{pk(X83!),{pk(X84!),{pk(X85!),{pk(X86!),{pk(X87!),{pk(X88!),{pk(X89!),{pk(X90!),{pk(X91!),{pk(X92!),{pk(X93!),{pk(X94!),{pk(X95!),{pk(X96!),{pk(X97!),{pk(X98!),{pk(X99!),{pk(X100!),{pk(X101!),{pk(X102!),{pk(X103!),{pk(X104!),{pk(X105!),{pk(X106!),{pk(X107!),{pk(X108!),{pk(X109!),{pk(X110!),{pk(X111!),{pk(X112!),{pk(X113!),{pk(X114!),{pk(X115!),{pk(X116!),{pk(X117!),{pk(X118!),{pk(X119!),{pk(X120!),{pk(X121!),{pk(X122!),{pk(X123!),{pk(X124!),{pk(X125!),{pk(X126!),{pk(X127!),{pk(X128!),{pk(X129!),pk(X130)}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}})");
140+
match result {
141+
Ok(wit) => (),
142+
Err(error) => println!("script tree is having depth 129 and hence it is invalid : {}", error)
143+
}
144+
117145
// Misc tests for other descriptors that we support
118146
// Keys
119147
test_desc::test_desc_satisfy(cl, testdata, "wpkh(K)");

integration_test/src/test_desc.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use miniscript::psbt::{PsbtExt, PsbtInputExt};
1717
use miniscript::{Descriptor, Miniscript, ToPublicKey};
1818
use miniscript::{MiniscriptKey, ScriptContext};
1919
use std::collections::BTreeMap;
20+
use std::error;
21+
use std::fmt;
22+
use miniscript::Error;
2023

2124
use crate::test_util::{self, TestData};
2225

@@ -40,7 +43,27 @@ fn get_vout(cl: &Client, txid: Txid, value: u64, spk: Script) -> (OutPoint, TxOu
4043
unreachable!("Only call get vout on functions which have the expected outpoint");
4144
}
4245

43-
pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witness {
46+
// Currently this is not being used, since miniscript::Error is being propagated
47+
// But if the types of errors grow in future, we can extend this enum and use it.
48+
#[derive(Debug, PartialEq)]
49+
pub enum MalleableDescError {
50+
/// PSBT was not able to finalize
51+
PsbtFinalizeError,
52+
}
53+
54+
impl fmt::Display for MalleableDescError{
55+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56+
match *self {
57+
MalleableDescError::PsbtFinalizeError => {
58+
f.write_str("PSBT was not able to finalize")
59+
}
60+
}
61+
}
62+
}
63+
64+
impl error::Error for MalleableDescError {}
65+
66+
pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Result<Witness, Error> {
4467
let secp = secp256k1::Secp256k1::new();
4568
let sks = &testdata.secretdata.sks;
4669
let xonly_keypairs = &testdata.secretdata.x_only_keypairs;
@@ -52,12 +75,12 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witnes
5275
.unwrap();
5376
assert_eq!(blocks.len(), 1);
5477

55-
let desc = test_util::parse_test_desc(&desc, &testdata.pubdata);
78+
let desc = test_util::parse_test_desc(&desc, &testdata.pubdata)?;
5679
let derived_desc = desc.derived_descriptor(&secp, 0).unwrap();
5780
// Next send some btc to each address corresponding to the miniscript
5881
let txid = cl
5982
.send_to_address(
60-
&derived_desc.address(bitcoin::Network::Regtest).unwrap(),
83+
&derived_desc.address(bitcoin::Network::Regtest)?,
6184
btc(1),
6285
None,
6386
None,
@@ -137,7 +160,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witnes
137160
if let Some(mut internal_keypair) = internal_keypair {
138161
// ---------------------- Tr key spend --------------------
139162
internal_keypair
140-
.tweak_add_assign(&secp, tr.spend_info().tap_tweak().as_ref())
163+
.tweak_add_assign(&secp, tr.spend_info().unwrap().tap_tweak().as_ref())
141164
.expect("Tweaking failed");
142165
let sighash_msg = sighash_cache
143166
.taproot_key_spend_signature_hash(0, &prevouts, hash_ty)
@@ -266,11 +289,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witnes
266289
// Finalize the transaction using psbt
267290
// Let miniscript do it's magic!
268291
if let Err(e) = psbt.finalize_mut(&secp) {
269-
// All miniscripts should satisfy
270-
panic!(
271-
"Could not satisfy non-malleably: error{} desc:{} ",
272-
e[0], desc
273-
);
292+
return Err(Error::Unexpected(String::from("PSBT was not able to finalize")));
274293
}
275294
let tx = psbt.extract(&secp).expect("Extraction error");
276295

@@ -290,7 +309,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witnes
290309
// Assert that the confirmations are > 0.
291310
let num_conf = cl.get_transaction(&txid, None).unwrap().info.confirmations;
292311
assert!(num_conf > 0);
293-
tx.input[0].witness.clone()
312+
return Ok(tx.input[0].witness.clone());
294313
}
295314

296315
// Find all secret corresponding to the known public keys in ms

integration_test/src/test_util.rs

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use miniscript::descriptor::{SinglePub, SinglePubKey};
2222
use miniscript::{Descriptor, DescriptorPublicKey, Miniscript, ScriptContext, TranslatePk};
2323
use rand::RngCore;
2424
use std::str::FromStr;
25+
use miniscript::Error;
2526

2627
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
2728
use bitcoin::secp256k1;
@@ -213,63 +214,73 @@ pub fn parse_insane_ms<Ctx: ScriptContext>(
213214
ms
214215
}
215216

216-
pub fn parse_test_desc(desc: &str, pubdata: &PubData) -> Descriptor<DescriptorPublicKey> {
217+
pub fn parse_test_desc(desc: &str, pubdata: &PubData) -> Result<Descriptor<DescriptorPublicKey>, Error> {
217218
let desc = subs_hash_frag(desc, pubdata);
218-
let desc =
219-
Descriptor::<String>::from_str(&desc).expect("only parsing valid and sane descriptors");
220-
let mut i = 0;
221-
let mut j = pubdata.pks.len();
222-
let desc: Result<_, ()> = desc.translate_pk(
223-
&mut |pk_str: &'_ String| {
224-
let avail = !pk_str.ends_with("!");
225-
if avail {
226-
i = i + 1;
227-
if pk_str.starts_with("K") {
228-
Ok(DescriptorPublicKey::Single(SinglePub {
229-
origin: None,
230-
key: SinglePubKey::FullKey(pubdata.pks[i]),
231-
}))
232-
} else if pk_str.starts_with("X") {
233-
Ok(DescriptorPublicKey::Single(SinglePub {
234-
origin: None,
235-
key: SinglePubKey::XOnly(pubdata.x_only_pks[i]),
236-
}))
219+
if let Ok(result) = Descriptor::<String>::from_str(&desc) {
220+
let desc = result;
221+
let mut i = 0;
222+
let mut j = pubdata.pks.len();
223+
let desc: Result<_, ()> = desc.translate_pk(
224+
&mut |pk_str: &'_ String| {
225+
let avail = !pk_str.ends_with("!");
226+
if avail {
227+
i = i + 1;
228+
if pk_str.starts_with("K") {
229+
Ok(DescriptorPublicKey::Single(SinglePub {
230+
origin: None,
231+
key: SinglePubKey::FullKey(pubdata.pks[i]),
232+
}))
233+
} else if pk_str.starts_with("X") {
234+
Ok(DescriptorPublicKey::Single(SinglePub {
235+
origin: None,
236+
key: SinglePubKey::XOnly(pubdata.x_only_pks[i]),
237+
}))
238+
} else {
239+
panic!("Key must start with either K or X")
240+
}
237241
} else {
238-
panic!("Key must start with either K or X")
239-
}
240-
} else {
241-
Ok(DescriptorPublicKey::Single(SinglePub {
242-
origin: None,
243-
key: SinglePubKey::FullKey(random_pk(59)),
244-
}))
245-
}
246-
},
247-
&mut |pkh_str: &'_ String| {
248-
let avail = !pkh_str.ends_with("!");
249-
if avail {
250-
j = j - 1;
251-
if pkh_str.starts_with("K") {
252242
Ok(DescriptorPublicKey::Single(SinglePub {
253243
origin: None,
254-
key: SinglePubKey::FullKey(pubdata.pks[j]),
244+
key: SinglePubKey::FullKey(random_pk(59)),
255245
}))
256-
} else if pkh_str.starts_with("X") {
246+
}
247+
},
248+
&mut |pkh_str: &'_ String| {
249+
let avail = !pkh_str.ends_with("!");
250+
if avail {
251+
j = j - 1;
252+
if pkh_str.starts_with("K") {
253+
Ok(DescriptorPublicKey::Single(SinglePub {
254+
origin: None,
255+
key: SinglePubKey::FullKey(pubdata.pks[j]),
256+
}))
257+
} else if pkh_str.starts_with("X") {
258+
Ok(DescriptorPublicKey::Single(SinglePub {
259+
origin: None,
260+
key: SinglePubKey::XOnly(pubdata.x_only_pks[j]),
261+
}))
262+
} else {
263+
panic!("Key must start with either K or X")
264+
}
265+
} else {
257266
Ok(DescriptorPublicKey::Single(SinglePub {
258267
origin: None,
259-
key: SinglePubKey::XOnly(pubdata.x_only_pks[j]),
268+
key: SinglePubKey::FullKey(random_pk(61)),
260269
}))
261-
} else {
262-
panic!("Key must start with either K or X")
263270
}
264-
} else {
265-
Ok(DescriptorPublicKey::Single(SinglePub {
266-
origin: None,
267-
key: SinglePubKey::FullKey(random_pk(61)),
268-
}))
269-
}
270-
},
271-
);
272-
desc.expect("Translate must succeed")
271+
},
272+
);
273+
if let Ok(result) = desc {
274+
Ok(result)
275+
}
276+
else{
277+
Err(Error::Unexpected(String::from("Translation was not able to succeed")))
278+
}
279+
// desc.expect("Translate must succeed")
280+
}
281+
else{
282+
return Err(Error::Unexpected(String::from("The descriptor should have been sane and valid")))
283+
}
273284
}
274285

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

0 commit comments

Comments
 (0)