X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Foffers_tests.rs;h=5594c8ba930694bf5d92421d9204dfd0b44016d9;hb=411b9b43f6089b1482eb9831742bf5ecb8238e0d;hp=6484f5259f6dd99b9eb0025801cfe4b773ae5c79;hpb=4956ade170f112881f3454dacc95f90b64e6aad3;p=rust-lightning diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index 6484f525..5594c8ba 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -40,7 +40,8 @@ //! Nodes without channels are disconnected and connected as needed to ensure that deterministic //! blinded paths are used. -use bitcoin::network::constants::Network; +use bitcoin::network::Network; +use bitcoin::secp256k1::PublicKey; use core::time::Duration; use crate::blinded_path::{BlindedPath, IntroductionNode}; use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext}; @@ -133,6 +134,12 @@ fn announce_node_address<'a, 'b, 'c>( } } +fn resolve_introduction_node<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &BlindedPath) -> PublicKey { + path.public_introduction_node_id(&node.network_graph.read_only()) + .and_then(|node_id| node_id.as_pubkey().ok()) + .unwrap() +} + fn route_bolt12_payment<'a, 'b, 'c>( node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice ) { @@ -273,8 +280,9 @@ fn prefers_non_tor_nodes_in_blinded_paths() { assert_ne!(offer.signing_pubkey(), Some(bob_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { - assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id)); - assert_ne!(path.introduction_node, IntroductionNode::NodeId(charlie_id)); + let introduction_node_id = resolve_introduction_node(david, &path); + assert_ne!(introduction_node_id, bob_id); + assert_ne!(introduction_node_id, charlie_id); } // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only. @@ -288,7 +296,8 @@ fn prefers_non_tor_nodes_in_blinded_paths() { assert_ne!(offer.signing_pubkey(), Some(bob_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { - assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id)); + let introduction_node_id = resolve_introduction_node(david, &path); + assert_eq!(introduction_node_id, bob_id); } } @@ -338,7 +347,8 @@ fn prefers_more_connected_nodes_in_blinded_paths() { assert_ne!(offer.signing_pubkey(), Some(bob_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { - assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id())); + let introduction_node_id = resolve_introduction_node(david, &path); + assert_eq!(introduction_node_id, nodes[4].node.get_our_node_id()); } } @@ -388,7 +398,9 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() { assert_ne!(offer.signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { - assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id)); + let introduction_node_id = resolve_introduction_node(david, &path); + assert_eq!(introduction_node_id, bob_id); + assert!(matches!(path.introduction_node, IntroductionNode::DirectedShortChannelId(..))); } let payment_id = PaymentId([1; 32]); @@ -489,7 +501,9 @@ 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, IntroductionNode::NodeId(charlie_id)); + let introduction_node_id = resolve_introduction_node(alice, &path); + assert_eq!(introduction_node_id, charlie_id); + assert!(matches!(path.introduction_node, IntroductionNode::DirectedShortChannelId(..))); } expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id); @@ -545,7 +559,9 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() { assert_ne!(offer.signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { - assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id)); + let introduction_node_id = resolve_introduction_node(bob, &path); + assert_eq!(introduction_node_id, alice_id); + assert!(matches!(path.introduction_node, IntroductionNode::DirectedShortChannelId(..))); } let payment_id = PaymentId([1; 32]); @@ -614,7 +630,9 @@ 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, IntroductionNode::NodeId(bob_id)); + let introduction_node_id = resolve_introduction_node(alice, &path); + assert_eq!(introduction_node_id, bob_id); + assert!(matches!(path.introduction_node, IntroductionNode::DirectedShortChannelId(..))); } expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);