feat(wallet): add back TxBuilder finish() and sort_tx() with thread_rng()

This commit is contained in:
Steve Myers
2024-06-19 16:35:04 -05:00
committed by Rob N
parent 45c0cae0a4
commit 4bddb0de62
19 changed files with 243 additions and 240 deletions

View File

@@ -1,7 +1,6 @@
use bdk_wallet::bitcoin::{Amount, FeeRate, Psbt, TxIn};
use bdk_wallet::{psbt, KeychainKind, SignOptions};
use core::str::FromStr;
use rand::thread_rng;
mod common;
use common::*;
@@ -16,7 +15,7 @@ fn test_psbt_malformed_psbt_input_legacy() {
let send_to = wallet.peek_address(KeychainKind::External, 0);
let mut builder = wallet.build_tx();
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut psbt = builder.finish().unwrap();
psbt.inputs.push(psbt_bip.inputs[0].clone());
let options = SignOptions {
trust_witness_utxo: true,
@@ -33,7 +32,7 @@ fn test_psbt_malformed_psbt_input_segwit() {
let send_to = wallet.peek_address(KeychainKind::External, 0);
let mut builder = wallet.build_tx();
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut psbt = builder.finish().unwrap();
psbt.inputs.push(psbt_bip.inputs[1].clone());
let options = SignOptions {
trust_witness_utxo: true,
@@ -49,7 +48,7 @@ fn test_psbt_malformed_tx_input() {
let send_to = wallet.peek_address(KeychainKind::External, 0);
let mut builder = wallet.build_tx();
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut psbt = builder.finish().unwrap();
psbt.unsigned_tx.input.push(TxIn::default());
let options = SignOptions {
trust_witness_utxo: true,
@@ -65,7 +64,7 @@ fn test_psbt_sign_with_finalized() {
let send_to = wallet.peek_address(KeychainKind::External, 0);
let mut builder = wallet.build_tx();
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut psbt = builder.finish().unwrap();
// add a finalized input
psbt.inputs.push(psbt_bip.inputs[0].clone());
@@ -87,7 +86,7 @@ fn test_psbt_fee_rate_with_witness_utxo() {
let mut builder = wallet.build_tx();
builder.drain_to(addr.script_pubkey()).drain_wallet();
builder.fee_rate(expected_fee_rate);
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut psbt = builder.finish().unwrap();
let fee_amount = psbt.fee_amount();
assert!(fee_amount.is_some());
@@ -112,7 +111,7 @@ fn test_psbt_fee_rate_with_nonwitness_utxo() {
let mut builder = wallet.build_tx();
builder.drain_to(addr.script_pubkey()).drain_wallet();
builder.fee_rate(expected_fee_rate);
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut psbt = builder.finish().unwrap();
let fee_amount = psbt.fee_amount();
assert!(fee_amount.is_some());
let unfinalized_fee_rate = psbt.fee_rate().unwrap();
@@ -136,7 +135,7 @@ fn test_psbt_fee_rate_with_missing_txout() {
let mut builder = wpkh_wallet.build_tx();
builder.drain_to(addr.script_pubkey()).drain_wallet();
builder.fee_rate(expected_fee_rate);
let mut wpkh_psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut wpkh_psbt = builder.finish().unwrap();
wpkh_psbt.inputs[0].witness_utxo = None;
wpkh_psbt.inputs[0].non_witness_utxo = None;
@@ -150,7 +149,7 @@ fn test_psbt_fee_rate_with_missing_txout() {
let mut builder = pkh_wallet.build_tx();
builder.drain_to(addr.script_pubkey()).drain_wallet();
builder.fee_rate(expected_fee_rate);
let mut pkh_psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut pkh_psbt = builder.finish().unwrap();
pkh_psbt.inputs[0].non_witness_utxo = None;
assert!(pkh_psbt.fee_amount().is_none());
@@ -179,7 +178,7 @@ fn test_psbt_multiple_internalkey_signers() {
let send_to = wallet.peek_address(KeychainKind::External, 0);
let mut builder = wallet.build_tx();
builder.drain_to(send_to.script_pubkey()).drain_wallet();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let mut psbt = builder.finish().unwrap();
let unsigned_tx = psbt.unsigned_tx.clone();
// Adds a signer for the wrong internal key, bdk should not use this key to sign

File diff suppressed because it is too large Load Diff