Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] Add neg test for splice_channel with insufficient inputs #3674

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions lightning/src/ln/splicing_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use crate::ln::functional_test_utils::*;
use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, MessageSendEvent};
use crate::util::errors::APIError;

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

// Instantiate channel parameters where we push the maximum msats given our funding satoshis
let channel_value_sat = 100_000; // same as funding satoshis
let push_msat = 0;
let channel_value_sat = 100_000;
let channel_reserve_amnt_sat = 1_000;

let (_, _, channel_id, _) = create_announced_chan_between_nodes_with_value(
&nodes,
initiator_node_index,
acceptor_node_index,
channel_value_sat,
push_msat,
0, // push_msat,
);

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

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

// Amount being added to the channel through the splice-in
let splice_in_sats: u64 = 20000;
let funding_feerate_per_kw = 1024; // TODO
let splice_in_sats = 20_000;
let funding_feerate_per_kw = 1024;

// Create additional inputs
let extra_splice_funding_input_sats = 35_000;
let funding_inputs = create_dual_funding_utxos_with_prev_txs(
&initiator_node,
&[extra_splice_funding_input_sats],
);
// Initiate splice-in (on initiator_node)
// Initiate splice-in
let _res = initiator_node
.node
.splice_channel(
Expand All @@ -74,7 +72,7 @@ fn test_v1_splice_in() {
None, // locktime
)
.unwrap();
// Extract the splice message from node0 to node1
// Extract the splice_init message
let splice_init_msg = get_event_msg!(
initiator_node,
MessageSendEvent::SendSpliceInit,
Expand All @@ -88,7 +86,7 @@ fn test_v1_splice_in() {
let _res = acceptor_node
.node
.handle_splice_init(initiator_node.node.get_our_node_id(), &splice_init_msg);
// Extract the splice_ack message from node1 to node0
// Extract the splice_ack message
let splice_ack_msg = get_event_msg!(
acceptor_node,
MessageSendEvent::SendSpliceAck,
Expand Down Expand Up @@ -157,3 +155,38 @@ fn test_v1_splice_in() {
acceptor_node.node.get_our_node_id()
);
}

#[test]
fn test_v1_splice_in_negative_insufficient_inputs() {
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, _, channel_id, _) =
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 0);

// Amount being added to the channel through the splice-in
let splice_in_sats = 20_000;

// Create additional inputs, but insufficient
let extra_splice_funding_input_sats = splice_in_sats - 1;
let funding_inputs =
create_dual_funding_utxos_with_prev_txs(&nodes[0], &[extra_splice_funding_input_sats]);

// Initiate splice-in, with insufficient input contribution
let res = nodes[0].node.splice_channel(
&channel_id,
&nodes[1].node.get_our_node_id(),
splice_in_sats as i64,
funding_inputs,
1024, // funding_feerate_per_kw,
None, // locktime
);
match res {
Err(APIError::APIMisuseError { err }) => {
assert!(err.contains("Insufficient inputs for splicing"))
},
_ => panic!("Wrong error {:?}", res.err().unwrap()),
}
}
Loading