Skip to content

Commit 4bfb26f

Browse files
committed
Test splicing in do_channel_full_cycle
1 parent 68f0d4d commit 4bfb26f

File tree

2 files changed

+73
-26
lines changed

2 files changed

+73
-26
lines changed

tests/common/mod.rs

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ macro_rules! expect_channel_ready_event {
9999

100100
pub(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+
102120
macro_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!("\nB 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!("\nB 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!("\nA 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!("\nB 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

tests/integration_tests_rust.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use common::{
2020
bump_fee_and_broadcast, distribute_funds_unconfirmed, do_channel_full_cycle,
2121
expect_channel_pending_event, expect_channel_ready_event, expect_event,
2222
expect_payment_claimable_event, expect_payment_received_event, expect_payment_successful_event,
23-
generate_blocks_and_wait, open_channel, open_channel_push_amt, premine_and_distribute_funds,
24-
premine_blocks, prepare_rbf, random_config, random_listening_addresses,
25-
setup_bitcoind_and_electrsd, setup_builder, setup_node, setup_node_for_async_payments,
26-
setup_two_nodes, wait_for_tx, TestChainSource, TestSyncStore,
23+
expect_splice_pending_event, generate_blocks_and_wait, open_channel, open_channel_push_amt,
24+
premine_and_distribute_funds, premine_blocks, prepare_rbf, random_config,
25+
random_listening_addresses, setup_bitcoind_and_electrsd, setup_builder, setup_node,
26+
setup_node_for_async_payments, setup_two_nodes, wait_for_tx, TestChainSource, TestSyncStore,
2727
};
2828
use ldk_node::config::{AsyncPaymentsRole, EsploraSyncConfig};
2929
use ldk_node::liquidity::LSPS2ServiceConfig;
@@ -927,22 +927,6 @@ async fn concurrent_connections_succeed() {
927927

928928
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
929929
async fn splice_channel() {
930-
macro_rules! expect_splice_pending_event {
931-
($node: expr, $counterparty_node_id: expr) => {{
932-
match $node.next_event_async().await {
933-
ref e @ Event::SplicePending { new_funding_txo, counterparty_node_id, .. } => {
934-
println!("{} got event {:?}", $node.node_id(), e);
935-
assert_eq!(counterparty_node_id, $counterparty_node_id);
936-
$node.event_handled().unwrap();
937-
new_funding_txo
938-
},
939-
ref e => {
940-
panic!("{} got unexpected event!: {:?}", std::stringify!($node), e);
941-
},
942-
}
943-
}};
944-
}
945-
946930
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
947931
let chain_source = TestChainSource::Esplora(&electrsd);
948932
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);

0 commit comments

Comments
 (0)