@@ -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 {
@@ -795,8 +813,8 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
795813 node_b_anchor_reserve_sat
796814 ) ;
797815
798- let user_channel_id = expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
799- expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
816+ let user_channel_id_a = expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
817+ let user_channel_id_b = expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
800818
801819 println ! ( "\n B receive" ) ;
802820 let invoice_amount_1_msat = 2500_000 ;
@@ -1085,12 +1103,57 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
10851103 1
10861104 ) ;
10871105
1106+ println ! ( "\n B splices out to pay A" ) ;
1107+ let addr_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
1108+ let splice_out_sat = funding_amount_sat / 2 ;
1109+ node_b. splice_out ( & user_channel_id_b, node_a. node_id ( ) , & addr_a, splice_out_sat) . unwrap ( ) ;
1110+
1111+ expect_splice_pending_event ! ( node_a, node_b. node_id( ) ) ;
1112+ expect_splice_pending_event ! ( node_b, node_a. node_id( ) ) ;
1113+
1114+ generate_blocks_and_wait ( & bitcoind, electrsd, 6 ) . await ;
1115+ node_a. sync_wallets ( ) . unwrap ( ) ;
1116+ node_b. sync_wallets ( ) . unwrap ( ) ;
1117+
1118+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
1119+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
1120+
1121+ assert_eq ! (
1122+ node_a
1123+ . list_payments_with_filter( |p| p. direction == PaymentDirection :: Inbound
1124+ && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
1125+ . len( ) ,
1126+ 2
1127+ ) ;
1128+
1129+ println ! ( "\n A splices in the splice-out payment from B" ) ;
1130+ let splice_in_sat = splice_out_sat;
1131+ node_a. splice_in ( & user_channel_id_a, node_b. node_id ( ) , splice_in_sat) . unwrap ( ) ;
1132+
1133+ expect_splice_pending_event ! ( node_a, node_b. node_id( ) ) ;
1134+ expect_splice_pending_event ! ( node_b, node_a. node_id( ) ) ;
1135+
1136+ generate_blocks_and_wait ( & bitcoind, electrsd, 6 ) . await ;
1137+ node_a. sync_wallets ( ) . unwrap ( ) ;
1138+ node_b. sync_wallets ( ) . unwrap ( ) ;
1139+
1140+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
1141+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
1142+
1143+ assert_eq ! (
1144+ node_a
1145+ . list_payments_with_filter( |p| p. direction == PaymentDirection :: Outbound
1146+ && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
1147+ . len( ) ,
1148+ 2
1149+ ) ;
1150+
10881151 println ! ( "\n B close_channel (force: {})" , force_close) ;
10891152 if force_close {
10901153 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
1091- node_a. force_close_channel ( & user_channel_id , node_b. node_id ( ) , None ) . unwrap ( ) ;
1154+ node_a. force_close_channel ( & user_channel_id_a , node_b. node_id ( ) , None ) . unwrap ( ) ;
10921155 } else {
1093- node_a. close_channel ( & user_channel_id , node_b. node_id ( ) ) . unwrap ( ) ;
1156+ node_a. close_channel ( & user_channel_id_a , node_b. node_id ( ) ) . unwrap ( ) ;
10941157 }
10951158
10961159 expect_event ! ( node_a, ChannelClosed ) ;
@@ -1189,7 +1252,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11891252 + invoice_amount_3_msat
11901253 + determined_amount_msat
11911254 + keysend_amount_msat)
1192- / 1000 ;
1255+ / 1000 - splice_out_sat ;
11931256 let node_a_upper_bound_sat =
11941257 ( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
11951258 let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
@@ -1210,7 +1273,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
12101273 . list_payments_with_filter( |p| p. direction == PaymentDirection :: Inbound
12111274 && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
12121275 . len( ) ,
1213- 2
1276+ 3
12141277 ) ;
12151278 assert_eq ! (
12161279 node_b
0 commit comments