Skip to content

Commit

Permalink
fix tests with no default features
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Nov 13, 2024
1 parent 1258da1 commit d7ee8bf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/wallet/test/get_asset_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ fn success() {
assert!((timestamp - cfa_metadata.timestamp) < 30);
}

#[cfg(feature = "electrum")]
#[test]
#[parallel]
fn fail() {
Expand Down
13 changes: 8 additions & 5 deletions src/wallet/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ use time::OffsetDateTime;
use super::*;

#[cfg(any(feature = "electrum", feature = "esplora"))]
use crate::utils::build_indexer;
use crate::wallet::{
rust_only::{check_indexer_url, check_proxy_url},
test::utils::chain::*,
utils::build_indexer,
};
use crate::{
database::entities::transfer_transport_endpoint,
utils::{
Expand All @@ -28,10 +32,8 @@ use crate::{
},
wallet::{
backup::{get_backup_paths, unzip, zip_dir, BackupPubData, ScryptParams},
rust_only::{
check_indexer_url, check_proxy_url, AssetColoringInfo, ColoringInfo, IndexerProtocol,
},
test::utils::{api::*, chain::*, helpers::*},
rust_only::{AssetColoringInfo, ColoringInfo, IndexerProtocol},
test::utils::{api::*, helpers::*},
},
};

Expand Down Expand Up @@ -71,6 +73,7 @@ const QUEUE_DEPTH_EXCEEDED: &str = "Work queue depth exceeded";

static INIT: Once = Once::new();

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub fn initialize() {
INIT.call_once(|| {
if std::env::var("SKIP_INIT").is_ok() {
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/test/rust_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ fn check_indexer_url_esplora_fail() {
assert_matches!(result, Err(Error::InvalidIndexer { details: m }) if m == invalid_indexer);
}

#[cfg(feature = "electrum")]
#[test]
#[parallel]
fn check_proxy_url_success() {
Expand All @@ -579,6 +580,7 @@ fn check_proxy_url_success() {
assert!(check_proxy_url(PROXY_URL).is_ok());
}

#[cfg(feature = "electrum")]
#[test]
#[parallel]
fn check_proxy_url_fail() {
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/test/utils/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ fn _esplora_bitcoin_cli() -> Vec<String> {
}

impl Miner {
#[cfg(any(feature = "electrum", feature = "esplora"))]
fn mine(&self, esplora: bool, blocks: u32) -> bool {
if self.no_mine_count > 0 {
return false;
}
self.force_mine(esplora, blocks)
}

#[cfg(any(feature = "electrum", feature = "esplora"))]
fn force_mine(&self, esplora: bool, blocks: u32) -> bool {
println!("mining (esplora: {esplora}), time: {}", get_current_time());
let bitcoin_cli = if esplora {
Expand Down Expand Up @@ -91,6 +93,7 @@ impl Miner {
}
}

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) fn mine_blocks(esplora: bool, blocks: u32, resume: bool) {
let t_0 = OffsetDateTime::now_utc();
if resume {
Expand All @@ -108,10 +111,12 @@ pub(crate) fn mine_blocks(esplora: bool, blocks: u32, resume: bool) {
}
}

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) fn mine(esplora: bool, resume: bool) {
mine_blocks(esplora, 1, resume)
}

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) fn force_mine_no_resume_when_alone(esplora: bool) {
let t_0 = OffsetDateTime::now_utc();
loop {
Expand Down Expand Up @@ -190,6 +195,7 @@ pub(crate) fn estimate_smart_fee(esplora: bool) -> bool {
json_output.unwrap().get("errors").is_none()
}

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) fn wait_indexers_sync() {
let t_0 = OffsetDateTime::now_utc();
let mut max_blockcount = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/test/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub(crate) fn get_test_data_dir_path() -> PathBuf {
}

pub(crate) fn create_test_data_dir() -> PathBuf {
initialize();
let test_data_dir = get_test_data_dir_path();
if !test_data_dir.exists() {
fs::create_dir_all(&test_data_dir).unwrap();
Expand Down Expand Up @@ -138,6 +137,7 @@ pub(crate) fn drain_wallet(wallet: &Wallet, online: &Online) {
test_drain_to_destroy(wallet, online, &rcv_wallet.get_address().unwrap());
}

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) fn send_to_address(address: String) {
let t_0 = OffsetDateTime::now_utc();
let bitcoin_cli = bitcoin_cli();
Expand Down Expand Up @@ -169,6 +169,7 @@ pub(crate) fn send_to_address(address: String) {
}
}

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) fn fund_wallet(address: String) {
send_to_address(address);
mine(false, false);
Expand Down

0 comments on commit d7ee8bf

Please sign in to comment.