]> Untitled Git - bdk/commitdiff
test(electrum): cover transport errors when syncing outpoints
authorchaitika <chaitikab@gmail.com>
Sat, 26 Sep 2026 15:17:41 +0000 (20:47 +0530)
committerchaitika <chaitikab@gmail.com>
Sat, 26 Sep 2026 15:26:29 +0000 (20:56 +0530)
Add a regression test: syncing an outpoint against a server that drops
the connection must return an error instead of an empty successful
update.

crates/electrum/tests/test_electrum.rs

index d0632db422a2fcff02c908af474e1bb7fc9789ba..75e806f11e8a9128c21f79a78857a9afa3b0b2ee 100644 (file)
@@ -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(())
+}