Skip to content

Commit 07d766a

Browse files
committed
Test failing pay_for_offer on an unsupported chain
1 parent 670b41a commit 07d766a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 27 additions & 0 deletions
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};
@@ -732,6 +733,32 @@ fn fails_creating_refund_without_blinded_paths() {
732733
assert!(nodes[0].node.list_recent_payments().is_empty());
733734
}
734735

736+
/// Fails creating an invoice request when the offer contains an unsupported chain.
737+
#[test]
738+
fn fails_creating_invoice_request_for_unsupported_chain() {
739+
let chanmon_cfgs = create_chanmon_cfgs(2);
740+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
741+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
742+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
743+
744+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
745+
746+
let alice = &nodes[0];
747+
let bob = &nodes[1];
748+
749+
let offer = alice.node
750+
.create_offer_builder("coffee".to_string()).unwrap()
751+
.clear_chains()
752+
.chain(Network::Signet)
753+
.build().unwrap();
754+
755+
let payment_id = PaymentId([1; 32]);
756+
match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
757+
Ok(_) => panic!("Expected error"),
758+
Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
759+
}
760+
}
761+
735762
/// Fails creating an invoice request when a blinded reply path cannot be created without exposing
736763
/// the node's id.
737764
#[test]

lightning/src/offers/offer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ macro_rules! offer_builder_test_methods { (
390390
$return_value
391391
}
392392

393+
#[cfg_attr(c_bindings, allow(dead_code))]
394+
pub(crate) fn clear_chains($($self_mut)* $self: $self_type) -> $return_type {
395+
$self.offer.chains = None;
396+
$return_value
397+
}
398+
393399
#[cfg_attr(c_bindings, allow(dead_code))]
394400
pub(crate) fn clear_paths($($self_mut)* $self: $self_type) -> $return_type {
395401
$self.offer.paths = None;

0 commit comments

Comments
 (0)