Skip to content

Commit adb59c8

Browse files
committed
f - WIP test splicing in do_channel_full_cycle
1 parent 6b963fe commit adb59c8

File tree

2 files changed

+81
-26
lines changed

2 files changed

+81
-26
lines changed

tests/common/mod.rs

Lines changed: 77 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 {
@@ -761,8 +779,8 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
761779
node_b_anchor_reserve_sat
762780
);
763781

764-
let user_channel_id = expect_channel_ready_event!(node_a, node_b.node_id());
765-
expect_channel_ready_event!(node_b, node_a.node_id());
782+
let user_channel_id_a = expect_channel_ready_event!(node_a, node_b.node_id());
783+
let user_channel_id_b = expect_channel_ready_event!(node_b, node_a.node_id());
766784

767785
println!("\nB receive");
768786
let invoice_amount_1_msat = 2500_000;
@@ -1051,12 +1069,65 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
10511069
1
10521070
);
10531071

1072+
println!("\nB splices out to pay A");
1073+
let addr_a = node_a.onchain_payment().new_address().unwrap();
1074+
let splice_out_sat = funding_amount_sat / 2;
1075+
node_b.splice_out(&user_channel_id_b, node_a.node_id(), addr_a, splice_out_sat).unwrap();
1076+
1077+
expect_splice_pending_event!(node_a, node_b.node_id());
1078+
expect_splice_pending_event!(node_b, node_a.node_id());
1079+
1080+
generate_blocks_and_wait(&bitcoind, electrsd, 6).await;
1081+
node_a.sync_wallets().unwrap();
1082+
node_b.sync_wallets().unwrap();
1083+
1084+
expect_channel_ready_event!(node_a, node_b.node_id());
1085+
expect_channel_ready_event!(node_b, node_a.node_id());
1086+
1087+
assert_eq!(
1088+
node_a
1089+
.list_payments_with_filter(|p| p.direction == PaymentDirection::Inbound
1090+
&& matches!(p.kind, PaymentKind::Onchain { .. }))
1091+
.len(),
1092+
2
1093+
);
1094+
// FIXME: Should a splice-out be considered an outbound onchain payment?
1095+
//assert_eq!(
1096+
// node_b
1097+
// .list_payments_with_filter(|p| p.direction == PaymentDirection::Outbound
1098+
// && matches!(p.kind, PaymentKind::Onchain { .. }))
1099+
// .len(),
1100+
// 1
1101+
//);
1102+
1103+
println!("\nA splices in the splice-out payment from B");
1104+
let splice_in_sat = splice_out_sat;
1105+
node_a.splice_in(&user_channel_id_a, node_b.node_id(), splice_in_sat).unwrap();
1106+
1107+
expect_splice_pending_event!(node_a, node_b.node_id());
1108+
expect_splice_pending_event!(node_b, node_a.node_id());
1109+
1110+
generate_blocks_and_wait(&bitcoind, electrsd, 6).await;
1111+
node_a.sync_wallets().unwrap();
1112+
node_b.sync_wallets().unwrap();
1113+
1114+
expect_channel_ready_event!(node_a, node_b.node_id());
1115+
expect_channel_ready_event!(node_b, node_a.node_id());
1116+
1117+
assert_eq!(
1118+
node_a
1119+
.list_payments_with_filter(|p| p.direction == PaymentDirection::Outbound
1120+
&& matches!(p.kind, PaymentKind::Onchain { .. }))
1121+
.len(),
1122+
2
1123+
);
1124+
10541125
println!("\nB close_channel (force: {})", force_close);
10551126
if force_close {
10561127
tokio::time::sleep(Duration::from_secs(1)).await;
1057-
node_a.force_close_channel(&user_channel_id, node_b.node_id(), None).unwrap();
1128+
node_a.force_close_channel(&user_channel_id_a, node_b.node_id(), None).unwrap();
10581129
} else {
1059-
node_a.close_channel(&user_channel_id, node_b.node_id()).unwrap();
1130+
node_a.close_channel(&user_channel_id_a, node_b.node_id()).unwrap();
10601131
}
10611132

10621133
expect_event!(node_a, ChannelClosed);
@@ -1155,7 +1226,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11551226
+ invoice_amount_3_msat
11561227
+ determined_amount_msat
11571228
+ keysend_amount_msat)
1158-
/ 1000;
1229+
/ 1000 - splice_out_sat;
11591230
let node_a_upper_bound_sat =
11601231
(premine_amount_sat - funding_amount_sat) + (funding_amount_sat - sum_of_all_payments_sat);
11611232
let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
@@ -1176,7 +1247,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11761247
.list_payments_with_filter(|p| p.direction == PaymentDirection::Inbound
11771248
&& matches!(p.kind, PaymentKind::Onchain { .. }))
11781249
.len(),
1179-
2
1250+
3
11801251
);
11811252
assert_eq!(
11821253
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)