1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! Functional tests for the BOLT 12 Offers payment flow.
12 //! [`ChannelManager`] provides utilities to create [`Offer`]s and [`Refund`]s along with utilities
13 //! to initiate and request payment for them, respectively. It also manages the payment flow via
14 //! implementing [`OffersMessageHandler`]. This module tests that functionality, including the
15 //! resulting [`Event`] generation.
17 use core::time::Duration;
18 use crate::blinded_path::BlindedPath;
19 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
20 use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
21 use crate::ln::functional_test_utils::*;
22 use crate::ln::msgs::{ChannelMessageHandler, Init, OnionMessage, OnionMessageHandler};
23 use crate::offers::invoice::Bolt12Invoice;
24 use crate::offers::invoice_request::InvoiceRequest;
25 use crate::offers::parse::Bolt12SemanticError;
26 use crate::onion_message::messenger::PeeledOnion;
27 use crate::onion_message::offers::OffersMessage;
28 use crate::onion_message::packet::ParsedOnionMessageContents;
30 use crate::prelude::*;
32 macro_rules! expect_recent_payment {
33 ($node: expr, $payment_state: path, $payment_id: expr) => {
34 match $node.node.list_recent_payments().first() {
35 Some(&$payment_state { payment_id: actual_payment_id, .. }) => {
36 assert_eq!($payment_id, actual_payment_id);
38 Some(_) => panic!("Unexpected recent payment state"),
39 None => panic!("No recent payments"),
44 fn connect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) {
45 let node_id_a = node_a.node.get_our_node_id();
46 let node_id_b = node_b.node.get_our_node_id();
49 features: node_a.init_features(&node_id_b),
51 remote_network_address: None,
54 features: node_b.init_features(&node_id_a),
56 remote_network_address: None,
59 node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap();
60 node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap();
61 node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap();
62 node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap();
65 fn disconnect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>]) {
67 node_a.node.peer_disconnected(&node_b.node.get_our_node_id());
68 node_b.node.peer_disconnected(&node_a.node.get_our_node_id());
69 node_a.onion_messenger.peer_disconnected(&node_b.node.get_our_node_id());
70 node_b.onion_messenger.peer_disconnected(&node_a.node.get_our_node_id());
74 fn route_bolt12_payment<'a, 'b, 'c>(
75 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice
77 // Monitor added when handling the invoice onion message.
78 check_added_monitors(node, 1);
80 let mut events = node.node.get_and_clear_pending_msg_events();
81 assert_eq!(events.len(), 1);
82 let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
84 // Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
85 // invoice contains the payment_hash but it was encrypted inside an onion message.
86 let amount_msats = invoice.amount_msats();
87 let payment_hash = invoice.payment_hash();
89 node, path, amount_msats, payment_hash, None, ev, false, false, None, false
93 fn claim_bolt12_payment<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>]) {
94 let recipient = &path[path.len() - 1];
95 match get_event!(recipient, Event::PaymentClaimable) {
96 Event::PaymentClaimable {
97 purpose: PaymentPurpose::InvoicePayment {
98 payment_preimage: Some(payment_preimage), ..
100 } => claim_payment(node, path, payment_preimage),
105 fn extract_invoice_request<'a, 'b, 'c>(
106 node: &Node<'a, 'b, 'c>, message: &OnionMessage
107 ) -> (InvoiceRequest, Option<BlindedPath>) {
108 match node.onion_messenger.peel_onion_message(message) {
109 Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
110 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
111 OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path),
112 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
113 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
115 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
117 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
118 Err(e) => panic!("Failed to process onion message {:?}", e),
122 fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
123 match node.onion_messenger.peel_onion_message(message) {
124 Ok(PeeledOnion::Receive(message, _, _)) => match message {
125 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
126 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
127 OffersMessage::Invoice(invoice) => invoice,
128 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
130 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
132 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
133 Err(e) => panic!("Failed to process onion message {:?}", e),
137 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
138 /// rather than exposing a node's pubkey.
140 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
141 let mut accept_forward_cfg = test_default_channel_config();
142 accept_forward_cfg.accept_forwards_to_priv_channels = true;
144 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
145 features.set_onion_messages_optional();
146 features.set_route_blinding_optional();
148 let chanmon_cfgs = create_chanmon_cfgs(6);
149 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
151 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
153 let node_chanmgrs = create_node_chanmgrs(
154 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
156 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
158 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
159 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
160 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
161 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
162 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
163 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
164 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
166 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
167 let alice_id = alice.node.get_our_node_id();
168 let bob_id = bob.node.get_our_node_id();
169 let charlie_id = charlie.node.get_our_node_id();
170 let david_id = david.node.get_our_node_id();
172 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
173 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
175 let offer = alice.node
176 .create_offer_builder("coffee".to_string()).unwrap()
177 .amount_msats(10_000_000)
179 assert_ne!(offer.signing_pubkey(), alice_id);
180 assert!(!offer.paths().is_empty());
181 for path in offer.paths() {
182 assert_eq!(path.introduction_node_id, bob_id);
185 let payment_id = PaymentId([1; 32]);
186 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
188 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
190 connect_peers(david, bob);
192 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
193 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
195 connect_peers(alice, charlie);
197 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
198 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
200 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
201 assert_eq!(invoice_request.amount_msats(), None);
202 assert_ne!(invoice_request.payer_id(), david_id);
203 assert_eq!(reply_path.unwrap().introduction_node_id, charlie_id);
205 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
206 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
208 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
209 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
211 let invoice = extract_invoice(david, &onion_message);
212 assert_eq!(invoice.amount_msats(), 10_000_000);
213 assert_ne!(invoice.signing_pubkey(), alice_id);
214 assert!(!invoice.payment_paths().is_empty());
215 for (_, path) in invoice.payment_paths() {
216 assert_eq!(path.introduction_node_id, bob_id);
219 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
220 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
222 claim_bolt12_payment(david, &[charlie, bob, alice]);
223 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
226 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
227 /// rather than exposing a node's pubkey.
229 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
230 let mut accept_forward_cfg = test_default_channel_config();
231 accept_forward_cfg.accept_forwards_to_priv_channels = true;
233 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
234 features.set_onion_messages_optional();
235 features.set_route_blinding_optional();
237 let chanmon_cfgs = create_chanmon_cfgs(6);
238 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
240 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
242 let node_chanmgrs = create_node_chanmgrs(
243 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
245 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
247 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
248 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
249 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
250 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
251 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
252 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
253 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
255 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
256 let alice_id = alice.node.get_our_node_id();
257 let bob_id = bob.node.get_our_node_id();
258 let charlie_id = charlie.node.get_our_node_id();
259 let david_id = david.node.get_our_node_id();
261 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
262 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
264 let absolute_expiry = Duration::from_secs(u64::MAX);
265 let payment_id = PaymentId([1; 32]);
266 let refund = david.node
267 .create_refund_builder(
268 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
272 assert_eq!(refund.amount_msats(), 10_000_000);
273 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
274 assert_ne!(refund.payer_id(), david_id);
275 assert!(!refund.paths().is_empty());
276 for path in refund.paths() {
277 assert_eq!(path.introduction_node_id, charlie_id);
279 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
281 alice.node.request_refund_payment(&refund).unwrap();
283 connect_peers(alice, charlie);
285 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
286 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
288 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
289 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
291 let invoice = extract_invoice(david, &onion_message);
292 assert_eq!(invoice.amount_msats(), 10_000_000);
293 assert_ne!(invoice.signing_pubkey(), alice_id);
294 assert!(!invoice.payment_paths().is_empty());
295 for (_, path) in invoice.payment_paths() {
296 assert_eq!(path.introduction_node_id, bob_id);
299 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
300 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
302 claim_bolt12_payment(david, &[charlie, bob, alice]);
303 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
306 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
307 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
308 /// introduction node of the blinded path.
310 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
311 let chanmon_cfgs = create_chanmon_cfgs(2);
312 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
313 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
314 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
316 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
318 let alice = &nodes[0];
319 let alice_id = alice.node.get_our_node_id();
321 let bob_id = bob.node.get_our_node_id();
323 let offer = alice.node
324 .create_offer_builder("coffee".to_string()).unwrap()
325 .amount_msats(10_000_000)
327 assert_ne!(offer.signing_pubkey(), alice_id);
328 assert!(!offer.paths().is_empty());
329 for path in offer.paths() {
330 assert_eq!(path.introduction_node_id, alice_id);
333 let payment_id = PaymentId([1; 32]);
334 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
335 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
337 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
338 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
340 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
341 assert_eq!(invoice_request.amount_msats(), None);
342 assert_ne!(invoice_request.payer_id(), bob_id);
343 assert_eq!(reply_path.unwrap().introduction_node_id, bob_id);
345 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
346 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
348 let invoice = extract_invoice(bob, &onion_message);
349 assert_eq!(invoice.amount_msats(), 10_000_000);
350 assert_ne!(invoice.signing_pubkey(), alice_id);
351 assert!(!invoice.payment_paths().is_empty());
352 for (_, path) in invoice.payment_paths() {
353 assert_eq!(path.introduction_node_id, alice_id);
356 route_bolt12_payment(bob, &[alice], &invoice);
357 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
359 claim_bolt12_payment(bob, &[alice]);
360 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
363 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
364 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
365 /// introduction node of the blinded path.
367 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
368 let chanmon_cfgs = create_chanmon_cfgs(2);
369 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
370 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
371 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
373 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
375 let alice = &nodes[0];
376 let alice_id = alice.node.get_our_node_id();
378 let bob_id = bob.node.get_our_node_id();
380 let absolute_expiry = Duration::from_secs(u64::MAX);
381 let payment_id = PaymentId([1; 32]);
382 let refund = bob.node
383 .create_refund_builder(
384 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
388 assert_eq!(refund.amount_msats(), 10_000_000);
389 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
390 assert_ne!(refund.payer_id(), bob_id);
391 assert!(!refund.paths().is_empty());
392 for path in refund.paths() {
393 assert_eq!(path.introduction_node_id, bob_id);
395 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
397 alice.node.request_refund_payment(&refund).unwrap();
399 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
400 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
402 let invoice = extract_invoice(bob, &onion_message);
403 assert_eq!(invoice.amount_msats(), 10_000_000);
404 assert_ne!(invoice.signing_pubkey(), alice_id);
405 assert!(!invoice.payment_paths().is_empty());
406 for (_, path) in invoice.payment_paths() {
407 assert_eq!(path.introduction_node_id, alice_id);
410 route_bolt12_payment(bob, &[alice], &invoice);
411 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
413 claim_bolt12_payment(bob, &[alice]);
414 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
417 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
418 /// the requested is sent directly using the node's pubkey, the response and the payment still use
419 /// blinded paths as required by the spec.
421 fn pays_for_offer_without_blinded_paths() {
422 let chanmon_cfgs = create_chanmon_cfgs(2);
423 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
424 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
425 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
427 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
429 let alice = &nodes[0];
430 let alice_id = alice.node.get_our_node_id();
432 let bob_id = bob.node.get_our_node_id();
434 let offer = alice.node
435 .create_offer_builder("coffee".to_string()).unwrap()
437 .amount_msats(10_000_000)
439 assert_eq!(offer.signing_pubkey(), alice_id);
440 assert!(offer.paths().is_empty());
442 let payment_id = PaymentId([1; 32]);
443 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
444 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
446 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
447 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
449 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
450 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
452 let invoice = extract_invoice(bob, &onion_message);
453 route_bolt12_payment(bob, &[alice], &invoice);
454 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
456 claim_bolt12_payment(bob, &[alice]);
457 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
460 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
461 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
463 fn pays_for_refund_without_blinded_paths() {
464 let chanmon_cfgs = create_chanmon_cfgs(2);
465 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
466 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
467 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
469 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
471 let alice = &nodes[0];
472 let alice_id = alice.node.get_our_node_id();
474 let bob_id = bob.node.get_our_node_id();
476 let absolute_expiry = Duration::from_secs(u64::MAX);
477 let payment_id = PaymentId([1; 32]);
478 let refund = bob.node
479 .create_refund_builder(
480 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
485 assert_eq!(refund.payer_id(), bob_id);
486 assert!(refund.paths().is_empty());
487 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
489 alice.node.request_refund_payment(&refund).unwrap();
491 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
492 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
494 let invoice = extract_invoice(bob, &onion_message);
495 route_bolt12_payment(bob, &[alice], &invoice);
496 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
498 claim_bolt12_payment(bob, &[alice]);
499 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
502 /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
504 fn fails_creating_offer_without_blinded_paths() {
505 let chanmon_cfgs = create_chanmon_cfgs(2);
506 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
507 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
508 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
510 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
512 match nodes[0].node.create_offer_builder("coffee".to_string()) {
513 Ok(_) => panic!("Expected error"),
514 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
518 /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
520 fn fails_creating_refund_without_blinded_paths() {
521 let chanmon_cfgs = create_chanmon_cfgs(2);
522 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
523 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
524 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
526 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
528 let absolute_expiry = Duration::from_secs(u64::MAX);
529 let payment_id = PaymentId([1; 32]);
531 match nodes[0].node.create_refund_builder(
532 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
534 Ok(_) => panic!("Expected error"),
535 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
538 assert!(nodes[0].node.list_recent_payments().is_empty());
541 /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
544 fn fails_creating_invoice_request_without_blinded_reply_path() {
545 let chanmon_cfgs = create_chanmon_cfgs(6);
546 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
547 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
548 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
550 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
551 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
552 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
553 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
554 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
556 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
558 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
559 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
561 let offer = alice.node
562 .create_offer_builder("coffee".to_string()).unwrap()
563 .amount_msats(10_000_000)
566 let payment_id = PaymentId([1; 32]);
568 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
569 Ok(_) => panic!("Expected error"),
570 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
573 assert!(nodes[0].node.list_recent_payments().is_empty());