9
9
10
10
use crate :: ln:: functional_test_utils:: * ;
11
11
use crate :: ln:: msgs:: { BaseMessageHandler , ChannelMessageHandler , MessageSendEvent } ;
12
+ use crate :: util:: errors:: APIError ;
12
13
13
14
/// Splicing test, simple splice-in flow. Starts with opening a V1 channel first.
14
15
/// Builds on test_channel_open_simple()
@@ -25,17 +26,15 @@ fn test_v1_splice_in() {
25
26
let initiator_node = & nodes[ initiator_node_index] ;
26
27
let acceptor_node = & nodes[ acceptor_node_index] ;
27
28
28
- // Instantiate channel parameters where we push the maximum msats given our funding satoshis
29
- let channel_value_sat = 100_000 ; // same as funding satoshis
30
- let push_msat = 0 ;
29
+ let channel_value_sat = 100_000 ;
31
30
let channel_reserve_amnt_sat = 1_000 ;
32
31
33
32
let ( _, _, channel_id, _) = create_announced_chan_between_nodes_with_value (
34
33
& nodes,
35
34
initiator_node_index,
36
35
acceptor_node_index,
37
36
channel_value_sat,
38
- push_msat,
37
+ 0 , // push_msat,
39
38
) ;
40
39
41
40
let expected_funded_channel_id =
@@ -50,19 +49,18 @@ fn test_v1_splice_in() {
50
49
// ==== Channel is now ready for normal operation
51
50
52
51
// === Start of Splicing
53
- println ! ( "Start of Splicing ..., channel_id {}" , channel_id) ;
54
52
55
53
// Amount being added to the channel through the splice-in
56
- let splice_in_sats: u64 = 20000 ;
57
- let funding_feerate_per_kw = 1024 ; // TODO
54
+ let splice_in_sats = 20_000 ;
55
+ let funding_feerate_per_kw = 1024 ;
58
56
59
57
// Create additional inputs
60
58
let extra_splice_funding_input_sats = 35_000 ;
61
59
let funding_inputs = create_dual_funding_utxos_with_prev_txs (
62
60
& initiator_node,
63
61
& [ extra_splice_funding_input_sats] ,
64
62
) ;
65
- // Initiate splice-in (on initiator_node)
63
+ // Initiate splice-in
66
64
let _res = initiator_node
67
65
. node
68
66
. splice_channel (
@@ -74,7 +72,7 @@ fn test_v1_splice_in() {
74
72
None , // locktime
75
73
)
76
74
. unwrap ( ) ;
77
- // Extract the splice message from node0 to node1
75
+ // Extract the splice_init message
78
76
let splice_init_msg = get_event_msg ! (
79
77
initiator_node,
80
78
MessageSendEvent :: SendSpliceInit ,
@@ -88,7 +86,7 @@ fn test_v1_splice_in() {
88
86
let _res = acceptor_node
89
87
. node
90
88
. handle_splice_init ( initiator_node. node . get_our_node_id ( ) , & splice_init_msg) ;
91
- // Extract the splice_ack message from node1 to node0
89
+ // Extract the splice_ack message
92
90
let splice_ack_msg = get_event_msg ! (
93
91
acceptor_node,
94
92
MessageSendEvent :: SendSpliceAck ,
@@ -157,3 +155,38 @@ fn test_v1_splice_in() {
157
155
acceptor_node. node. get_our_node_id( )
158
156
) ;
159
157
}
158
+
159
+ #[ test]
160
+ fn test_v1_splice_in_negative_insufficient_inputs ( ) {
161
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
162
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
163
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
164
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
165
+
166
+ let ( _, _, channel_id, _) =
167
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , 0 ) ;
168
+
169
+ // Amount being added to the channel through the splice-in
170
+ let splice_in_sats = 20_000 ;
171
+
172
+ // Create additional inputs, but insufficient
173
+ let extra_splice_funding_input_sats = splice_in_sats - 1 ;
174
+ let funding_inputs =
175
+ create_dual_funding_utxos_with_prev_txs ( & nodes[ 0 ] , & [ extra_splice_funding_input_sats] ) ;
176
+
177
+ // Initiate splice-in, with insufficient input contribution
178
+ let res = nodes[ 0 ] . node . splice_channel (
179
+ & channel_id,
180
+ & nodes[ 1 ] . node . get_our_node_id ( ) ,
181
+ splice_in_sats as i64 ,
182
+ funding_inputs,
183
+ 1024 , // funding_feerate_per_kw,
184
+ None , // locktime
185
+ ) ;
186
+ match res {
187
+ Err ( APIError :: APIMisuseError { err } ) => {
188
+ assert ! ( err. contains( "Insufficient inputs for splicing" ) )
189
+ } ,
190
+ _ => panic ! ( "Wrong error {:?}" , res. err( ) . unwrap( ) ) ,
191
+ }
192
+ }
0 commit comments