Skip to content

Commit

Permalink
chore: remove anyhow dev dependency from electrum and esplora
Browse files Browse the repository at this point in the history
  • Loading branch information
LagginTimes committed Apr 26, 2024
1 parent ec34ad1 commit 70e9e01
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
1 change: 0 additions & 1 deletion crates/bitcoind_rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ bdk_chain = { path = "../chain", version = "0.12", default-features = false }

[dev-dependencies]
bdk_testenv = { path = "../testenv", default_features = false }
anyhow = { version = "1" }

[features]
default = ["std"]
Expand Down
28 changes: 14 additions & 14 deletions crates/bitcoind_rpc/tests/test_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bdk_chain::{
local_chain::{CheckPoint, LocalChain},
Append, BlockId, IndexedTxGraph, SpkTxOutIndex,
};
use bdk_testenv::TestEnv;
use bdk_testenv::{electrsd::bitcoind::anyhow::Result, TestEnv};
use bitcoin::{hashes::Hash, Block, OutPoint, ScriptBuf, WScriptHash};
use bitcoincore_rpc::RpcApi;

Expand All @@ -18,7 +18,7 @@ use bitcoincore_rpc::RpcApi;
/// 3. Reorg highest 6 blocks.
/// 4. Emit blocks from [`Emitter`] and re-update the [`LocalChain`].
#[test]
pub fn test_sync_local_chain() -> anyhow::Result<()> {
pub fn test_sync_local_chain() -> Result<()> {
let env = TestEnv::new()?;
let network_tip = env.rpc_client().get_block_count()?;
let (mut local_chain, _) = LocalChain::from_genesis_hash(env.rpc_client().get_block_hash(0)?);
Expand Down Expand Up @@ -127,7 +127,7 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
///
/// [`EmittedUpdate::into_tx_graph_update`]: bdk_bitcoind_rpc::EmittedUpdate::into_tx_graph_update
#[test]
fn test_into_tx_graph() -> anyhow::Result<()> {
fn test_into_tx_graph() -> Result<()> {
let env = TestEnv::new()?;

println!("getting new addresses!");
Expand Down Expand Up @@ -242,7 +242,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
/// TODO: If the reorg height is lower than the fallback height, how do we find a block height to
/// emit that can connect with our receiver chain?
#[test]
fn ensure_block_emitted_after_reorg_is_at_reorg_height() -> anyhow::Result<()> {
fn ensure_block_emitted_after_reorg_is_at_reorg_height() -> Result<()> {
const EMITTER_START_HEIGHT: usize = 100;
const CHAIN_TIP_HEIGHT: usize = 110;

Expand Down Expand Up @@ -281,7 +281,7 @@ fn process_block(
recv_graph: &mut IndexedTxGraph<BlockId, SpkTxOutIndex<()>>,
block: Block,
block_height: u32,
) -> anyhow::Result<()> {
) -> Result<()> {
recv_chain.apply_update(CheckPoint::from_header(&block.header, block_height))?;
let _ = recv_graph.apply_block(block, block_height);
Ok(())
Expand All @@ -291,7 +291,7 @@ fn sync_from_emitter<C>(
recv_chain: &mut LocalChain,
recv_graph: &mut IndexedTxGraph<BlockId, SpkTxOutIndex<()>>,
emitter: &mut Emitter<C>,
) -> anyhow::Result<()>
) -> Result<()>
where
C: bitcoincore_rpc::RpcApi,
{
Expand All @@ -305,7 +305,7 @@ where
fn get_balance(
recv_chain: &LocalChain,
recv_graph: &IndexedTxGraph<BlockId, SpkTxOutIndex<()>>,
) -> anyhow::Result<Balance> {
) -> Result<Balance> {
let chain_tip = recv_chain.tip().block_id();
let outpoints = recv_graph.index.outpoints().clone();
let balance = recv_graph
Expand All @@ -317,7 +317,7 @@ fn get_balance(
/// If a block is reorged out, ensure that containing transactions that do not exist in the
/// replacement block(s) become unconfirmed.
#[test]
fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
fn tx_can_become_unconfirmed_after_reorg() -> Result<()> {
const PREMINE_COUNT: usize = 101;
const ADDITIONAL_COUNT: usize = 11;
const SEND_AMOUNT: Amount = Amount::from_sat(10_000);
Expand Down Expand Up @@ -409,7 +409,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
/// When we call Emitter::mempool multiple times, mempool txs should not be re-emitted, even if the
/// chain tip is extended.
#[test]
fn mempool_avoids_re_emission() -> anyhow::Result<()> {
fn mempool_avoids_re_emission() -> Result<()> {
const BLOCKS_TO_MINE: usize = 101;
const MEMPOOL_TX_COUNT: usize = 2;

Expand Down Expand Up @@ -474,7 +474,7 @@ fn mempool_avoids_re_emission() -> anyhow::Result<()> {
/// that `mempool` should always re-emit txs that have introduced at a height greater than the last
/// emitted block height.
#[test]
fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()> {
fn mempool_re_emits_if_tx_introduction_height_not_reached() -> Result<()> {
const PREMINE_COUNT: usize = 101;
const MEMPOOL_TX_COUNT: usize = 21;

Expand All @@ -498,12 +498,12 @@ fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()

// mine blocks to introduce txs to mempool at different heights
let tx_introductions = (0..MEMPOOL_TX_COUNT)
.map(|_| -> anyhow::Result<_> {
.map(|_| -> Result<_> {
let (height, _) = env.mine_empty_block()?;
let txid = env.send(&addr, Amount::from_sat(2100))?;
Ok((height, txid))
})
.collect::<anyhow::Result<BTreeSet<_>>>()?;
.collect::<Result<BTreeSet<_>>>()?;

assert_eq!(
emitter
Expand Down Expand Up @@ -562,7 +562,7 @@ fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()

/// Ensure we force re-emit all mempool txs after reorg.
#[test]
fn mempool_during_reorg() -> anyhow::Result<()> {
fn mempool_during_reorg() -> Result<()> {
const TIP_DIFF: usize = 10;
const PREMINE_COUNT: usize = 101;

Expand Down Expand Up @@ -687,7 +687,7 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
/// The block hash of 99b should be different than 99a, but their previous block hashes should
/// be the same.
#[test]
fn no_agreement_point() -> anyhow::Result<()> {
fn no_agreement_point() -> Result<()> {
const PREMINE_COUNT: usize = 101;

let env = TestEnv::new()?;
Expand Down
3 changes: 1 addition & 2 deletions crates/electrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
bdk_testenv = { path = "../testenv", default-features = false }
6 changes: 4 additions & 2 deletions crates/electrum/tests/test_electrum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use anyhow::Result;
use bdk_chain::{
bitcoin::{hashes::Hash, Address, Amount, ScriptBuf, WScriptHash},
keychain::Balance,
local_chain::LocalChain,
ConfirmationTimeHeightAnchor, IndexedTxGraph, SpkTxOutIndex,
};
use bdk_electrum::{ElectrumExt, ElectrumUpdate};
use bdk_testenv::{electrsd::bitcoind::bitcoincore_rpc::RpcApi, TestEnv};
use bdk_testenv::{
electrsd::bitcoind::{anyhow, anyhow::Result, bitcoincore_rpc::RpcApi},
TestEnv,
};

fn get_balance(
recv_chain: &LocalChain,
Expand Down
1 change: 0 additions & 1 deletion crates/esplora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
15 changes: 9 additions & 6 deletions crates/esplora/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ mod test {
local_chain::LocalChain,
BlockId,
};
use bdk_testenv::{electrsd::bitcoind::bitcoincore_rpc::RpcApi, TestEnv};
use bdk_testenv::{
electrsd::bitcoind::{anyhow::Result, bitcoincore_rpc::RpcApi},
TestEnv,
};
use esplora_client::Builder;

use crate::async_ext::{chain_update, fetch_latest_blocks};
Expand All @@ -422,7 +425,7 @@ 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() -> Result<()> {
struct TestCase<'a> {
name: &'a str,
/// Initial blockchain height to start the env with.
Expand Down Expand Up @@ -485,7 +488,7 @@ mod test {
let anchors = t
.initial_cps
.iter()
.map(|&height| -> anyhow::Result<_> {
.map(|&height| -> Result<_> {
Ok((
BlockId {
height,
Expand All @@ -494,7 +497,7 @@ mod test {
Txid::all_zeros(),
))
})
.collect::<anyhow::Result<BTreeSet<_>>>()?;
.collect::<Result<BTreeSet<_>>>()?;
let update = chain_update(
&client,
&fetch_latest_blocks(&client).await?,
Expand Down Expand Up @@ -523,7 +526,7 @@ mod test {
let anchors = t
.anchors
.iter()
.map(|&(height, txid)| -> anyhow::Result<_> {
.map(|&(height, txid)| -> Result<_> {
Ok((
BlockId {
height,
Expand All @@ -532,7 +535,7 @@ mod test {
txid,
))
})
.collect::<anyhow::Result<_>>()?;
.collect::<Result<_>>()?;
chain_update(
&client,
&fetch_latest_blocks(&client).await?,
Expand Down
17 changes: 10 additions & 7 deletions crates/esplora/src/blocking_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ mod test {
use bdk_chain::bitcoin::Txid;
use bdk_chain::local_chain::LocalChain;
use bdk_chain::BlockId;
use bdk_testenv::{electrsd::bitcoind::bitcoincore_rpc::RpcApi, TestEnv};
use bdk_testenv::{
electrsd::bitcoind::{anyhow::Result, bitcoincore_rpc::RpcApi},
TestEnv,
};
use esplora_client::{BlockHash, Builder};
use std::collections::{BTreeMap, BTreeSet};
use std::time::Duration;
Expand All @@ -435,7 +438,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() -> Result<()> {
struct TestCase<'a> {
name: &'a str,
/// Initial blockchain height to start the env with.
Expand Down Expand Up @@ -498,7 +501,7 @@ mod test {
let anchors = t
.initial_cps
.iter()
.map(|&height| -> anyhow::Result<_> {
.map(|&height| -> Result<_> {
Ok((
BlockId {
height,
Expand All @@ -507,7 +510,7 @@ mod test {
Txid::all_zeros(),
))
})
.collect::<anyhow::Result<BTreeSet<_>>>()?;
.collect::<Result<BTreeSet<_>>>()?;
let update = chain_update(
&client,
&fetch_latest_blocks(&client)?,
Expand Down Expand Up @@ -535,7 +538,7 @@ mod test {
let anchors = t
.anchors
.iter()
.map(|&(height, txid)| -> anyhow::Result<_> {
.map(|&(height, txid)| -> Result<_> {
Ok((
BlockId {
height,
Expand All @@ -544,7 +547,7 @@ mod test {
txid,
))
})
.collect::<anyhow::Result<_>>()?;
.collect::<Result<_>>()?;
chain_update(
&client,
&fetch_latest_blocks(&client)?,
Expand Down Expand Up @@ -598,7 +601,7 @@ mod test {
}

#[test]
fn update_local_chain() -> anyhow::Result<()> {
fn update_local_chain() -> Result<()> {
const TIP_HEIGHT: u32 = 50;

let env = TestEnv::new()?;
Expand Down

0 comments on commit 70e9e01

Please sign in to comment.