Skip to content

test: add legacy descriptor tests #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions wallet/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{KeychainKind, Update, Wallet};
/// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
/// to a foreign address and one returning 50_000 back to the wallet. The remaining 1000
/// sats are the transaction fee.
pub fn get_funded_wallet(descriptor: &str, change_descriptor: &str) -> (Wallet, Txid) {
new_funded_wallet(descriptor, Some(change_descriptor))
pub fn get_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wallet, Txid) {
new_funded_wallet(descriptor, change_descriptor)
}

fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wallet, Txid) {
Expand Down Expand Up @@ -131,7 +131,12 @@ pub fn get_funded_wallet_single(descriptor: &str) -> (Wallet, Txid) {
/// Get funded segwit wallet
pub fn get_funded_wallet_wpkh() -> (Wallet, Txid) {
let (desc, change_desc) = get_test_wpkh_and_change_desc();
get_funded_wallet(desc, change_desc)
get_funded_wallet(desc, Some(change_desc))
}

/// `pkh` single key descriptor
pub fn get_test_pkh() -> &'static str {
"pkh(cNJFgo1driFnPcBdBX8BrJrpxchBWXwXCvNH5SoSkdcF6JXXwHMm)"
}

/// `wpkh` single key descriptor
Expand Down
6 changes: 3 additions & 3 deletions wallet/src/wallet/coin_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ pub trait CoinSelectionAlgorithm: core::fmt::Debug {
/// Perform the coin selection
///
/// - `required_utxos`: the utxos that must be spent regardless of `target_amount` with their
/// weight cost
/// weight cost
/// - `optional_utxos`: the remaining available utxos to satisfy `target_amount` with their
/// weight cost
/// weight cost
/// - `fee_rate`: fee rate to use
/// - `target_amount`: the outgoing amount and the fees already accumulated from adding
/// outputs and transaction’s header.
/// outputs and transaction’s header.
/// - `drain_script`: the script to use in case of change
/// - `rand`: random number generated used by some coin selection algorithms such as [`SingleRandomDraw`]
fn coin_select<R: RngCore>(
Expand Down
6 changes: 3 additions & 3 deletions wallet/src/wallet/persisted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ pub trait AsyncWalletPersister {
///
/// * Ensure the persister is initialized before data is persisted.
/// * Ensure there were no previously persisted wallet data before creating a fresh wallet and
/// persisting it.
/// persisting it.
/// * Only clear the staged changes of [`Wallet`] after persisting succeeds.
/// * Ensure the wallet is persisted to the same `P` type as when created/loaded. Note that this is
/// not completely fool-proof as you can have multiple instances of the same `P` type that are
/// connected to different databases.
/// not completely fool-proof as you can have multiple instances of the same `P` type that are
/// connected to different databases.
#[derive(Debug)]
pub struct PersistedWallet<P> {
inner: Wallet,
Expand Down
4 changes: 2 additions & 2 deletions wallet/tests/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn test_psbt_fee_rate_with_missing_txout() {

let desc = "pkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/0)";
let change_desc = "pkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/1)";
let (mut pkh_wallet, _) = get_funded_wallet(desc, change_desc);
let (mut pkh_wallet, _) = get_funded_wallet(desc, Some(change_desc));
let addr = pkh_wallet.peek_address(KeychainKind::External, 0);
let mut builder = pkh_wallet.build_tx();
builder.drain_to(addr.script_pubkey()).drain_wallet();
Expand Down Expand Up @@ -172,7 +172,7 @@ fn test_psbt_multiple_internalkey_signers() {
let keypair = Keypair::from_secret_key(&secp, &prv.inner);

let change_desc = "tr(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)";
let (mut wallet, _) = get_funded_wallet(&desc, change_desc);
let (mut wallet, _) = get_funded_wallet(&desc, Some(change_desc));
let to_spend = wallet.balance().total();
let send_to = wallet.peek_address(KeychainKind::External, 0);
let mut builder = wallet.build_tx();
Expand Down
Loading
Loading