Skip to content

Commit

Permalink
Functional tests for offers without blinded paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Dec 14, 2023
1 parent 2e22006 commit 449252f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
86 changes: 86 additions & 0 deletions lightning/src/ln/offers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,89 @@ fn creates_and_pays_for_refund_using_blinded_paths() {
claim_bolt12_payment(bob, &[alice]);
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
}

/// Similar to `creates_and_pays_for_offer_using_blinded_paths` but for an offer without any blinded
/// paths. Note that while the invoice is requested directly using the node's pubkey, the response
/// and the payment still use blinded paths as required by the spec.
#[test]
fn creates_and_pays_for_offer_without_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);

let alice = &nodes[0];
let alice_id = alice.node.get_our_node_id();
let bob = &nodes[1];
let bob_id = bob.node.get_our_node_id();

let offer = alice.node
.create_offer_builder("coffee".to_string())
.clear_paths()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), alice_id);
assert!(offer.paths().is_empty());

let payment_id = PaymentId([1; 32]);
bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);

let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);

let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);

let invoice = extract_invoice(bob, &onion_message);
route_bolt12_payment(bob, &[alice], &invoice);
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);

claim_bolt12_payment(bob, &[alice]);
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
}

/// Similar to `creates_and_pays_for_refund_using_blinded_paths` but for a refund without any
/// blinded paths. Note that while the invoice is sent directly using the node's pubkey, the payment
/// still uses blinded paths as required by the spec.
#[test]
fn creates_and_pays_for_refund_without_blinded_paths() {
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);

let alice = &nodes[0];
let alice_id = alice.node.get_our_node_id();
let bob = &nodes[1];
let bob_id = bob.node.get_our_node_id();

let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.unwrap()
.clear_paths()
.build().unwrap();
assert_eq!(refund.payer_id(), bob_id);
assert!(refund.paths().is_empty());
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);

alice.node.request_refund_payment(&refund).unwrap();

let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);

let invoice = extract_invoice(bob, &onion_message);
route_bolt12_payment(bob, &[alice], &invoice);
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);

claim_bolt12_payment(bob, &[alice]);
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
}
5 changes: 5 additions & 0 deletions lightning/src/offers/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
self
}

pub(crate) fn clear_paths(mut self) -> Self {
self.offer.paths = None;
self
}

pub(super) fn build_unchecked(self) -> Offer {
self.build_without_checks()
}
Expand Down
5 changes: 5 additions & 0 deletions lightning/src/offers/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {

#[cfg(test)]
impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
pub(crate) fn clear_paths(mut self) -> Self {
self.refund.paths = None;
self
}

fn features_unchecked(mut self, features: InvoiceRequestFeatures) -> Self {
self.refund.features = features;
self
Expand Down

0 comments on commit 449252f

Please sign in to comment.