Rename InvoicePayment to Bolt11InvoicePayment
[rust-lightning] / lightning / src / ln / offers_tests.rs
index 63e73975b940a8dba323db48d518028bc728f85f..6a0eb6cb3b1e515d034e0e41d6487fb24484e480 100644 (file)
@@ -42,7 +42,7 @@
 
 use bitcoin::network::constants::Network;
 use core::time::Duration;
-use crate::blinded_path::BlindedPath;
+use crate::blinded_path::{BlindedPath, IntroductionNode};
 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
 use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
 use crate::ln::functional_test_utils::*;
@@ -146,16 +146,16 @@ fn route_bolt12_payment<'a, 'b, 'c>(
        // invoice contains the payment_hash but it was encrypted inside an onion message.
        let amount_msats = invoice.amount_msats();
        let payment_hash = invoice.payment_hash();
-       do_pass_along_path(
-               node, path, amount_msats, payment_hash, None, ev, false, false, None, false
-       );
+       let args = PassAlongPathArgs::new(node, path, amount_msats, payment_hash, ev)
+               .without_clearing_recipient_events();
+       do_pass_along_path(args);
 }
 
 fn claim_bolt12_payment<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>]) {
        let recipient = &path[path.len() - 1];
        match get_event!(recipient, Event::PaymentClaimable) {
                Event::PaymentClaimable {
-                       purpose: PaymentPurpose::InvoicePayment {
+                       purpose: PaymentPurpose::Bolt11InvoicePayment {
                                payment_preimage: Some(payment_preimage), ..
                        }, ..
                } => claim_payment(node, path, payment_preimage),
@@ -260,8 +260,8 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
        assert_ne!(offer.signing_pubkey(), bob_id);
        assert!(!offer.paths().is_empty());
        for path in offer.paths() {
-               assert_ne!(path.introduction_node_id, bob_id);
-               assert_ne!(path.introduction_node_id, charlie_id);
+               assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
+               assert_ne!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
        }
 
        // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
@@ -275,7 +275,7 @@ fn prefers_non_tor_nodes_in_blinded_paths() {
        assert_ne!(offer.signing_pubkey(), bob_id);
        assert!(!offer.paths().is_empty());
        for path in offer.paths() {
-               assert_eq!(path.introduction_node_id, bob_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
        }
 }
 
@@ -325,7 +325,7 @@ fn prefers_more_connected_nodes_in_blinded_paths() {
        assert_ne!(offer.signing_pubkey(), bob_id);
        assert!(!offer.paths().is_empty());
        for path in offer.paths() {
-               assert_eq!(path.introduction_node_id, nodes[4].node.get_our_node_id());
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
        }
 }
 
@@ -374,7 +374,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
        assert_ne!(offer.signing_pubkey(), alice_id);
        assert!(!offer.paths().is_empty());
        for path in offer.paths() {
-               assert_eq!(path.introduction_node_id, bob_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
        }
 
        let payment_id = PaymentId([1; 32]);
@@ -395,7 +395,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
        let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
        assert_eq!(invoice_request.amount_msats(), None);
        assert_ne!(invoice_request.payer_id(), david_id);
-       assert_eq!(reply_path.unwrap().introduction_node_id, charlie_id);
+       assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(charlie_id));
 
        let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
        charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
@@ -408,7 +408,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
        assert_ne!(invoice.signing_pubkey(), alice_id);
        assert!(!invoice.payment_paths().is_empty());
        for (_, path) in invoice.payment_paths() {
-               assert_eq!(path.introduction_node_id, bob_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
        }
 
        route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
@@ -469,11 +469,11 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
        assert_ne!(refund.payer_id(), david_id);
        assert!(!refund.paths().is_empty());
        for path in refund.paths() {
-               assert_eq!(path.introduction_node_id, charlie_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
        }
        expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
 
-       alice.node.request_refund_payment(&refund).unwrap();
+       let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
 
        connect_peers(alice, charlie);
 
@@ -484,11 +484,13 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
        david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
 
        let invoice = extract_invoice(david, &onion_message);
+       assert_eq!(invoice, expected_invoice);
+
        assert_eq!(invoice.amount_msats(), 10_000_000);
        assert_ne!(invoice.signing_pubkey(), alice_id);
        assert!(!invoice.payment_paths().is_empty());
        for (_, path) in invoice.payment_paths() {
-               assert_eq!(path.introduction_node_id, bob_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
        }
 
        route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
@@ -522,7 +524,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
        assert_ne!(offer.signing_pubkey(), alice_id);
        assert!(!offer.paths().is_empty());
        for path in offer.paths() {
-               assert_eq!(path.introduction_node_id, alice_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
        }
 
        let payment_id = PaymentId([1; 32]);
@@ -535,7 +537,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
        let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
        assert_eq!(invoice_request.amount_msats(), None);
        assert_ne!(invoice_request.payer_id(), bob_id);
-       assert_eq!(reply_path.unwrap().introduction_node_id, bob_id);
+       assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(bob_id));
 
        let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
        bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
@@ -545,7 +547,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
        assert_ne!(invoice.signing_pubkey(), alice_id);
        assert!(!invoice.payment_paths().is_empty());
        for (_, path) in invoice.payment_paths() {
-               assert_eq!(path.introduction_node_id, alice_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
        }
 
        route_bolt12_payment(bob, &[alice], &invoice);
@@ -585,21 +587,23 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
        assert_ne!(refund.payer_id(), bob_id);
        assert!(!refund.paths().is_empty());
        for path in refund.paths() {
-               assert_eq!(path.introduction_node_id, bob_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
        }
        expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
 
-       alice.node.request_refund_payment(&refund).unwrap();
+       let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
 
        let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
        bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
 
        let invoice = extract_invoice(bob, &onion_message);
+       assert_eq!(invoice, expected_invoice);
+
        assert_eq!(invoice.amount_msats(), 10_000_000);
        assert_ne!(invoice.signing_pubkey(), alice_id);
        assert!(!invoice.payment_paths().is_empty());
        for (_, path) in invoice.payment_paths() {
-               assert_eq!(path.introduction_node_id, alice_id);
+               assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
        }
 
        route_bolt12_payment(bob, &[alice], &invoice);
@@ -681,12 +685,14 @@ fn pays_for_refund_without_blinded_paths() {
        assert!(refund.paths().is_empty());
        expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
 
-       alice.node.request_refund_payment(&refund).unwrap();
+       let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
 
        let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
        bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
 
        let invoice = extract_invoice(bob, &onion_message);
+       assert_eq!(invoice, expected_invoice);
+
        route_bolt12_payment(bob, &[alice], &invoice);
        expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);