Skip to content

Commit dd1401f

Browse files
committed
Test: Add coverage for Offers and Refunds without blinded paths
Introduced tests to validate the behavior of Offers and Refunds created without blinded paths, using `NullMessageRouter`.
1 parent d1e2b66 commit dd1401f

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

lightning/src/ln/offers_tests.rs

+50-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use crate::offers::invoice_error::InvoiceError;
5858
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields};
5959
use crate::offers::nonce::Nonce;
6060
use crate::offers::parse::Bolt12SemanticError;
61-
use crate::onion_message::messenger::{CompactMessageRouter, Destination, MessageSendInstructions, PeeledOnion};
61+
use crate::onion_message::messenger::{CompactMessageRouter, Destination, MessageSendInstructions, NullMessageRouter, PeeledOnion};
6262
use crate::onion_message::offers::OffersMessage;
6363
use crate::onion_message::packet::ParsedOnionMessageContents;
6464
use crate::routing::gossip::{NodeAlias, NodeId};
@@ -255,6 +255,55 @@ fn extract_invoice_error<'a, 'b, 'c>(
255255
}
256256
}
257257

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

0 commit comments

Comments
 (0)