@@ -46,24 +46,34 @@ fn get_vout(cl: &Client, txid: Txid, value: u64, spk: Script) -> (OutPoint, TxOu
46
46
// Currently this is not being used, since miniscript::Error is being propagated
47
47
// But if the types of errors grow in future, we can extend this enum and use it.
48
48
#[ derive( Debug , PartialEq ) ]
49
- pub enum MalleableDescError {
49
+ pub enum DescTestError {
50
50
/// PSBT was not able to finalize
51
51
PsbtFinalizeError ,
52
+ /// Problem with address computation
53
+ AddressComputationError ,
54
+ /// Error while parsing the descriptor
55
+ DescParseError ,
52
56
}
53
57
54
- impl fmt:: Display for MalleableDescError {
58
+ impl fmt:: Display for DescTestError {
55
59
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
56
60
match * self {
57
- MalleableDescError :: PsbtFinalizeError => {
61
+ DescTestError :: PsbtFinalizeError => {
58
62
f. write_str ( "PSBT was not able to finalize" )
59
63
}
64
+ DescTestError :: AddressComputationError => {
65
+ f. write_str ( "Problem with address computation" )
66
+ }
67
+ DescTestError :: DescParseError => {
68
+ f. write_str ( "Not able to parse the descriptor" )
69
+ }
60
70
}
61
71
}
62
72
}
63
73
64
- impl error:: Error for MalleableDescError { }
74
+ impl error:: Error for DescTestError { }
65
75
66
- pub fn test_desc_satisfy ( cl : & Client , testdata : & TestData , desc : & str ) -> Result < Witness , Error > {
76
+ pub fn test_desc_satisfy ( cl : & Client , testdata : & TestData , desc : & str ) -> Result < Witness , DescTestError > {
67
77
let secp = secp256k1:: Secp256k1 :: new ( ) ;
68
78
let sks = & testdata. secretdata . sks ;
69
79
let xonly_keypairs = & testdata. secretdata . x_only_keypairs ;
@@ -75,12 +85,21 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Result
75
85
. unwrap ( ) ;
76
86
assert_eq ! ( blocks. len( ) , 1 ) ;
77
87
78
- let desc = test_util:: parse_test_desc ( & desc, & testdata. pubdata ) ?;
88
+ let desc = test_util:: parse_test_desc ( & desc, & testdata. pubdata ) ;
89
+ if let Err ( Error ) = desc {
90
+ return Err ( DescTestError :: DescParseError ) ;
91
+ }
92
+ let desc = desc. unwrap ( ) ;
79
93
let derived_desc = desc. derived_descriptor ( & secp, 0 ) . unwrap ( ) ;
94
+ let desc_address = derived_desc. address ( bitcoin:: Network :: Regtest ) ;
95
+ if let Err ( Error ) = desc_address {
96
+ return Err ( DescTestError :: AddressComputationError ) ;
97
+ }
98
+ let desc_address = desc_address. unwrap ( ) ;
80
99
// Next send some btc to each address corresponding to the miniscript
81
100
let txid = cl
82
101
. send_to_address (
83
- & derived_desc . address ( bitcoin :: Network :: Regtest ) ? ,
102
+ & desc_address ,
84
103
btc ( 1 ) ,
85
104
None ,
86
105
None ,
@@ -289,7 +308,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Result
289
308
// Finalize the transaction using psbt
290
309
// Let miniscript do it's magic!
291
310
if let Err ( e) = psbt. finalize_mut ( & secp) {
292
- return Err ( Error :: Unexpected ( String :: from ( "PSBT was not able to finalize" ) ) ) ;
311
+ return Err ( DescTestError :: PsbtFinalizeError ) ;
293
312
}
294
313
let tx = psbt. extract ( & secp) . expect ( "Extraction error" ) ;
295
314
0 commit comments