Skip to content

Commit

Permalink
Check PaymentKind explicitly in full_cycle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed May 31, 2024
1 parent d57f67f commit 82b85c1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(dead_code)]

use ldk_node::io::sqlite_store::SqliteStore;
use ldk_node::payment::{PaymentDirection, PaymentStatus};
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentStatus};
use ldk_node::{Builder, Config, Event, LogLevel, Node, NodeError};

use lightning::ln::msgs::SocketAddress;
Expand Down Expand Up @@ -447,9 +447,11 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
assert_eq!(node_a.payment(&payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_a.payment(&payment_id).unwrap().direction, PaymentDirection::Outbound);
assert_eq!(node_a.payment(&payment_id).unwrap().amount_msat, Some(invoice_amount_1_msat));
assert!(matches!(node_a.payment(&payment_id).unwrap().kind, PaymentKind::Bolt11 { .. }));
assert_eq!(node_b.payment(&payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_b.payment(&payment_id).unwrap().direction, PaymentDirection::Inbound);
assert_eq!(node_b.payment(&payment_id).unwrap().amount_msat, Some(invoice_amount_1_msat));
assert!(matches!(node_b.payment(&payment_id).unwrap().kind, PaymentKind::Bolt11 { .. }));

// Assert we fail duplicate outbound payments and check the status hasn't changed.
assert_eq!(Err(NodeError::DuplicatePayment), node_a.bolt11_payment().send(&invoice));
Expand Down Expand Up @@ -492,9 +494,11 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
assert_eq!(node_a.payment(&payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_a.payment(&payment_id).unwrap().direction, PaymentDirection::Outbound);
assert_eq!(node_a.payment(&payment_id).unwrap().amount_msat, Some(overpaid_amount_msat));
assert!(matches!(node_a.payment(&payment_id).unwrap().kind, PaymentKind::Bolt11 { .. }));
assert_eq!(node_b.payment(&payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_b.payment(&payment_id).unwrap().direction, PaymentDirection::Inbound);
assert_eq!(node_b.payment(&payment_id).unwrap().amount_msat, Some(overpaid_amount_msat));
assert!(matches!(node_b.payment(&payment_id).unwrap().kind, PaymentKind::Bolt11 { .. }));

// Test "zero-amount" invoice payment
println!("\nB receive_variable_amount_payment");
Expand Down Expand Up @@ -526,9 +530,11 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
assert_eq!(node_a.payment(&payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_a.payment(&payment_id).unwrap().direction, PaymentDirection::Outbound);
assert_eq!(node_a.payment(&payment_id).unwrap().amount_msat, Some(determined_amount_msat));
assert!(matches!(node_a.payment(&payment_id).unwrap().kind, PaymentKind::Bolt11 { .. }));
assert_eq!(node_b.payment(&payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_b.payment(&payment_id).unwrap().direction, PaymentDirection::Inbound);
assert_eq!(node_b.payment(&payment_id).unwrap().amount_msat, Some(determined_amount_msat));
assert!(matches!(node_b.payment(&payment_id).unwrap().kind, PaymentKind::Bolt11 { .. }));

// Test spontaneous/keysend payments
println!("\nA send_spontaneous_payment");
Expand All @@ -550,9 +556,19 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
assert_eq!(node_a.payment(&keysend_payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_a.payment(&keysend_payment_id).unwrap().direction, PaymentDirection::Outbound);
assert_eq!(node_a.payment(&keysend_payment_id).unwrap().amount_msat, Some(keysend_amount_msat));
assert!(matches!(
node_a.payment(&keysend_payment_id).unwrap().kind,
PaymentKind::Spontaneous { .. }
));
assert_eq!(node_b.payment(&keysend_payment_id).unwrap().status, PaymentStatus::Succeeded);
assert_eq!(node_b.payment(&keysend_payment_id).unwrap().direction, PaymentDirection::Inbound);
assert_eq!(node_b.payment(&keysend_payment_id).unwrap().amount_msat, Some(keysend_amount_msat));
assert!(matches!(
node_b.payment(&keysend_payment_id).unwrap().kind,
PaymentKind::Spontaneous { .. }
));
assert_eq!(node_a.list_payments().len(), 4);
assert_eq!(node_b.list_payments().len(), 5);

println!("\nB close_channel");
node_b.close_channel(&user_channel_id, node_a.node_id()).unwrap();
Expand Down

0 comments on commit 82b85c1

Please sign in to comment.