diff --git a/Cargo.toml b/Cargo.toml index 7123580709..d1d8521d5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,17 +62,20 @@ rpc = ["bitcoincore-rpc"] # Debug/Test features +testutils = [] test-blockchains = ["bitcoincore-rpc", "electrum-client"] test-electrum = ["electrum", "electrsd/electrs_0_8_10", "test-blockchains"] test-rpc = ["rpc", "electrsd/electrs_0_8_10", "test-blockchains"] test-esplora = ["esplora", "electrsd/legacy", "electrsd/esplora_a33e97e1", "test-blockchains"] test-md-docs = ["electrum"] +test-wallet = [] [dev-dependencies] lazy_static = "1.4" env_logger = "0.7" clap = "2.33" electrsd = { version= "0.8", features = ["trigger", "bitcoind_0_21_1"] } +bdk = { path = ".", features = ["testutils", "test-wallet"] } [[example]] name = "address_validator" diff --git a/src/lib.rs b/src/lib.rs index 09779fd13a..fdd6dee6a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -262,9 +262,7 @@ pub fn version() -> &'static str { env!("CARGO_PKG_VERSION", "unknown") } -// We should consider putting this under a feature flag but we need the macro in doctets so we need -// to wait until https://github.com/rust-lang/rust/issues/67295 is fixed. -// +#[cfg(feature = "testutils")] // Stuff in here is too rough to document atm #[doc(hidden)] pub mod testutils; diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 109a219cbd..442a0986c0 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -18,7 +18,6 @@ use std::collections::HashMap; use std::collections::{BTreeMap, HashSet}; use std::fmt; use std::ops::{Deref, DerefMut}; -use std::str::FromStr; use std::sync::Arc; use bitcoin::secp256k1::Secp256k1; @@ -56,7 +55,6 @@ use tx_builder::{BumpFee, CreateTx, FeePolicy, TxBuilder, TxParams}; use utils::{check_nlocktime, check_nsequence_rbf, After, Older, SecpCtx, DUST_LIMIT_SATOSHI}; use crate::blockchain::{Blockchain, Progress}; -use crate::database::memory::MemoryDatabase; use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils}; use crate::descriptor::derived::AsDerived; use crate::descriptor::policy::BuildSatisfaction; @@ -68,7 +66,6 @@ use crate::descriptor::{ use crate::error::Error; use crate::psbt::PsbtUtils; use crate::signer::SignerError; -use crate::testutils; use crate::types::*; const CACHE_ADDR_BATCH_SIZE: u32 = 100; @@ -1551,6 +1548,11 @@ where } } +#[cfg(feature = "test-wallet")] +use crate::database::memory::MemoryDatabase; + +#[cfg(feature = "test-wallet")] +#[doc(hidden)] /// Return a fake wallet that appears to be funded for testing. pub fn get_funded_wallet( descriptor: &str, @@ -1559,6 +1561,9 @@ pub fn get_funded_wallet( (String, Option), bitcoin::Txid, ) { + use crate::testutils; + use std::str::FromStr; + let descriptors = testutils!(@descriptors (descriptor)); let wallet = Wallet::new_offline( &descriptors.0, @@ -1607,6 +1612,9 @@ pub(crate) mod test { use crate::signer::{SignOptions, SignerError}; use crate::wallet::AddressIndex::{LastUnused, New, Peek, Reset}; + use crate::testutils; + use std::str::FromStr; + #[test] fn test_cache_addresses_fixed() { let db = MemoryDatabase::new();