Skip to content

Commit 7573150

Browse files
committed
Functional tests for failing without blinded paths
1 parent 533c3cc commit 7573150

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::ln::functional_test_utils::*;
2222
use crate::ln::msgs::{ChannelMessageHandler, Init, OnionMessage, OnionMessageHandler};
2323
use crate::offers::invoice::Bolt12Invoice;
2424
use crate::offers::invoice_request::InvoiceRequest;
25+
use crate::offers::parse::Bolt12SemanticError;
2526
use crate::onion_message::messenger::PeeledOnion;
2627
use crate::onion_message::offers::OffersMessage;
2728
use crate::onion_message::packet::ParsedOnionMessageContents;
@@ -497,3 +498,77 @@ fn pays_for_refund_without_blinded_paths() {
497498
claim_bolt12_payment(bob, &[alice]);
498499
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
499500
}
501+
502+
/// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
503+
#[test]
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);
509+
510+
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
511+
512+
match nodes[0].node.create_offer_builder("coffee".to_string()) {
513+
Ok(_) => panic!("Expected error"),
514+
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
515+
}
516+
}
517+
518+
/// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
519+
#[test]
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);
525+
526+
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
527+
528+
let absolute_expiry = Duration::from_secs(u64::MAX);
529+
let payment_id = PaymentId([1; 32]);
530+
531+
match nodes[0].node.create_refund_builder(
532+
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
533+
) {
534+
Ok(_) => panic!("Expected error"),
535+
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
536+
}
537+
538+
assert!(nodes[0].node.list_recent_payments().is_empty());
539+
}
540+
541+
/// Fails creating an invoice request when a blinded reply path cannot be created without exposing
542+
/// the node's id.
543+
#[test]
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);
549+
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);
555+
556+
let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
557+
558+
disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
559+
disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
560+
561+
let offer = alice.node
562+
.create_offer_builder("coffee".to_string()).unwrap()
563+
.amount_msats(10_000_000)
564+
.build().unwrap();
565+
566+
let payment_id = PaymentId([1; 32]);
567+
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),
571+
}
572+
573+
assert!(nodes[0].node.list_recent_payments().is_empty());
574+
}

0 commit comments

Comments
 (0)