From: chaitika Date: Sat, 26 Sep 2026 15:17:41 +0000 (+0530) Subject: test(electrum): cover transport errors when syncing outpoints X-Git-Url: http://internal-gitweb-vhost/-script/src/example_cli/database/struct.AddrsOutput.html?a=commitdiff_plain;h=edbf4a38847f0fc96f7aad72fbda0221d9c7e063;p=bdk test(electrum): cover transport errors when syncing outpoints Add a regression test: syncing an outpoint against a server that drops the connection must return an error instead of an empty successful update. --- diff --git a/crates/electrum/tests/test_electrum.rs b/crates/electrum/tests/test_electrum.rs index d0632db4..75e806f1 100644 --- a/crates/electrum/tests/test_electrum.rs +++ b/crates/electrum/tests/test_electrum.rs @@ -1,5 +1,5 @@ use bdk_chain::{ - bitcoin::{hashes::Hash, Address, Amount, ScriptBuf, WScriptHash}, + bitcoin::{hashes::Hash, Address, Amount, OutPoint, ScriptBuf, Txid, WScriptHash}, local_chain::LocalChain, spk_client::{FullScanRequest, SyncRequest, SyncResponse}, spk_txout::SpkTxOutIndex, @@ -934,3 +934,26 @@ fn test_check_fee_calculation() -> anyhow::Result<()> { } Ok(()) } + +/// Syncing outpoints must report network errors instead of silently skipping the outpoint. +#[test] +fn test_sync_outpoints_propagates_connection_error() -> anyhow::Result<()> { + // A "server" that accepts connections and closes them immediately. + let listener = std::net::TcpListener::bind("127.0.0.1:0")?; + let url = format!("tcp://{}", listener.local_addr()?); + std::thread::spawn(move || listener.incoming().for_each(drop)); + + let config = electrum_client::ConfigBuilder::new().retry(0).build(); + let client = BdkElectrumClient::new(electrum_client::Client::from_config(&url, config)?); + + let outpoint = OutPoint::new(Txid::from_byte_array([1; 32]), 0); + let request = SyncRequest::<()>::builder().outpoints([outpoint]).build(); + let result = client.sync(request, BATCH_SIZE, false); + + assert!( + result.is_err(), + "sync dropped the outpoint and returned {result:?}" + ); + + Ok(()) +}