Skip to content

Commit d0dfd93

Browse files
committed
Assert expected TransactionType in integration tests
Extend `channel_full_cycle`, `onchain_send_receive`, and `run_splice_channel_test` to verify that the `tx_type` field on `PaymentKind::Onchain` matches the expected variant (`Funding`, `OnchainSend`, `Splice`, or `None` for externally-received payments). Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent ddde930 commit d0dfd93

File tree

2 files changed

+77
-30
lines changed

2 files changed

+77
-30
lines changed

tests/common/mod.rs

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use electrum_client::ElectrumApi;
2929
use ldk_node::config::{AsyncPaymentsRole, Config, ElectrumSyncConfig, EsploraSyncConfig};
3030
use ldk_node::entropy::{generate_entropy_mnemonic, NodeEntropy};
3131
use ldk_node::io::sqlite_store::SqliteStore;
32-
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentStatus};
32+
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentStatus, TransactionType};
3333
use ldk_node::{
3434
Builder, CustomTlvRecord, Event, LightningBalance, Node, NodeError, PendingSweepBalance,
3535
};
@@ -765,14 +765,21 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
765765
node_a.sync_wallets().unwrap();
766766
node_b.sync_wallets().unwrap();
767767

768-
// Check we now see the channel funding transaction as outbound.
769-
assert_eq!(
770-
node_a
771-
.list_payments_with_filter(|p| p.direction == PaymentDirection::Outbound
772-
&& matches!(p.kind, PaymentKind::Onchain { .. }))
773-
.len(),
774-
1
775-
);
768+
// Check we now see the channel funding transaction as outbound with the correct type.
769+
let funding_payments_a = node_a.list_payments_with_filter(|p| {
770+
p.direction == PaymentDirection::Outbound && matches!(p.kind, PaymentKind::Onchain { .. })
771+
});
772+
assert_eq!(funding_payments_a.len(), 1);
773+
match funding_payments_a[0].kind {
774+
PaymentKind::Onchain { ref tx_type, .. } => {
775+
assert!(
776+
matches!(tx_type, Some(TransactionType::Funding { .. })),
777+
"Expected Funding transaction type, got {:?}",
778+
tx_type
779+
);
780+
},
781+
_ => panic!("Unexpected payment kind"),
782+
}
776783

777784
let onchain_fee_buffer_sat = 5000;
778785
let node_a_anchor_reserve_sat = if expect_anchor_channel { 25_000 } else { 0 };
@@ -1115,13 +1122,21 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11151122
expect_channel_ready_event!(node_a, node_b.node_id());
11161123
expect_channel_ready_event!(node_b, node_a.node_id());
11171124

1118-
assert_eq!(
1119-
node_a
1120-
.list_payments_with_filter(|p| p.direction == PaymentDirection::Inbound
1121-
&& matches!(p.kind, PaymentKind::Onchain { .. }))
1122-
.len(),
1123-
2
1124-
);
1125+
let inbound_onchain_a = node_a.list_payments_with_filter(|p| {
1126+
p.direction == PaymentDirection::Inbound && matches!(p.kind, PaymentKind::Onchain { .. })
1127+
});
1128+
assert_eq!(inbound_onchain_a.len(), 2);
1129+
// The second inbound on-chain payment should be from the splice-out.
1130+
match inbound_onchain_a[1].kind {
1131+
PaymentKind::Onchain { ref tx_type, .. } => {
1132+
assert!(
1133+
matches!(tx_type, Some(TransactionType::Splice { .. })),
1134+
"Expected Splice transaction type, got {:?}",
1135+
tx_type
1136+
);
1137+
},
1138+
_ => panic!("Unexpected payment kind"),
1139+
}
11251140

11261141
println!("\nA splices in the splice-out payment from B");
11271142
let splice_in_sat = splice_out_sat;
@@ -1137,13 +1152,21 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11371152
expect_channel_ready_event!(node_a, node_b.node_id());
11381153
expect_channel_ready_event!(node_b, node_a.node_id());
11391154

1140-
assert_eq!(
1141-
node_a
1142-
.list_payments_with_filter(|p| p.direction == PaymentDirection::Outbound
1143-
&& matches!(p.kind, PaymentKind::Onchain { .. }))
1144-
.len(),
1145-
2
1146-
);
1155+
let outbound_onchain_a = node_a.list_payments_with_filter(|p| {
1156+
p.direction == PaymentDirection::Outbound && matches!(p.kind, PaymentKind::Onchain { .. })
1157+
});
1158+
assert_eq!(outbound_onchain_a.len(), 2);
1159+
// The second outbound on-chain payment should be from the splice-in.
1160+
match outbound_onchain_a[1].kind {
1161+
PaymentKind::Onchain { ref tx_type, .. } => {
1162+
assert!(
1163+
matches!(tx_type, Some(TransactionType::Splice { .. })),
1164+
"Expected Splice transaction type, got {:?}",
1165+
tx_type
1166+
);
1167+
},
1168+
_ => panic!("Unexpected payment kind"),
1169+
}
11471170

11481171
println!("\nB close_channel (force: {})", force_close);
11491172
if force_close {

tests/integration_tests_rust.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use ldk_node::entropy::NodeEntropy;
3131
use ldk_node::liquidity::LSPS2ServiceConfig;
3232
use ldk_node::payment::{
3333
ConfirmationStatus, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
34-
UnifiedPaymentResult,
34+
TransactionType, UnifiedPaymentResult,
3535
};
3636
use ldk_node::{Builder, Event, NodeError};
3737
use lightning::ln::channelmanager::PaymentId;
@@ -418,17 +418,19 @@ async fn onchain_send_receive() {
418418
let payment_a = node_a.payment(&payment_id).unwrap();
419419
assert_eq!(payment_a.status, PaymentStatus::Pending);
420420
match payment_a.kind {
421-
PaymentKind::Onchain { status, .. } => {
421+
PaymentKind::Onchain { status, ref tx_type, .. } => {
422422
assert!(matches!(status, ConfirmationStatus::Unconfirmed));
423+
assert_eq!(*tx_type, None);
423424
},
424425
_ => panic!("Unexpected payment kind"),
425426
}
426427
assert!(payment_a.fee_paid_msat > Some(0));
427428
let payment_b = node_b.payment(&payment_id).unwrap();
428429
assert_eq!(payment_b.status, PaymentStatus::Pending);
429-
match payment_a.kind {
430-
PaymentKind::Onchain { status, .. } => {
430+
match payment_b.kind {
431+
PaymentKind::Onchain { status, ref tx_type, .. } => {
431432
assert!(matches!(status, ConfirmationStatus::Unconfirmed));
433+
assert_eq!(*tx_type, Some(TransactionType::OnchainSend));
432434
},
433435
_ => panic!("Unexpected payment kind"),
434436
}
@@ -457,18 +459,20 @@ async fn onchain_send_receive() {
457459

458460
let payment_a = node_a.payment(&payment_id).unwrap();
459461
match payment_a.kind {
460-
PaymentKind::Onchain { txid: _txid, status, .. } => {
462+
PaymentKind::Onchain { txid: _txid, status, ref tx_type, .. } => {
461463
assert_eq!(_txid, txid);
462464
assert!(matches!(status, ConfirmationStatus::Confirmed { .. }));
465+
assert_eq!(*tx_type, None);
463466
},
464467
_ => panic!("Unexpected payment kind"),
465468
}
466469

467-
let payment_b = node_a.payment(&payment_id).unwrap();
470+
let payment_b = node_b.payment(&payment_id).unwrap();
468471
match payment_b.kind {
469-
PaymentKind::Onchain { txid: _txid, status, .. } => {
472+
PaymentKind::Onchain { txid: _txid, status, ref tx_type, .. } => {
470473
assert_eq!(_txid, txid);
471474
assert!(matches!(status, ConfirmationStatus::Confirmed { .. }));
475+
assert_eq!(*tx_type, Some(TransactionType::OnchainSend));
472476
},
473477
_ => panic!("Unexpected payment kind"),
474478
}
@@ -1018,6 +1022,16 @@ async fn run_splice_channel_test(bitcoind_chain_source: bool) {
10181022
let payment =
10191023
payments.into_iter().find(|p| p.id == PaymentId(txo.txid.to_byte_array())).unwrap();
10201024
assert_eq!(payment.fee_paid_msat, Some(expected_splice_in_fee_sat * 1_000));
1025+
match payment.kind {
1026+
PaymentKind::Onchain { ref tx_type, .. } => {
1027+
assert!(
1028+
matches!(tx_type, Some(TransactionType::Splice { .. })),
1029+
"Expected Splice transaction type, got {:?}",
1030+
tx_type
1031+
);
1032+
},
1033+
_ => panic!("Unexpected payment kind"),
1034+
}
10211035

10221036
assert_eq!(
10231037
node_b.list_balances().total_onchain_balance_sats,
@@ -1061,6 +1075,16 @@ async fn run_splice_channel_test(bitcoind_chain_source: bool) {
10611075
let payment =
10621076
payments.into_iter().find(|p| p.id == PaymentId(txo.txid.to_byte_array())).unwrap();
10631077
assert_eq!(payment.fee_paid_msat, Some(expected_splice_out_fee_sat * 1_000));
1078+
match payment.kind {
1079+
PaymentKind::Onchain { ref tx_type, .. } => {
1080+
assert!(
1081+
matches!(tx_type, Some(TransactionType::Splice { .. })),
1082+
"Expected Splice transaction type, got {:?}",
1083+
tx_type
1084+
);
1085+
},
1086+
_ => panic!("Unexpected payment kind"),
1087+
}
10641088

10651089
assert_eq!(
10661090
node_a.list_balances().total_onchain_balance_sats,

0 commit comments

Comments
 (0)