Skip to content

Commit 39d33f1

Browse files
committed
f Wait for funding txo spend
1 parent 9373729 commit 39d33f1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/tests/functional_tests.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::tests::test_utils::expect_event;
22
use crate::{Builder, Config, Error, Event};
33

4-
use bitcoin::{Address, Amount, Txid};
4+
use bitcoin::{Address, Amount, OutPoint, Txid};
55
use bitcoind::bitcoincore_rpc::RpcApi;
66
use electrsd::bitcoind::bitcoincore_rpc::bitcoincore_rpc_json::AddressType;
77
use electrsd::{bitcoind, bitcoind::BitcoinD, ElectrsD};
@@ -83,6 +83,22 @@ fn wait_for_tx(txid: Txid) {
8383
}
8484
}
8585

86+
fn wait_for_outpoint_spend(outpoint: OutPoint) {
87+
let tx = get_electrsd().client.transaction_get(&outpoint.txid).unwrap();
88+
let txout_script = tx.output.get(outpoint.vout as usize).unwrap().clone().script_pubkey;
89+
let mut is_spent = !get_electrsd().client.script_get_history(&txout_script).unwrap().is_empty();
90+
loop {
91+
if is_spent {
92+
break;
93+
}
94+
is_spent = exponential_backoff_poll(|| {
95+
get_electrsd().trigger().unwrap();
96+
get_electrsd().client.ping().unwrap();
97+
Some(!get_electrsd().client.script_get_history(&txout_script).unwrap().is_empty())
98+
});
99+
}
100+
}
101+
86102
fn exponential_backoff_poll<T, F>(mut poll: F) -> T
87103
where
88104
F: FnMut() -> Option<T>,
@@ -254,8 +270,7 @@ fn channel_full_cycle() {
254270
expect_event!(node_a, ChannelClosed);
255271
expect_event!(node_b, ChannelClosed);
256272

257-
// Wait a sec so the shutdown tx can 'propagate' via EsploraD to BitcoinD.
258-
std::thread::sleep(Duration::from_secs(1));
273+
wait_for_outpoint_spend(funding_txo.into_bitcoin_outpoint());
259274

260275
generate_blocks_and_wait(1);
261276
node_a.sync_wallets().unwrap();

0 commit comments

Comments
 (0)