From 50d1792984ac7ebbf6e9a2d24d8528a65a54cade Mon Sep 17 00:00:00 2001 From: Wei Chen Date: Fri, 26 Apr 2024 03:28:41 -0400 Subject: [PATCH] chore: remove `anyhow` dev dependency from `electrum` and `esplora` --- crates/electrum/Cargo.toml | 3 +- crates/electrum/tests/test_electrum.rs | 30 ++++++++-------- crates/esplora/Cargo.toml | 1 - crates/esplora/src/async_ext.rs | 50 ++++++++++++++------------ crates/esplora/src/blocking_ext.rs | 49 +++++++++++++------------ 5 files changed, 70 insertions(+), 63 deletions(-) diff --git a/crates/electrum/Cargo.toml b/crates/electrum/Cargo.toml index ef5051d68d..443cadbe74 100644 --- a/crates/electrum/Cargo.toml +++ b/crates/electrum/Cargo.toml @@ -17,5 +17,4 @@ electrum-client = { version = "0.19" } #rustls = { version = "=0.21.1", optional = true, features = ["dangerous_configuration"] } [dev-dependencies] -bdk_testenv = { path = "../testenv", default-features = false } -anyhow = "1" \ No newline at end of file +bdk_testenv = { path = "../testenv", default-features = false } \ No newline at end of file diff --git a/crates/electrum/tests/test_electrum.rs b/crates/electrum/tests/test_electrum.rs index da5a3d0cee..2e1a8ea55d 100644 --- a/crates/electrum/tests/test_electrum.rs +++ b/crates/electrum/tests/test_electrum.rs @@ -1,4 +1,3 @@ -use anyhow::Result; use bdk_chain::{ bitcoin::{hashes::Hash, Address, Amount, ScriptBuf, WScriptHash}, keychain::Balance, @@ -6,12 +5,15 @@ use bdk_chain::{ ConfirmationTimeHeightAnchor, IndexedTxGraph, SpkTxOutIndex, }; use bdk_electrum::{ElectrumExt, ElectrumUpdate}; -use bdk_testenv::{electrsd::bitcoind::bitcoincore_rpc::RpcApi, TestEnv}; +use bdk_testenv::{ + electrsd::bitcoind::{anyhow::Error, bitcoincore_rpc::RpcApi}, + TestEnv, +}; fn get_balance( recv_chain: &LocalChain, recv_graph: &IndexedTxGraph>, -) -> Result { +) -> Result { let chain_tip = recv_chain.tip().block_id(); let outpoints = recv_graph.index.outpoints().clone(); let balance = recv_graph @@ -27,7 +29,7 @@ fn get_balance( /// 3. Mine extra block to confirm sent tx. /// 4. Check [`Balance`] to ensure tx is confirmed. #[test] -fn scan_detects_confirmed_tx() -> Result<()> { +fn scan_detects_confirmed_tx() -> Result<(), Error> { const SEND_AMOUNT: Amount = Amount::from_sat(10_000); let env = TestEnv::new()?; @@ -68,9 +70,9 @@ fn scan_detects_confirmed_tx() -> Result<()> { let missing = relevant_txids.missing_full_txs(recv_graph.graph()); let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, missing)?; - let _ = recv_chain - .apply_update(chain_update) - .map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?; + let _ = recv_chain.apply_update(chain_update).map_err(|err| { + bdk_testenv::electrsd::bitcoind::anyhow::anyhow!("LocalChain update error: {:?}", err) + })?; let _ = recv_graph.apply_update(graph_update); // Check to see if tx is confirmed. @@ -92,7 +94,7 @@ fn scan_detects_confirmed_tx() -> Result<()> { /// 3. Perform 8 separate reorgs on each block with a confirmed tx. /// 4. Check [`Balance`] after each reorg to ensure unconfirmed amount is correct. #[test] -fn tx_can_become_unconfirmed_after_reorg() -> Result<()> { +fn tx_can_become_unconfirmed_after_reorg() -> Result<(), Error> { const REORG_COUNT: usize = 8; const SEND_AMOUNT: Amount = Amount::from_sat(10_000); @@ -134,9 +136,9 @@ fn tx_can_become_unconfirmed_after_reorg() -> Result<()> { let missing = relevant_txids.missing_full_txs(recv_graph.graph()); let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, missing)?; - let _ = recv_chain - .apply_update(chain_update) - .map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?; + let _ = recv_chain.apply_update(chain_update).map_err(|err| { + bdk_testenv::electrsd::bitcoind::anyhow::anyhow!("LocalChain update error: {:?}", err) + })?; let _ = recv_graph.apply_update(graph_update.clone()); // Retain a snapshot of all anchors before reorg process. @@ -164,9 +166,9 @@ fn tx_can_become_unconfirmed_after_reorg() -> Result<()> { let missing = relevant_txids.missing_full_txs(recv_graph.graph()); let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, missing)?; - let _ = recv_chain - .apply_update(chain_update) - .map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?; + let _ = recv_chain.apply_update(chain_update).map_err(|err| { + bdk_testenv::electrsd::bitcoind::anyhow::anyhow!("LocalChain update error: {:?}", err) + })?; // Check to see if a new anchor is added during current reorg. if !initial_anchors.is_superset(graph_update.all_anchors()) { diff --git a/crates/esplora/Cargo.toml b/crates/esplora/Cargo.toml index 3cca71a892..8ecfe8634f 100644 --- a/crates/esplora/Cargo.toml +++ b/crates/esplora/Cargo.toml @@ -24,7 +24,6 @@ miniscript = { version = "11.0.0", optional = true, default-features = false } [dev-dependencies] bdk_testenv = { path = "../testenv", default_features = false } tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] } -anyhow = "1" [features] default = ["std", "async-https", "blocking-https-rustls"] diff --git a/crates/esplora/src/async_ext.rs b/crates/esplora/src/async_ext.rs index 5de9cfab63..81e441de8b 100644 --- a/crates/esplora/src/async_ext.rs +++ b/crates/esplora/src/async_ext.rs @@ -422,7 +422,8 @@ mod test { /// Ensure that update does not remove heights (from original), and all anchor heights are included. #[tokio::test] - pub async fn test_finalize_chain_update() -> anyhow::Result<()> { + pub async fn test_finalize_chain_update() -> bdk_testenv::electrsd::bitcoind::anyhow::Result<()> + { struct TestCase<'a> { name: &'a str, /// Initial blockchain height to start the env with. @@ -485,16 +486,18 @@ mod test { let anchors = t .initial_cps .iter() - .map(|&height| -> anyhow::Result<_> { - Ok(( - BlockId { - height, - hash: env.bitcoind.client.get_block_hash(height as _)?, - }, - Txid::all_zeros(), - )) - }) - .collect::>>()?; + .map( + |&height| -> bdk_testenv::electrsd::bitcoind::anyhow::Result<_> { + Ok(( + BlockId { + height, + hash: env.bitcoind.client.get_block_hash(height as _)?, + }, + Txid::all_zeros(), + )) + }, + ) + .collect::>>()?; let update = chain_update( &client, &fetch_latest_blocks(&client).await?, @@ -519,11 +522,12 @@ mod test { } // craft update - let update = { - let anchors = t + let update = + { + let anchors = t .anchors .iter() - .map(|&(height, txid)| -> anyhow::Result<_> { + .map(|&(height, txid)| -> bdk_testenv::electrsd::bitcoind::anyhow::Result<_> { Ok(( BlockId { height, @@ -532,15 +536,15 @@ mod test { txid, )) }) - .collect::>()?; - chain_update( - &client, - &fetch_latest_blocks(&client).await?, - &local_chain.tip(), - &anchors, - ) - .await? - }; + .collect::>()?; + chain_update( + &client, + &fetch_latest_blocks(&client).await?, + &local_chain.tip(), + &anchors, + ) + .await? + }; // apply update let mut updated_local_chain = local_chain.clone(); diff --git a/crates/esplora/src/blocking_ext.rs b/crates/esplora/src/blocking_ext.rs index 8312fd5e6a..6ce6ce7302 100644 --- a/crates/esplora/src/blocking_ext.rs +++ b/crates/esplora/src/blocking_ext.rs @@ -435,7 +435,7 @@ mod test { /// Ensure that update does not remove heights (from original), and all anchor heights are included. #[test] - pub fn test_finalize_chain_update() -> anyhow::Result<()> { + pub fn test_finalize_chain_update() -> bdk_testenv::electrsd::bitcoind::anyhow::Result<()> { struct TestCase<'a> { name: &'a str, /// Initial blockchain height to start the env with. @@ -498,16 +498,18 @@ mod test { let anchors = t .initial_cps .iter() - .map(|&height| -> anyhow::Result<_> { - Ok(( - BlockId { - height, - hash: env.bitcoind.client.get_block_hash(height as _)?, - }, - Txid::all_zeros(), - )) - }) - .collect::>>()?; + .map( + |&height| -> bdk_testenv::electrsd::bitcoind::anyhow::Result<_> { + Ok(( + BlockId { + height, + hash: env.bitcoind.client.get_block_hash(height as _)?, + }, + Txid::all_zeros(), + )) + }, + ) + .collect::>>()?; let update = chain_update( &client, &fetch_latest_blocks(&client)?, @@ -531,11 +533,12 @@ mod test { } // craft update - let update = { - let anchors = t + let update = + { + let anchors = t .anchors .iter() - .map(|&(height, txid)| -> anyhow::Result<_> { + .map(|&(height, txid)| -> bdk_testenv::electrsd::bitcoind::anyhow::Result<_> { Ok(( BlockId { height, @@ -544,14 +547,14 @@ mod test { txid, )) }) - .collect::>()?; - chain_update( - &client, - &fetch_latest_blocks(&client)?, - &local_chain.tip(), - &anchors, - )? - }; + .collect::>()?; + chain_update( + &client, + &fetch_latest_blocks(&client)?, + &local_chain.tip(), + &anchors, + )? + }; // apply update let mut updated_local_chain = local_chain.clone(); @@ -598,7 +601,7 @@ mod test { } #[test] - fn update_local_chain() -> anyhow::Result<()> { + fn update_local_chain() -> bdk_testenv::electrsd::bitcoind::anyhow::Result<()> { const TIP_HEIGHT: u32 = 50; let env = TestEnv::new()?;