Skip to content

deps(bdk_testenv): bump electrsd to 0.31.0 #1826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ authors = ["Bitcoin Dev Kit Developers"]
[workspace.lints.clippy]
print_stdout = "deny"
print_stderr = "deny"

[patch.crates-io.corepc-types]
git = "https://github.com/rust-bitcoin/corepc.git"
branch = "master"

[patch.crates-io.corepc-client]
git = "https://github.com/rust-bitcoin/corepc.git"
branch = "master"

[patch.crates-io.corepc-node]
git = "https://github.com/rust-bitcoin/corepc.git"
branch = "master"

[patch.crates-io.electrsd]
git = "https://github.com/oleonardolima/electrsd.git"
branch = "deps/bump-corepc-deps"
16 changes: 16 additions & 0 deletions crates/electrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ use-openssl = ["electrum-client/use-openssl"]
[[test]]
name = "test_electrum"
required-features = ["use-rustls"]

[patch.crates-io.corepc-types]
git = "https://github.com/rust-bitcoin/corepc.git"
branch = "master"

[patch.crates-io.corepc-client]
git = "https://github.com/rust-bitcoin/corepc.git"
branch = "master"

[patch.crates-io.corepc-node]
git = "https://github.com/rust-bitcoin/corepc.git"
branch = "master"

[patch.crates-io.electrsd]
git = "https://github.com/oleonardolima/electrsd.git"
branch = "deps/bump-corepc-deps"
133 changes: 52 additions & 81 deletions crates/electrum/tests/test_electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ use bdk_chain::{
};
use bdk_core::bitcoin::{
key::{Secp256k1, UntweakedPublicKey},
Network,
Denomination, Network,
};
use bdk_electrum::BdkElectrumClient;
use bdk_testenv::{
anyhow,
bitcoincore_rpc::{json::CreateRawTransactionInput, RawTx, RpcApi},
TestEnv,
};
use bdk_testenv::{anyhow, TestEnv};
use core::time::Duration;
use electrum_client::ElectrumApi;
use std::collections::{BTreeSet, HashMap, HashSet};
Expand Down Expand Up @@ -88,7 +84,8 @@ pub fn detect_receive_tx_cancel() -> anyhow::Result<()> {
let client = BdkElectrumClient::new(electrum_client);

let mut graph = IndexedTxGraph::<ConfirmationBlockTime, _>::new(SpkTxOutIndex::<()>::default());
let (chain, _) = LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?);
let (chain, _) =
LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?.block_hash()?);

// Get receiving address.
let receiver_spk = get_test_spk();
Expand All @@ -99,11 +96,13 @@ pub fn detect_receive_tx_cancel() -> anyhow::Result<()> {

// Select a UTXO to use as an input for constructing our test transactions.
let selected_utxo = rpc_client
.list_unspent(None, None, None, Some(false), None)?
.list_unspent()?
.0
.into_iter()
// Find a block reward tx.
.find(|utxo| utxo.amount == Amount::from_int_btc(50))
.expect("Must find a block reward UTXO");
.find(|utxo| utxo.amount == Amount::from_int_btc(50).to_btc())
.expect("Must find a block reward UTXO")
.into_model()?;

// Derive the sender's address from the selected UTXO.
let sender_spk = selected_utxo.script_pub_key.clone();
Expand All @@ -122,9 +121,9 @@ pub fn detect_receive_tx_cancel() -> anyhow::Result<()> {
receiver_addr.to_string(),
selected_utxo.amount - SEND_TX_FEE,
)]);
let send_tx = rpc_client.create_raw_transaction(&inputs, &send_tx_outputs, None, Some(true))?;
let send_tx = rpc_client.create_raw_transaction(&inputs, &send_tx_outputs)?;
let send_tx = rpc_client
.sign_raw_transaction_with_wallet(send_tx.raw_hex(), None, None)?
.sign_raw_transaction_with_wallet(send_tx.raw_hex())?
.transaction()?;

// Create and sign the `undo_send_tx` transaction. This redirects funds back to the sender
Expand All @@ -133,10 +132,9 @@ pub fn detect_receive_tx_cancel() -> anyhow::Result<()> {
sender_addr.to_string(),
selected_utxo.amount - UNDO_SEND_TX_FEE,
)]);
let undo_send_tx =
rpc_client.create_raw_transaction(&inputs, &undo_send_outputs, None, Some(true))?;
let undo_send_tx = rpc_client.create_raw_transaction(&inputs, &undo_send_outputs)?;
let undo_send_tx = rpc_client
.sign_raw_transaction_with_wallet(undo_send_tx.raw_hex(), None, None)?
.sign_raw_transaction_with_wallet(undo_send_tx.raw_hex())?
.transaction()?;

// Sync after broadcasting the `send_tx`. Ensure that we detect and receive the `send_tx`.
Expand Down Expand Up @@ -198,7 +196,7 @@ pub fn chained_mempool_tx_sync() -> anyhow::Result<()> {
let electrum_client = electrum_client::Client::new(env.electrsd.electrum_url.as_str())?;

let tracked_addr = rpc_client
.get_new_address(None, None)?
.new_address()?
.require_network(Network::Regtest)?;

env.mine_blocks(100, None)?;
Expand All @@ -208,7 +206,8 @@ pub fn chained_mempool_tx_sync() -> anyhow::Result<()> {

// Create second unconfirmed tx that spends the first.
let utxo = rpc_client
.list_unspent(None, Some(0), None, Some(true), None)?
.list_unspent()?
.0
.into_iter()
.find(|utxo| utxo.script_pub_key == tracked_addr.script_pubkey())
.expect("must find the newly created utxo");
Expand All @@ -223,11 +222,9 @@ pub fn chained_mempool_tx_sync() -> anyhow::Result<()> {
utxo.amount - Amount::from_sat(1000),
)]
.into(),
None,
None,
)?;
let signed_tx = rpc_client
.sign_raw_transaction_with_wallet(tx_that_spends_unconfirmed.raw_hex(), None, None)?
.sign_raw_transaction_with_wallet(tx_that_spends_unconfirmed.raw_hex())?
.transaction()?;
let txid2 = rpc_client.send_raw_transaction(signed_tx.raw_hex())?;

Expand Down Expand Up @@ -271,26 +268,16 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
];

let _block_hashes = env.mine_blocks(101, None)?;
let txid1 = env.bitcoind.client.send_to_address(
&receive_address1,
Amount::from_sat(10000),
None,
None,
None,
None,
Some(1),
None,
)?;
let txid2 = env.bitcoind.client.send_to_address(
&receive_address0,
Amount::from_sat(20000),
None,
None,
None,
None,
Some(1),
None,
)?;
let txid1 = env
.bitcoind
.client
.send_to_address(&receive_address1, Amount::from_sat(10000))?
.txid();
let txid2 = env
.bitcoind
.client
.send_to_address(&receive_address0, Amount::from_sat(20000))?
.txid();
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block(Duration::from_secs(6))?;

Expand Down Expand Up @@ -337,7 +324,8 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
let tx_fee = env
.bitcoind
.client
.get_transaction(&tx.compute_txid(), None)
.get_transaction(&tx.compute_txid())?
.into
.expect("Tx must exist")
.fee
.expect("Fee must exist")
Expand Down Expand Up @@ -393,16 +381,11 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
.collect();

// Then receive coins on the 4th address.
let txid_4th_addr = env.bitcoind.client.send_to_address(
&addresses[3],
Amount::from_sat(10000),
None,
None,
None,
None,
Some(1),
None,
)?;
let txid_4th_addr = env
.bitcoind
.client
.send_to_address(&addresses[3], Amount::from_sat(10000))?
.txid()?;
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block(Duration::from_secs(6))?;

Expand Down Expand Up @@ -437,16 +420,11 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
assert_eq!(full_scan_update.last_active_indices[&0], 3);

// Now receive a coin on the last address.
let txid_last_addr = env.bitcoind.client.send_to_address(
&addresses[addresses.len() - 1],
Amount::from_sat(10000),
None,
None,
None,
None,
Some(1),
None,
)?;
let txid_last_addr = env
.bitcoind
.client
.send_to_address(&addresses[addresses.len() - 1], Amount::from_sat(10000))?
.txid()?;
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block(Duration::from_secs(6))?;

Expand Down Expand Up @@ -498,11 +476,7 @@ fn test_sync() -> anyhow::Result<()> {
let client = BdkElectrumClient::new(electrum_client);

// Setup addresses.
let addr_to_mine = env
.bitcoind
.client
.get_new_address(None, None)?
.assume_checked();
let addr_to_mine = env.bitcoind.client.new_address()?;
let spk_to_track = ScriptBuf::new_p2wsh(&WScriptHash::all_zeros());
let addr_to_track = Address::from_script(&spk_to_track, bdk_chain::bitcoin::Network::Regtest)?;

Expand Down Expand Up @@ -610,7 +584,7 @@ fn test_sync() -> anyhow::Result<()> {
let tx_fee = env
.bitcoind
.client
.get_transaction(&tx.txid, None)
.get_transaction(&tx.txid)?
.expect("Tx must exist")
.fee
.expect("Fee must exist")
Expand Down Expand Up @@ -641,16 +615,13 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
let client = BdkElectrumClient::new(electrum_client);

// Setup addresses.
let addr_to_mine = env
.bitcoind
.client
.get_new_address(None, None)?
.assume_checked();
let addr_to_mine = env.bitcoind.client.new_address()?;
let spk_to_track = ScriptBuf::new_p2wsh(&WScriptHash::all_zeros());
let addr_to_track = Address::from_script(&spk_to_track, bdk_chain::bitcoin::Network::Regtest)?;

// Setup receiver.
let (mut recv_chain, _) = LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?);
let (mut recv_chain, _) =
LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?.block_hash()?);
let mut recv_graph = IndexedTxGraph::<ConfirmationBlockTime, _>::new({
let mut recv_index = SpkTxOutIndex::default();
recv_index.insert_spk((), spk_to_track.clone());
Expand Down Expand Up @@ -737,7 +708,8 @@ fn test_sync_with_coinbase() -> anyhow::Result<()> {
let addr_to_track = Address::from_script(&spk_to_track, bdk_chain::bitcoin::Network::Regtest)?;

// Setup receiver.
let (mut recv_chain, _) = LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?);
let (mut recv_chain, _) =
LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?.block_hash()?);
let mut recv_graph = IndexedTxGraph::<ConfirmationBlockTime, _>::new({
let mut recv_index = SpkTxOutIndex::default();
recv_index.insert_spk((), spk_to_track.clone());
Expand Down Expand Up @@ -772,7 +744,8 @@ fn test_check_fee_calculation() -> anyhow::Result<()> {
let addr_to_track = Address::from_script(&spk_to_track, bdk_chain::bitcoin::Network::Regtest)?;

// Setup receiver.
let (mut recv_chain, _) = LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?);
let (mut recv_chain, _) =
LocalChain::from_genesis_hash(env.bitcoind.client.get_block_hash(0)?.block_hash()?);
let mut recv_graph = IndexedTxGraph::<ConfirmationBlockTime, _>::new({
let mut recv_index = SpkTxOutIndex::default();
recv_index.insert_spk((), spk_to_track.clone());
Expand All @@ -784,10 +757,7 @@ fn test_check_fee_calculation() -> anyhow::Result<()> {

// Send a preliminary tx such that the new utxo in Core's wallet
// becomes the input of the next tx
let new_addr = env
.rpc_client()
.get_new_address(None, None)?
.assume_checked();
let new_addr = env.rpc_client().new_address()?;
let prev_amt = SEND_AMOUNT + FEE_AMOUNT;
env.send(&new_addr, prev_amt)?;
let prev_block_hash = env.mine_blocks(1, None)?.into_iter().next();
Expand Down Expand Up @@ -864,11 +834,12 @@ fn test_check_fee_calculation() -> anyhow::Result<()> {
let tx_fee = env
.bitcoind
.client
.get_transaction(&tx.txid, None)
.get_transaction(tx.txid)
.expect("Tx must exist")
.fee
.map(|fee| Amount::from_float_in(fee.abs(), Denomination::BTC))
.expect("Fee must exist")
.abs()
.expect("Amount parsing should succeed")
.to_sat() as u64;

// Check that the calculated fee matches the fee from the transaction data.
Expand Down
14 changes: 11 additions & 3 deletions crates/esplora/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ mod test {
BlockId,
};
use bdk_core::ConfirmationBlockTime;
use bdk_testenv::{anyhow, bitcoincore_rpc::RpcApi, TestEnv};
use bdk_testenv::{anyhow, TestEnv};
use esplora_client::Builder;

use crate::async_ext::{chain_update, fetch_latest_blocks};
Expand Down Expand Up @@ -626,7 +626,11 @@ mod test {
ConfirmationBlockTime {
block_id: BlockId {
height,
hash: env.bitcoind.client.get_block_hash(height as _)?,
hash: env
.bitcoind
.client
.get_block_hash(height as _)?
.block_hash()?,
},
confirmation_time: height as _,
},
Expand Down Expand Up @@ -666,7 +670,11 @@ mod test {
ConfirmationBlockTime {
block_id: BlockId {
height,
hash: env.bitcoind.client.get_block_hash(height as _)?,
hash: env
.bitcoind
.client
.get_block_hash(height as _)?
.block_hash()?,
},
confirmation_time: height as _,
},
Expand Down
Loading
Loading