@@ -99,6 +99,24 @@ macro_rules! expect_channel_ready_event {
9999
100100pub ( crate ) use expect_channel_ready_event;
101101
102+ macro_rules! expect_splice_pending_event {
103+ ( $node: expr, $counterparty_node_id: expr) => { {
104+ match $node. next_event_async( ) . await {
105+ ref e @ Event :: SplicePending { new_funding_txo, counterparty_node_id, .. } => {
106+ println!( "{} got event {:?}" , $node. node_id( ) , e) ;
107+ assert_eq!( counterparty_node_id, $counterparty_node_id) ;
108+ $node. event_handled( ) . unwrap( ) ;
109+ new_funding_txo
110+ } ,
111+ ref e => {
112+ panic!( "{} got unexpected event!: {:?}" , std:: stringify!( $node) , e) ;
113+ } ,
114+ }
115+ } } ;
116+ }
117+
118+ pub ( crate ) use expect_splice_pending_event;
119+
102120macro_rules! expect_payment_received_event {
103121 ( $node: expr, $amount_msat: expr) => { {
104122 match $node. next_event_async( ) . await {
@@ -761,8 +779,8 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
761779 node_b_anchor_reserve_sat
762780 ) ;
763781
764- let user_channel_id = expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
765- expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
782+ let user_channel_id_a = expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
783+ let user_channel_id_b = expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
766784
767785 println ! ( "\n B receive" ) ;
768786 let invoice_amount_1_msat = 2500_000 ;
@@ -1051,12 +1069,57 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
10511069 1
10521070 ) ;
10531071
1072+ println ! ( "\n B splices out to pay A" ) ;
1073+ let addr_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
1074+ let splice_out_sat = funding_amount_sat / 2 ;
1075+ node_b. splice_out ( & user_channel_id_b, node_a. node_id ( ) , & addr_a, splice_out_sat) . unwrap ( ) ;
1076+
1077+ expect_splice_pending_event ! ( node_a, node_b. node_id( ) ) ;
1078+ expect_splice_pending_event ! ( node_b, node_a. node_id( ) ) ;
1079+
1080+ generate_blocks_and_wait ( & bitcoind, electrsd, 6 ) . await ;
1081+ node_a. sync_wallets ( ) . unwrap ( ) ;
1082+ node_b. sync_wallets ( ) . unwrap ( ) ;
1083+
1084+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
1085+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
1086+
1087+ assert_eq ! (
1088+ node_a
1089+ . list_payments_with_filter( |p| p. direction == PaymentDirection :: Inbound
1090+ && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
1091+ . len( ) ,
1092+ 2
1093+ ) ;
1094+
1095+ println ! ( "\n A splices in the splice-out payment from B" ) ;
1096+ let splice_in_sat = splice_out_sat;
1097+ node_a. splice_in ( & user_channel_id_a, node_b. node_id ( ) , splice_in_sat) . unwrap ( ) ;
1098+
1099+ expect_splice_pending_event ! ( node_a, node_b. node_id( ) ) ;
1100+ expect_splice_pending_event ! ( node_b, node_a. node_id( ) ) ;
1101+
1102+ generate_blocks_and_wait ( & bitcoind, electrsd, 6 ) . await ;
1103+ node_a. sync_wallets ( ) . unwrap ( ) ;
1104+ node_b. sync_wallets ( ) . unwrap ( ) ;
1105+
1106+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
1107+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
1108+
1109+ assert_eq ! (
1110+ node_a
1111+ . list_payments_with_filter( |p| p. direction == PaymentDirection :: Outbound
1112+ && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
1113+ . len( ) ,
1114+ 2
1115+ ) ;
1116+
10541117 println ! ( "\n B close_channel (force: {})" , force_close) ;
10551118 if force_close {
10561119 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
1057- node_a. force_close_channel ( & user_channel_id , node_b. node_id ( ) , None ) . unwrap ( ) ;
1120+ node_a. force_close_channel ( & user_channel_id_a , node_b. node_id ( ) , None ) . unwrap ( ) ;
10581121 } else {
1059- node_a. close_channel ( & user_channel_id , node_b. node_id ( ) ) . unwrap ( ) ;
1122+ node_a. close_channel ( & user_channel_id_a , node_b. node_id ( ) ) . unwrap ( ) ;
10601123 }
10611124
10621125 expect_event ! ( node_a, ChannelClosed ) ;
@@ -1155,7 +1218,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11551218 + invoice_amount_3_msat
11561219 + determined_amount_msat
11571220 + keysend_amount_msat)
1158- / 1000 ;
1221+ / 1000 - splice_out_sat ;
11591222 let node_a_upper_bound_sat =
11601223 ( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
11611224 let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
@@ -1176,7 +1239,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11761239 . list_payments_with_filter( |p| p. direction == PaymentDirection :: Inbound
11771240 && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
11781241 . len( ) ,
1179- 2
1242+ 3
11801243 ) ;
11811244 assert_eq ! (
11821245 node_b
0 commit comments