Skip to content

Commit

Permalink
Add testutils feature and test-wallet feature to expose wallet::get_f…
Browse files Browse the repository at this point in the history
…unded_wallet()
  • Loading branch information
notmandatory committed Jul 29, 2021
1 parent 29f32d8 commit 344a3dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 11 additions & 3 deletions src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -1559,6 +1561,9 @@ pub fn get_funded_wallet(
(String, Option<String>),
bitcoin::Txid,
) {
use crate::testutils;
use std::str::FromStr;

let descriptors = testutils!(@descriptors (descriptor));
let wallet = Wallet::new_offline(
&descriptors.0,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 344a3dd

Please sign in to comment.