Skip to content

Commit d49c71d

Browse files
committed
Test failing pay_for_offer on an unsupported chain
1 parent 7ab438d commit d49c71d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lightning/src/ln/offers_tests.rs

+27
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//! Nodes without channels are disconnected and connected as needed to ensure that deterministic
4141
//! blinded paths are used.
4242
43+
use bitcoin::network::constants::Network;
4344
use core::time::Duration;
4445
use crate::blinded_path::BlindedPath;
4546
use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
@@ -667,6 +668,32 @@ fn fails_creating_refund_without_blinded_paths() {
667668
assert!(nodes[0].node.list_recent_payments().is_empty());
668669
}
669670

671+
/// Fails creating an invoice request when the offer contains an unsupported chain.
672+
#[test]
673+
fn fails_creating_invoice_request_for_unsupported_chain() {
674+
let chanmon_cfgs = create_chanmon_cfgs(2);
675+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
676+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
677+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
678+
679+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
680+
681+
let alice = &nodes[0];
682+
let bob = &nodes[1];
683+
684+
let offer = alice.node
685+
.create_offer_builder("coffee".to_string()).unwrap()
686+
.clear_chains()
687+
.chain(Network::Signet)
688+
.build().unwrap();
689+
690+
let payment_id = PaymentId([1; 32]);
691+
match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
692+
Ok(_) => panic!("Expected error"),
693+
Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
694+
}
695+
}
696+
670697
/// Fails creating an invoice request when a blinded reply path cannot be created without exposing
671698
/// the node's id.
672699
#[test]

lightning/src/offers/offer.rs

+5
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
339339
self
340340
}
341341

342+
pub(crate) fn clear_chains(mut self) -> Self {
343+
self.offer.chains = None;
344+
self
345+
}
346+
342347
pub(crate) fn clear_paths(mut self) -> Self {
343348
self.offer.paths = None;
344349
self

0 commit comments

Comments
 (0)