Skip to content

Commit 58ccb93

Browse files
committed
Use DescTestError instead of miniscript::Error
1 parent 8817924 commit 58ccb93

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

integration_test/run.sh

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

3232
RPC_URL=http://localhost:12348 \
3333
RPC_COOKIE=${TESTDIR}/1/regtest/.cookie \
34-
RUST_BACKTRACE=1 \
3534
cargo run
3635

3736
RESULT=$?

integration_test/src/test_desc.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,34 @@ fn get_vout(cl: &Client, txid: Txid, value: u64, spk: Script) -> (OutPoint, TxOu
4646
// Currently this is not being used, since miniscript::Error is being propagated
4747
// But if the types of errors grow in future, we can extend this enum and use it.
4848
#[derive(Debug, PartialEq)]
49-
pub enum MalleableDescError {
49+
pub enum DescTestError {
5050
/// PSBT was not able to finalize
5151
PsbtFinalizeError,
52+
/// Problem with address computation
53+
AddressComputationError,
54+
/// Error while parsing the descriptor
55+
DescParseError,
5256
}
5357

54-
impl fmt::Display for MalleableDescError{
58+
impl fmt::Display for DescTestError {
5559
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5660
match *self {
57-
MalleableDescError::PsbtFinalizeError => {
61+
DescTestError::PsbtFinalizeError => {
5862
f.write_str("PSBT was not able to finalize")
5963
}
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+
}
6070
}
6171
}
6272
}
6373

64-
impl error::Error for MalleableDescError {}
74+
impl error::Error for DescTestError {}
6575

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> {
6777
let secp = secp256k1::Secp256k1::new();
6878
let sks = &testdata.secretdata.sks;
6979
let xonly_keypairs = &testdata.secretdata.x_only_keypairs;
@@ -75,12 +85,21 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Result
7585
.unwrap();
7686
assert_eq!(blocks.len(), 1);
7787

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();
7993
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();
8099
// Next send some btc to each address corresponding to the miniscript
81100
let txid = cl
82101
.send_to_address(
83-
&derived_desc.address(bitcoin::Network::Regtest)?,
102+
&desc_address,
84103
btc(1),
85104
None,
86105
None,
@@ -289,7 +308,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Result
289308
// Finalize the transaction using psbt
290309
// Let miniscript do it's magic!
291310
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);
293312
}
294313
let tx = psbt.extract(&secp).expect("Extraction error");
295314

0 commit comments

Comments
 (0)