|
1 | 1 | use crate::tests::test_utils::expect_event;
|
2 | 2 | use crate::{Builder, Config, Error, Event};
|
3 | 3 |
|
4 |
| -use bitcoin::{Address, Amount, Txid}; |
| 4 | +use bitcoin::{Address, Amount, OutPoint, Txid}; |
5 | 5 | use bitcoind::bitcoincore_rpc::RpcApi;
|
6 | 6 | use electrsd::bitcoind::bitcoincore_rpc::bitcoincore_rpc_json::AddressType;
|
7 | 7 | use electrsd::{bitcoind, bitcoind::BitcoinD, ElectrsD};
|
@@ -83,6 +83,22 @@ fn wait_for_tx(txid: Txid) {
|
83 | 83 | }
|
84 | 84 | }
|
85 | 85 |
|
| 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 | + |
86 | 102 | fn exponential_backoff_poll<T, F>(mut poll: F) -> T
|
87 | 103 | where
|
88 | 104 | F: FnMut() -> Option<T>,
|
@@ -254,8 +270,7 @@ fn channel_full_cycle() {
|
254 | 270 | expect_event!(node_a, ChannelClosed);
|
255 | 271 | expect_event!(node_b, ChannelClosed);
|
256 | 272 |
|
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()); |
259 | 274 |
|
260 | 275 | generate_blocks_and_wait(1);
|
261 | 276 | node_a.sync_wallets().unwrap();
|
|
0 commit comments