Skip to content

Commit 43f7057

Browse files
Update test to support new PaymentMetadata rule while preserving legacy behavior
The test was modified to be compatible with the new `PaymentMetadata` logic, while still verifying compatibility with the legacy rule that stores payments directly in `PaymentStore`. Issue lightningdevkit#425
1 parent bf2c21e commit 43f7057

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

tests/common/mod.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use logging::TestLogWriter;
1414

1515
use ldk_node::config::{Config, ElectrumSyncConfig, EsploraSyncConfig};
1616
use ldk_node::io::sqlite_store::SqliteStore;
17-
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentStatus};
17+
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentMetadataDetail, PaymentStatus};
1818
use ldk_node::{
1919
Builder, CustomTlvRecord, Event, LightningBalance, Node, NodeError, PendingSweepBalance,
2020
};
@@ -653,10 +653,23 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
653653
});
654654
assert_eq!(outbound_payments_b.len(), 0);
655655

656-
let inbound_payments_b = node_b.list_payments_with_filter(|p| {
657-
p.direction == PaymentDirection::Inbound && matches!(p.kind, PaymentKind::Bolt11 { .. })
658-
});
659-
assert_eq!(inbound_payments_b.len(), 1);
656+
if cfg!(feature = "legacy_payment_store") {
657+
let inbound_payments_b = node_b.list_payments_with_filter(|p| {
658+
p.direction == PaymentDirection::Inbound && matches!(p.kind, PaymentKind::Bolt11 { .. })
659+
});
660+
assert_eq!(inbound_payments_b.len(), 1);
661+
} else {
662+
// Payment inbound are saved in the payment metadata store when they are pending
663+
let inbound_metadata_b = node_b.list_payments_metadata_with_filter(|p| {
664+
p.direction == PaymentDirection::Inbound
665+
&& matches!(p.payment_metadata_detail, PaymentMetadataDetail::Bolt11 { .. })
666+
});
667+
assert_eq!(inbound_metadata_b.len(), 1);
668+
let inbound_payments_b = node_b.list_payments_with_filter(|p| {
669+
p.direction == PaymentDirection::Inbound && matches!(p.kind, PaymentKind::Bolt11 { .. })
670+
});
671+
assert_eq!(inbound_payments_b.len(), 0);
672+
}
660673

661674
expect_event!(node_a, PaymentSuccessful);
662675
expect_event!(node_b, PaymentReceived);
@@ -893,10 +906,22 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
893906
node_a.list_payments_with_filter(|p| matches!(p.kind, PaymentKind::Bolt11 { .. })).len(),
894907
5
895908
);
896-
assert_eq!(
897-
node_b.list_payments_with_filter(|p| matches!(p.kind, PaymentKind::Bolt11 { .. })).len(),
898-
6
899-
);
909+
if cfg!(feature = "legacy_payment_store") {
910+
assert_eq!(
911+
node_b
912+
.list_payments_with_filter(|p| matches!(p.kind, PaymentKind::Bolt11 { .. }))
913+
.len(),
914+
6
915+
);
916+
} else {
917+
assert_eq!(
918+
node_b
919+
.list_payments_with_filter(|p| matches!(p.kind, PaymentKind::Bolt11 { .. }))
920+
.len(),
921+
5
922+
);
923+
}
924+
900925
assert_eq!(
901926
node_a
902927
.list_payments_with_filter(|p| matches!(p.kind, PaymentKind::Spontaneous { .. }))

0 commit comments

Comments
 (0)