Skip to content

Commit 0721ba5

Browse files
authored
Merge pull request #3674 from optout21/splice-init-neg-test
[Test] Add neg test for splice_channel with insufficient inputs
2 parents ebdbee0 + a0fa32e commit 0721ba5

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

lightning/src/ln/splicing_tests.rs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use crate::ln::functional_test_utils::*;
1111
use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, MessageSendEvent};
12+
use crate::util::errors::APIError;
1213

1314
/// Splicing test, simple splice-in flow. Starts with opening a V1 channel first.
1415
/// Builds on test_channel_open_simple()
@@ -25,17 +26,15 @@ fn test_v1_splice_in() {
2526
let initiator_node = &nodes[initiator_node_index];
2627
let acceptor_node = &nodes[acceptor_node_index];
2728

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;
3130
let channel_reserve_amnt_sat = 1_000;
3231

3332
let (_, _, channel_id, _) = create_announced_chan_between_nodes_with_value(
3433
&nodes,
3534
initiator_node_index,
3635
acceptor_node_index,
3736
channel_value_sat,
38-
push_msat,
37+
0, // push_msat,
3938
);
4039

4140
let expected_funded_channel_id =
@@ -50,19 +49,18 @@ fn test_v1_splice_in() {
5049
// ==== Channel is now ready for normal operation
5150

5251
// === Start of Splicing
53-
println!("Start of Splicing ..., channel_id {}", channel_id);
5452

5553
// 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;
5856

5957
// Create additional inputs
6058
let extra_splice_funding_input_sats = 35_000;
6159
let funding_inputs = create_dual_funding_utxos_with_prev_txs(
6260
&initiator_node,
6361
&[extra_splice_funding_input_sats],
6462
);
65-
// Initiate splice-in (on initiator_node)
63+
// Initiate splice-in
6664
let _res = initiator_node
6765
.node
6866
.splice_channel(
@@ -74,7 +72,7 @@ fn test_v1_splice_in() {
7472
None, // locktime
7573
)
7674
.unwrap();
77-
// Extract the splice message from node0 to node1
75+
// Extract the splice_init message
7876
let splice_init_msg = get_event_msg!(
7977
initiator_node,
8078
MessageSendEvent::SendSpliceInit,
@@ -88,7 +86,7 @@ fn test_v1_splice_in() {
8886
let _res = acceptor_node
8987
.node
9088
.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
9290
let splice_ack_msg = get_event_msg!(
9391
acceptor_node,
9492
MessageSendEvent::SendSpliceAck,
@@ -157,3 +155,38 @@ fn test_v1_splice_in() {
157155
acceptor_node.node.get_our_node_id()
158156
);
159157
}
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

Comments
 (0)