Skip to content

Commit 3bcc420

Browse files
committed
Introduce Tests for Offers and Refunds Without Blinded Paths
1 parent 4014246 commit 3bcc420

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9038,7 +9038,9 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
90389038
let secp_ctx = &$self.secp_ctx;
90399039

90409040
let nonce = Nonce::from_entropy_source(entropy);
9041-
let context = OffersContext::InvoiceRequest { nonce };
9041+
let context = MessageContext::Offers(
9042+
OffersContext::InvoiceRequest { nonce }
9043+
);
90429044
let builder = match blinded_path {
90439045
Some(blinded_path) => {
90449046
let path = $self
@@ -9115,7 +9117,9 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
91159117
let secp_ctx = &$self.secp_ctx;
91169118

91179119
let nonce = Nonce::from_entropy_source(entropy);
9118-
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
9120+
let context = MessageContext::Offers(
9121+
OffersContext::OutboundPayment { payment_id, nonce, hmac: None }
9122+
);
91199123

91209124
let builder = match blinded_path {
91219125
Some(blinded_path) => {
@@ -9573,7 +9577,7 @@ where
95739577
.collect::<Vec<_>>();
95749578

95759579
self.router
9576-
.create_blinded_paths(recipient, MessageContext::Offers(context), blinded_path, peers, secp_ctx)
9580+
.create_blinded_paths(recipient, context, blinded_path, peers, secp_ctx)
95779581
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
95789582
}
95799583

@@ -10954,7 +10958,7 @@ where
1095410958
nonce,
1095510959
hmac: Some(hmac)
1095610960
});
10957-
match self.create_blinded_paths(context) {
10961+
match self.create_blinded_paths(context, BlindedPathType::Full) {
1095810962
Ok(reply_paths) => match self.enqueue_invoice_request(invoice_request, reply_paths) {
1095910963
Ok(_) => {}
1096010964
Err(_) => {

lightning/src/ln/offers_tests.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,53 @@ fn extract_invoice_error<'a, 'b, 'c>(
261261
}
262262
}
263263

264+
/// Checks that an offer can be created with no blinded paths.
265+
#[test]
266+
fn create_offer_with_no_blinded_path() {
267+
let chanmon_cfgs = create_chanmon_cfgs(2);
268+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
269+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
270+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
271+
272+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
273+
274+
let alice = &nodes[0];
275+
let alice_id = alice.node.get_our_node_id();
276+
277+
let offer = alice.node
278+
.create_offer_builder(None).unwrap()
279+
.amount_msats(10_000_000)
280+
.build().unwrap();
281+
assert_eq!(offer.issuer_signing_pubkey(), Some(alice_id));
282+
assert!(offer.paths().is_empty());
283+
}
284+
285+
/// Checks that a refund can be created with no blinded paths.
286+
#[test]
287+
fn create_refund_with_no_blinded_path() {
288+
let chanmon_cfgs = create_chanmon_cfgs(2);
289+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
290+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
291+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
292+
293+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
294+
295+
let alice = &nodes[0];
296+
let alice_id = alice.node.get_our_node_id();
297+
298+
let absolute_expiry = Duration::from_secs(u64::MAX);
299+
let payment_id = PaymentId([1; 32]);
300+
301+
let refund = alice.node
302+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, None)
303+
.unwrap()
304+
.build().unwrap();
305+
assert_eq!(refund.amount_msats(), 10_000_000);
306+
assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
307+
assert_eq!(refund.payer_signing_pubkey(), alice_id);
308+
assert!(refund.paths().is_empty());
309+
}
310+
264311
/// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
265312
#[test]
266313
fn prefers_non_tor_nodes_in_blinded_paths() {

0 commit comments

Comments
 (0)