Skip to content
Draft
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
8 changes: 5 additions & 3 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,11 @@ impl From<BdkCreateTxError> for CreateTxError {
BdkCreateTxError::OutputBelowDustLimit(index) => CreateTxError::OutputBelowDustLimit {
index: index as u64,
},
BdkCreateTxError::CoinSelection(e) => CreateTxError::CoinSelection {
error_message: e.to_string(),
},
BdkCreateTxError::CoinSelection(e) => {
let needed = e.needed.to_sat();
let available = e.available.to_sat();
CreateTxError::InsufficientFunds { needed, available }
}
BdkCreateTxError::NoRecipients => CreateTxError::NoRecipients,
BdkCreateTxError::Psbt(e) => CreateTxError::Psbt {
error_message: e.to_string(),
Expand Down
25 changes: 22 additions & 3 deletions bdk-ffi/src/tests/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::error::{
Bip32Error, Bip39Error, CannotConnectError, DescriptorError, DescriptorKeyError, ElectrumError,
EsploraError, ExtractTxError, PsbtError, PsbtParseError, RequestBuilderError, SignerError,
TransactionError, TxidParseError,
Bip32Error, Bip39Error, CannotConnectError, CreateTxError, DescriptorError, DescriptorKeyError,
ElectrumError, EsploraError, ExtractTxError, PsbtError, PsbtParseError, RequestBuilderError,
SignerError, TransactionError, TxidParseError,
};
use bdk_wallet::bitcoin::Amount;
use bdk_wallet::coin_selection::InsufficientFunds as BdkInsufficientFunds;
use bdk_wallet::error::CreateTxError as BdkCreateTxError;

#[test]
fn test_error_bip32() {
Expand Down Expand Up @@ -104,6 +107,22 @@ fn test_error_cannot_connect() {
assert_eq!(format!("{}", error), "cannot include height: 42");
}

#[test]
fn test_error_create_tx_insufficient_funds_conversion() {
let error = BdkCreateTxError::CoinSelection(BdkInsufficientFunds {
needed: Amount::from_sat(50_000),
available: Amount::from_sat(30_000),
});

match CreateTxError::from(error) {
CreateTxError::InsufficientFunds { needed, available } => {
assert_eq!(needed, 50_000);
assert_eq!(available, 30_000);
}
other => panic!("expected insufficient funds error, got {:?}", other),
}
}

#[test]
fn test_error_descriptor() {
let cases = vec![
Expand Down
Loading