Skip to content

Commit c61b96f

Browse files
committed
f - expand tests
1 parent be7e2f3 commit c61b96f

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,20 @@ fn fails_authentication_when_handling_invoice_request() {
11201120
assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
11211121
}
11221122

1123+
let invalid_path = alice.node
1124+
.create_offer_builder(None)
1125+
.unwrap()
1126+
.build().unwrap()
1127+
.paths().first().unwrap()
1128+
.clone();
1129+
assert_eq!(invalid_path.introduction_node, IntroductionNode::NodeId(bob_id));
1130+
1131+
// Send the invoice request directly to Alice instead of using a blinded path.
11231132
let payment_id = PaymentId([1; 32]);
11241133
david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
11251134
.unwrap();
11261135
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
11271136

1128-
// Send the invoice request directly to Alice instead of using a blinded path.
11291137
connect_peers(david, alice);
11301138
#[cfg(not(c_bindings))] {
11311139
david.node.pending_offers_messages.lock().unwrap().first_mut().unwrap().destination =
@@ -1145,6 +1153,39 @@ fn fails_authentication_when_handling_invoice_request() {
11451153
assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(charlie_id));
11461154

11471155
assert_eq!(alice.onion_messenger.next_onion_message_for_peer(charlie_id), None);
1156+
1157+
david.node.abandon_payment(payment_id);
1158+
get_event!(david, Event::InvoiceRequestFailed);
1159+
1160+
// Send the invoice request to Alice using an invalid blinded path.
1161+
let payment_id = PaymentId([2; 32]);
1162+
david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
1163+
.unwrap();
1164+
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1165+
1166+
#[cfg(not(c_bindings))] {
1167+
david.node.pending_offers_messages.lock().unwrap().first_mut().unwrap().destination =
1168+
Destination::BlindedPath(invalid_path);
1169+
}
1170+
#[cfg(c_bindings)] {
1171+
david.node.pending_offers_messages.lock().unwrap().first_mut().unwrap().1 =
1172+
Destination::BlindedPath(invalid_path);
1173+
}
1174+
1175+
connect_peers(david, bob);
1176+
1177+
let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1178+
bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1179+
1180+
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1181+
alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1182+
1183+
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
1184+
assert_eq!(invoice_request.amount_msats(), None);
1185+
assert_ne!(invoice_request.payer_id(), david_id);
1186+
assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(charlie_id));
1187+
1188+
assert_eq!(alice.onion_messenger.next_onion_message_for_peer(charlie_id), None);
11481189
}
11491190

11501191
/// Check that authentication fails when an invoice is handled using the wrong context (i.e., was
@@ -1308,9 +1349,9 @@ fn fails_authentication_when_handling_invoice_for_refund() {
13081349
}
13091350
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
13101351

1352+
// Send the invoice directly to David instead of using a blinded path.
13111353
let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
13121354

1313-
// Send the invoice directly to David instead of using a blinded path.
13141355
connect_peers(david, alice);
13151356
#[cfg(not(c_bindings))] {
13161357
alice.node.pending_offers_messages.lock().unwrap().first_mut().unwrap().destination =
@@ -1328,6 +1369,43 @@ fn fails_authentication_when_handling_invoice_for_refund() {
13281369
assert_eq!(invoice, expected_invoice);
13291370

13301371
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1372+
1373+
// Send the invoice to David using an invalid blinded path.
1374+
let invalid_path = refund.paths().first().unwrap().clone();
1375+
let payment_id = PaymentId([2; 32]);
1376+
let refund = david.node
1377+
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
1378+
.unwrap()
1379+
.build().unwrap();
1380+
assert_ne!(refund.payer_id(), david_id);
1381+
assert!(!refund.paths().is_empty());
1382+
for path in refund.paths() {
1383+
assert_eq!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
1384+
}
1385+
1386+
let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
1387+
1388+
#[cfg(not(c_bindings))] {
1389+
alice.node.pending_offers_messages.lock().unwrap().first_mut().unwrap().destination =
1390+
Destination::BlindedPath(invalid_path);
1391+
}
1392+
#[cfg(c_bindings)] {
1393+
alice.node.pending_offers_messages.lock().unwrap().first_mut().unwrap().1 =
1394+
Destination::BlindedPath(invalid_path);
1395+
}
1396+
1397+
connect_peers(alice, charlie);
1398+
1399+
let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1400+
charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1401+
1402+
let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1403+
david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1404+
1405+
let invoice = extract_invoice(david, &onion_message);
1406+
assert_eq!(invoice, expected_invoice);
1407+
1408+
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
13311409
}
13321410

13331411
/// Fails creating or paying an offer when a blinded path cannot be created because no peers are

0 commit comments

Comments
 (0)