Skip to content

Commit

Permalink
test(electrum): test populate_with_txids does not panic
Browse files Browse the repository at this point in the history
  • Loading branch information
LagginTimes committed Dec 4, 2024
1 parent f05bc69 commit 5bce448
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/electrum/src/bdk_electrum_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,30 @@ fn chain_update(
}
Ok(tip)
}

#[cfg(test)]
mod test {
use crate::{bdk_electrum_client::TxUpdate, BdkElectrumClient};
use bdk_testenv::{utils::new_tx, TestEnv};

#[cfg(feature = "default")]
#[test]
fn test_populate_with_txids_without_output() {
let env = TestEnv::new().unwrap();
let electrum_client =
electrum_client::Client::new(env.electrsd.electrum_url.as_str()).unwrap();
let client = BdkElectrumClient::new(electrum_client);

// Setup transaction with no outputs.
let tx = new_tx(0);

// Populate tx_cache with `tx` to make it fetchable.
client.populate_tx_cache(vec![tx.clone()]);

// Test that populate_with_txids does not panic or process a tx with no output.
let mut tx_update = TxUpdate::default();
let _ = client.populate_with_txids(&mut tx_update, vec![tx.compute_txid()]);

assert_eq!(tx_update.txs, Vec::new());
}
}

0 comments on commit 5bce448

Please sign in to comment.