X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Foffers_tests.rs;h=5b774ce4ee266e597f4d43a534cb52a8300d3119;hb=12c3a24bebe67ba406609fdfe6747da9c1449756;hp=e75bd2c70e1e9c3d6b68945fa0ea424a694d4f7d;hpb=8354e0c9ba383d4f4df14c9735847a0b19a37f91;p=rust-lightning diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index e75bd2c7..5b774ce4 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -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::*; @@ -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);