From 0c7cb969bfafb29e4a9f1d47ae180c0632f7b3a0 Mon Sep 17 00:00:00 2001 From: tsk Date: Wed, 28 Oct 2026 20:45:53 +0000 Subject: [PATCH] test: synchronize peers before the second splice Wait for the LSP to observe splice negotiation and for Electrum to index the splice transaction before mining confirmations. Sync both wallets and wait for both peers to use the new funding output before starting splice-out. --- orange-sdk/tests/integration_tests.rs | 16 ++++++++++++++++ orange-sdk/tests/test_utils.rs | 24 ++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/orange-sdk/tests/integration_tests.rs b/orange-sdk/tests/integration_tests.rs index 7fd4361..092df50 100644 --- a/orange-sdk/tests/integration_tests.rs +++ b/orange-sdk/tests/integration_tests.rs @@ -1071,8 +1071,24 @@ async fn test_concurrent_splice_in_and_out_preserve_pending_events() { ev => panic!("Expected first SplicePending event, got {ev:?}"), }; + // Regtest can confirm immediately, before the peer processes our signatures. + // Wait for both sides to negotiate before mining the splice transaction. + test_utils::wait_for_condition("LSP splice-in negotiation", || async { + params.lsp_splices.lock().unwrap().contains(&first_splice.1) + }) + .await; + wait_for_tx(&electrsd.client, first_splice.1.txid).await; generate_blocks(&bitcoind, &electrsd, 6).await; wallet.sync_ln_wallet().unwrap(); + lsp.sync_wallets().unwrap(); + test_utils::wait_for_condition("splice-in locked on both peers", || async { + wallet.channels().iter().any(|c| c.funding_txo == Some(first_splice.1) && c.is_usable) + && lsp + .list_channels() + .iter() + .any(|c| c.funding_txo == Some(first_splice.1) && c.is_usable) + }) + .await; let addr = third_party.onchain_payment().new_address().unwrap(); let send_amount = Amount::from_sats(10_000).unwrap(); diff --git a/orange-sdk/tests/test_utils.rs b/orange-sdk/tests/test_utils.rs index 9eb2e25..846634e 100644 --- a/orange-sdk/tests/test_utils.rs +++ b/orange-sdk/tests/test_utils.rs @@ -154,7 +154,10 @@ pub async fn generate_blocks(bitcoind: &Bitcoind, electrs: &ElectrsD, num: usize wait_for_block(&electrs.client, cur_height as usize + num).await; } -fn create_lsp(uuid: Uuid, bitcoind: &Bitcoind) -> Arc { +fn create_lsp( + uuid: Uuid, bitcoind: &Bitcoind, + splices: Arc>>, +) -> Arc { let mut config = ldk_node::config::Config::default(); config.anchor_channels_config.enable_zero_fee_commitments = true; let mut builder = ldk_node::Builder::from_config(config); @@ -206,6 +209,9 @@ fn create_lsp(uuid: Uuid, bitcoind: &Bitcoind) -> Arc { loop { let event = events_ref.next_event_async().await; println!("LSP: {event:?}"); + if let ldk_node::Event::SpliceNegotiated { new_funding_txo, .. } = &event { + splices.lock().unwrap().push(*new_funding_txo); + } if let Err(e) = events_ref.event_handled() { eprintln!("Error handling LSP ldk event: {e}"); } @@ -282,6 +288,7 @@ async fn fund_two_nodes(a: &Node, b: &Node, bitcoind: &Bitcoind, electrsd: &Elec pub struct TestParams { pub wallet: Arc, pub lsp: Arc, + pub lsp_splices: Arc>>, pub third_party: Arc, pub bitcoind: Arc, pub electrsd: Arc, @@ -437,7 +444,8 @@ async fn build_test_nodes() -> TestParams { let (bitcoind, electrsd) = create_bitcoind(test_id).await; log::info!("creating LSP and third-party nodes for {test_id}"); - let lsp = create_lsp(test_id, &bitcoind); + let lsp_splices = Arc::new(std::sync::Mutex::new(Vec::new())); + let lsp = create_lsp(test_id, &bitcoind, Arc::clone(&lsp_splices)); let third_party = create_third_party(test_id, &bitcoind); let start_bal = third_party.list_balances().total_onchain_balance_sats; log::info!("funding LSP and third-party nodes for {test_id}"); @@ -659,13 +667,21 @@ async fn build_test_nodes() -> TestParams { let wallet = Arc::new(Wallet::new(wallet_config).await.unwrap()); log::info!("finished building test nodes for {test_id}"); - return TestParams { wallet, lsp, third_party, bitcoind, electrsd, _mint: mint }; + return TestParams { + wallet, + lsp, + lsp_splices, + third_party, + bitcoind, + electrsd, + _mint: mint, + }; }; #[cfg(not(feature = "_cashu-tests"))] { log::info!("finished building test nodes for {test_id}"); - TestParams { wallet, lsp, third_party, bitcoind, electrsd } + TestParams { wallet, lsp, lsp_splices, third_party, bitcoind, electrsd } } }