@@ -310,21 +310,24 @@ async fn test_sweep_to_ln() {
310310
311311 let expect_amt = intermediate_amt. saturating_add ( recv_amt) ;
312312
313- let event = wait_next_event ( & wallet) . await ;
314- match event {
313+ let received_rebalance_amount = match wait_next_event ( & wallet) . await {
315314 Event :: PaymentReceived { payment_id, amount_msat, lsp_fee_msats, .. } => {
316315 assert ! ( matches!( payment_id, orange_sdk:: PaymentId :: SelfCustodial ( _) ) ) ;
317- assert ! ( lsp_fee_msats. is_some( ) ) ;
318- assert_eq ! ( amount_msat, expect_amt. milli_sats( ) - lsp_fee_msats. unwrap( ) ) ;
316+ let lsp_fee_msats = lsp_fee_msats. expect ( "rebalance receive should pay LSP fee" ) ;
317+ assert ! (
318+ amount_msat + lsp_fee_msats <= expect_amt. milli_sats( ) ,
319+ "rebalance receive should not exceed trusted balance after fees"
320+ ) ;
321+ amount_msat + lsp_fee_msats
319322 } ,
320323 e => panic ! ( "Expected RebalanceSuccessful event, got {e:?}" ) ,
321- }
324+ } ;
322325
323326 let event = wait_next_event ( & wallet) . await ;
324327 match event {
325328 Event :: RebalanceSuccessful { amount_msat, fee_msat, .. } => {
326329 assert ! ( fee_msat > 0 ) ;
327- assert_eq ! ( amount_msat, expect_amt . milli_sats ( ) ) ;
330+ assert_eq ! ( amount_msat, received_rebalance_amount ) ;
328331 } ,
329332 e => panic ! ( "Expected RebalanceSuccessful event, got {e:?}" ) ,
330333 }
@@ -786,9 +789,12 @@ async fn test_receive_to_onchain_with_channel() {
786789
787790 // check we received on-chain, should be pending
788791 // wait for payment success
789- test_utils:: wait_for_condition ( "pending balance to update" , || async {
790- // onchain balance is always listed as pending until we splice it into the channel.
792+ test_utils:: wait_for_condition ( "onchain receive to appear" , || async {
791793 wallet. get_balance ( ) . await . unwrap ( ) . pending_balance == recv_amt
794+ || wallet. list_transactions ( ) . await . unwrap ( ) . iter ( ) . any ( |tx| {
795+ tx. payment_type == PaymentType :: IncomingOnChain { txid : Some ( sent_txid) }
796+ && tx. amount == Some ( recv_amt)
797+ } )
792798 } )
793799 . await ;
794800
@@ -886,8 +892,12 @@ async fn test_concurrent_splice_in_and_out_preserve_pending_events() {
886892 generate_blocks ( & bitcoind, & electrsd, 6 ) . await ;
887893 wallet. sync_ln_wallet ( ) . unwrap ( ) ;
888894
889- test_utils:: wait_for_condition ( "pending balance to update " , || async {
895+ test_utils:: wait_for_condition ( "onchain receive to appear " , || async {
890896 wallet. get_balance ( ) . await . unwrap ( ) . pending_balance == recv_amt
897+ || wallet. list_transactions ( ) . await . unwrap ( ) . iter ( ) . any ( |tx| {
898+ tx. payment_type == PaymentType :: IncomingOnChain { txid : Some ( sent_txid) }
899+ && tx. amount == Some ( recv_amt)
900+ } )
891901 } )
892902 . await ;
893903
0 commit comments