@@ -185,7 +185,20 @@ fn route_bolt12_payment<'a, 'b, 'c>(
185185fn claim_bolt12_payment < ' a , ' b , ' c > (
186186 node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] , expected_payment_context : PaymentContext , invoice : & Bolt12Invoice
187187) {
188- let recipient = & path[ path. len ( ) - 1 ] ;
188+ claim_bolt12_payment_with_fees (
189+ node,
190+ path,
191+ expected_payment_context,
192+ invoice,
193+ None ,
194+ )
195+ }
196+
197+ fn claim_bolt12_payment_with_fees < ' a , ' b , ' c > (
198+ node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] , expected_payment_context : PaymentContext , invoice : & Bolt12Invoice ,
199+ expected_extra_fees_msat : Option < u64 > ,
200+ ) {
201+ let recipient = path. last ( ) . expect ( "Empty path?" ) ;
189202 let payment_purpose = match get_event ! ( recipient, Event :: PaymentClaimable ) {
190203 Event :: PaymentClaimable { purpose, .. } => purpose,
191204 _ => panic ! ( "No Event::PaymentClaimable" ) ,
@@ -194,20 +207,29 @@ fn claim_bolt12_payment<'a, 'b, 'c>(
194207 Some ( preimage) => preimage,
195208 None => panic ! ( "No preimage in Event::PaymentClaimable" ) ,
196209 } ;
197- match payment_purpose {
198- PaymentPurpose :: Bolt12OfferPayment { payment_context, .. } => {
199- assert_eq ! ( PaymentContext :: Bolt12Offer ( payment_context) , expected_payment_context) ;
200- } ,
201- PaymentPurpose :: Bolt12RefundPayment { payment_context, .. } => {
202- assert_eq ! ( PaymentContext :: Bolt12Refund ( payment_context) , expected_payment_context) ;
203- } ,
210+ let context = match payment_purpose {
211+ PaymentPurpose :: Bolt12OfferPayment { payment_context, .. } =>
212+ PaymentContext :: Bolt12Offer ( payment_context) ,
213+ PaymentPurpose :: Bolt12RefundPayment { payment_context, .. } =>
214+ PaymentContext :: Bolt12Refund ( payment_context) ,
204215 _ => panic ! ( "Unexpected payment purpose: {:?}" , payment_purpose) ,
205- }
206- if let Some ( inv) = claim_payment ( node, path, payment_preimage) {
207- assert_eq ! ( inv, PaidBolt12Invoice :: Bolt12Invoice ( invoice. to_owned( ) ) ) ;
208- } else {
209- panic ! ( "Expected PaidInvoice::Bolt12Invoice" ) ;
210216 } ;
217+
218+ assert_eq ! ( context, expected_payment_context) ;
219+
220+ let expected_paths = [ path] ;
221+ let mut args = ClaimAlongRouteArgs :: new (
222+ node,
223+ & expected_paths,
224+ payment_preimage,
225+ ) ;
226+
227+ if let Some ( extra) = expected_extra_fees_msat {
228+ args = args. with_expected_extra_total_fees_msat ( extra) ;
229+ }
230+
231+ let ( inv, _) = claim_payment_along_route ( args) ;
232+ assert_eq ! ( inv, Some ( PaidBolt12Invoice :: Bolt12Invoice ( invoice. clone( ) ) ) ) ;
211233}
212234
213235fn extract_offer_nonce < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , message : & OnionMessage ) -> Nonce {
@@ -1410,41 +1432,7 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
14101432 route_bolt12_payment ( bob, & [ alice] , & invoice) ;
14111433 expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
14121434
1413- // Extract PaymentClaimable, verify context, and obtain the payment preimage.
1414- let recipient = & alice;
1415- let payment_purpose = match get_event ! ( recipient, Event :: PaymentClaimable ) {
1416- Event :: PaymentClaimable { purpose, .. } => purpose,
1417- _ => panic ! ( "No Event::PaymentClaimable" ) ,
1418- } ;
1419-
1420- let payment_preimage = payment_purpose
1421- . preimage ( )
1422- . expect ( "No preimage in Event::PaymentClaimable" ) ;
1423-
1424- match payment_purpose {
1425- PaymentPurpose :: Bolt12OfferPayment { payment_context : ctx, .. } => {
1426- assert_eq ! ( PaymentContext :: Bolt12Offer ( ctx) , payment_context) ;
1427- } ,
1428- PaymentPurpose :: Bolt12RefundPayment { payment_context : ctx, .. } => {
1429- assert_eq ! ( PaymentContext :: Bolt12Refund ( ctx) , payment_context) ;
1430- } ,
1431- _ => panic ! ( "Unexpected payment purpose: {:?}" , payment_purpose) ,
1432- } ;
1433-
1434- // Build ClaimAlongRouteArgs and compensate for the expected overpayment
1435- // caused by the payer being the introduction node of the blinded path with
1436- // dummy hops.
1437- let expected_paths: & [ & [ & Node ] ] = & [ & [ alice] ] ;
1438- let args = ClaimAlongRouteArgs :: new (
1439- bob,
1440- expected_paths,
1441- payment_preimage,
1442- ) . with_expected_extra_total_fees_msat ( 1000 ) ;
1443-
1444- // Execute the claim and verify the invoice was fulfilled.
1445- let ( inv, _events) = claim_payment_along_route ( args) ;
1446- assert_eq ! ( inv, Some ( PaidBolt12Invoice :: Bolt12Invoice ( invoice. clone( ) ) ) ) ;
1447-
1435+ claim_bolt12_payment_with_fees ( bob, & [ alice] , payment_context, & invoice, Some ( 1000 ) ) ;
14481436 expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
14491437}
14501438
0 commit comments