Skip to content

Commit b01a386

Browse files
committed
test: add create custom fee rate for legacy descriptors
1 parent edc1835 commit b01a386

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

crates/bdk/tests/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ pub fn get_funded_wallet(descriptor: &str) -> (Wallet, bitcoin::Txid) {
108108
get_funded_wallet_with_change(descriptor, None)
109109
}
110110

111-
// This PKH can be obtained in testnet by using the 12-word seed
112-
// abandon x 11 + cactus and getting the first receiving address.
111+
// This PKH WIF was taken from example 5 in
112+
// https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-ec-to-wif
113113
pub fn get_test_pkh() -> &'static str {
114-
"pkh(0275d93539d503d824ad0c69a4c23ae480700489de09378ba32c1776cf86d6bb93)"
114+
"pkh(cNJFgo1driFnPcBdBX8BrJrpxchBWXwXCvNH5SoSkdcF6JXXwHMm)"
115115
}
116116

117117
pub fn get_test_wpkh() -> &'static str {

crates/bdk/tests/wallet.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,16 @@ macro_rules! check_fee {
461461
}};
462462
}
463463

464+
/// A floating point assert! that taker an additional third argument `delta`
465+
/// as a tolerance value when test for equality the first and second argument.
466+
macro_rules! assert_delta {
467+
($x:expr, $y:expr, $d:expr) => {
468+
if !($x - $y < $d || $y - $x < $d) {
469+
panic!();
470+
}
471+
};
472+
}
473+
464474
#[test]
465475
fn test_create_tx_drain_wallet_and_drain_to() {
466476
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
@@ -542,10 +552,6 @@ fn test_create_tx_default_fee_rate() {
542552
assert_fee_rate!(psbt, fee.unwrap_or(0), FeeRate::default(), @add_signature);
543553
}
544554

545-
// FIXME: Something is going on
546-
// thread 'test_legacy_create_tx_custom_fee_rate' panicked at 'assertion failed: `(left == right)`
547-
// left: `FeeRate(9.537815)`,
548-
// right: `FeeRate(5.0)`'
549555
#[test]
550556
fn test_legacy_create_tx_custom_fee_rate() {
551557
let (mut wallet, _) = get_funded_wallet(get_test_pkh());
@@ -554,9 +560,16 @@ fn test_legacy_create_tx_custom_fee_rate() {
554560
builder
555561
.add_recipient(addr.script_pubkey(), 25_000)
556562
.fee_rate(FeeRate::from_sat_per_vb(5.0));
557-
let psbt = builder.finish().unwrap();
563+
let mut psbt = builder.finish().unwrap();
558564

559-
assert_eq!(psbt.fee_rate().unwrap(), FeeRate::from_sat_per_vb(5.0));
565+
// sign the transaction
566+
wallet.sign(&mut psbt, SignOptions::default()).unwrap();
567+
568+
assert_delta!(
569+
psbt.fee_rate().unwrap(),
570+
FeeRate::from_sat_per_vb(5.0),
571+
FeeRate::from_sat_per_vb(0.6)
572+
)
560573
}
561574

562575
#[test]

0 commit comments

Comments
 (0)