fix(bdk): remove rand dependency

This commit is contained in:
rustaceanrob
2024-04-02 14:31:18 -10:00
committed by Rob N
parent 0543801787
commit 45c0cae0a4
20 changed files with 412 additions and 297 deletions

View File

@@ -1,6 +1,7 @@
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::*;
@@ -15,7 +16,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().unwrap();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
psbt.inputs.push(psbt_bip.inputs[0].clone());
let options = SignOptions {
trust_witness_utxo: true,
@@ -32,7 +33,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().unwrap();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
psbt.inputs.push(psbt_bip.inputs[1].clone());
let options = SignOptions {
trust_witness_utxo: true,
@@ -48,7 +49,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().unwrap();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
psbt.unsigned_tx.input.push(TxIn::default());
let options = SignOptions {
trust_witness_utxo: true,
@@ -64,7 +65,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().unwrap();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
// add a finalized input
psbt.inputs.push(psbt_bip.inputs[0].clone());
@@ -86,7 +87,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().unwrap();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let fee_amount = psbt.fee_amount();
assert!(fee_amount.is_some());
@@ -111,7 +112,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().unwrap();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
let fee_amount = psbt.fee_amount();
assert!(fee_amount.is_some());
let unfinalized_fee_rate = psbt.fee_rate().unwrap();
@@ -135,7 +136,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().unwrap();
let mut wpkh_psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
wpkh_psbt.inputs[0].witness_utxo = None;
wpkh_psbt.inputs[0].non_witness_utxo = None;
@@ -149,7 +150,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().unwrap();
let mut pkh_psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap();
pkh_psbt.inputs[0].non_witness_utxo = None;
assert!(pkh_psbt.fee_amount().is_none());
@@ -178,7 +179,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().unwrap();
let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).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