Skip to content

Commit c9086fb

Browse files
committed
Add testutils feature and test-wallet feature to expose wallet::get_funded_wallet()
1 parent 29f32d8 commit c9086fb

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,20 @@ rpc = ["bitcoincore-rpc"]
6262

6363

6464
# Debug/Test features
65+
testutils = []
6566
test-blockchains = ["bitcoincore-rpc", "electrum-client"]
6667
test-electrum = ["electrum", "electrsd/electrs_0_8_10", "test-blockchains"]
6768
test-rpc = ["rpc", "electrsd/electrs_0_8_10", "test-blockchains"]
6869
test-esplora = ["esplora", "electrsd/legacy", "electrsd/esplora_a33e97e1", "test-blockchains"]
6970
test-md-docs = ["electrum"]
71+
test-wallet = []
7072

7173
[dev-dependencies]
7274
lazy_static = "1.4"
7375
env_logger = "0.7"
7476
clap = "2.33"
7577
electrsd = { version= "0.8", features = ["trigger", "bitcoind_0_21_1"] }
78+
bdk = { path = ".", default-features = false, features = ["testutils", "test-wallet"] }
7679

7780
[[example]]
7881
name = "address_validator"

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ pub fn version() -> &'static str {
262262
env!("CARGO_PKG_VERSION", "unknown")
263263
}
264264

265-
// We should consider putting this under a feature flag but we need the macro in doctets so we need
266-
// to wait until https://github.com/rust-lang/rust/issues/67295 is fixed.
267-
//
265+
#[cfg(feature = "testutils")]
268266
// Stuff in here is too rough to document atm
269267
#[doc(hidden)]
270268
pub mod testutils;

src/wallet/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::collections::HashMap;
1818
use std::collections::{BTreeMap, HashSet};
1919
use std::fmt;
2020
use std::ops::{Deref, DerefMut};
21-
use std::str::FromStr;
2221
use std::sync::Arc;
2322

2423
use bitcoin::secp256k1::Secp256k1;
@@ -56,7 +55,6 @@ use tx_builder::{BumpFee, CreateTx, FeePolicy, TxBuilder, TxParams};
5655
use utils::{check_nlocktime, check_nsequence_rbf, After, Older, SecpCtx, DUST_LIMIT_SATOSHI};
5756

5857
use crate::blockchain::{Blockchain, Progress};
59-
use crate::database::memory::MemoryDatabase;
6058
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
6159
use crate::descriptor::derived::AsDerived;
6260
use crate::descriptor::policy::BuildSatisfaction;
@@ -68,7 +66,6 @@ use crate::descriptor::{
6866
use crate::error::Error;
6967
use crate::psbt::PsbtUtils;
7068
use crate::signer::SignerError;
71-
use crate::testutils;
7269
use crate::types::*;
7370

7471
const CACHE_ADDR_BATCH_SIZE: u32 = 100;
@@ -1551,6 +1548,11 @@ where
15511548
}
15521549
}
15531550

1551+
#[cfg(feature = "test-wallet")]
1552+
use crate::database::memory::MemoryDatabase;
1553+
1554+
#[cfg(feature = "test-wallet")]
1555+
#[doc(hidden)]
15541556
/// Return a fake wallet that appears to be funded for testing.
15551557
pub fn get_funded_wallet(
15561558
descriptor: &str,
@@ -1559,6 +1561,9 @@ pub fn get_funded_wallet(
15591561
(String, Option<String>),
15601562
bitcoin::Txid,
15611563
) {
1564+
use crate::testutils;
1565+
use std::str::FromStr;
1566+
15621567
let descriptors = testutils!(@descriptors (descriptor));
15631568
let wallet = Wallet::new_offline(
15641569
&descriptors.0,
@@ -1607,6 +1612,9 @@ pub(crate) mod test {
16071612
use crate::signer::{SignOptions, SignerError};
16081613
use crate::wallet::AddressIndex::{LastUnused, New, Peek, Reset};
16091614

1615+
use crate::testutils;
1616+
use std::str::FromStr;
1617+
16101618
#[test]
16111619
fn test_cache_addresses_fixed() {
16121620
let db = MemoryDatabase::new();

0 commit comments

Comments
 (0)