@@ -1396,3 +1396,64 @@ func testSendPaymentKeysendMPPFail(ht *lntest.HarnessTest) {
1396
1396
_ , err = ht .ReceivePaymentUpdate (client )
1397
1397
require .Error (ht , err )
1398
1398
}
1399
+
1400
+ // testWrongPaymentAddr is a test that checks that a payment using a wrong
1401
+ // payment address will fail.
1402
+ func testWrongPaymentAddr (ht * lntest.HarnessTest ) {
1403
+ // Set the feerate to be 10 sat/vb.
1404
+ ht .SetFeeEstimate (2500 )
1405
+
1406
+ // Open a channel with 100k satoshis between Alice and Bob with Alice
1407
+ // being the sole funder of the channel.
1408
+ chanAmt := btcutil .Amount (100_000 )
1409
+ openChannelParams := lntest.OpenChannelParams {
1410
+ Amt : chanAmt ,
1411
+ }
1412
+ cfgs := [][]string {nil , nil }
1413
+
1414
+ invoiceAmt := int64 (1000 )
1415
+
1416
+ // Create a two hop network: Alice -> Bob.
1417
+ _ , nodes := ht .CreateSimpleNetwork (cfgs , openChannelParams )
1418
+
1419
+ alice , bob := nodes [0 ], nodes [1 ]
1420
+
1421
+ request1 := bob .RPC .AddInvoice (& lnrpc.Invoice {
1422
+ ValueMsat : invoiceAmt ,
1423
+ CltvExpiry : finalCltvDelta ,
1424
+ })
1425
+
1426
+ request2 := bob .RPC .AddInvoice (& lnrpc.Invoice {
1427
+ ValueMsat : invoiceAmt ,
1428
+ CltvExpiry : finalCltvDelta ,
1429
+ })
1430
+ payReq2 := alice .RPC .DecodePayReq (request2 .PaymentRequest )
1431
+
1432
+ ht .AssertNumInvoices (bob , 2 )
1433
+
1434
+ // Now we don't want to use the payment request to send the payment
1435
+ // because we want to use the payment_addr two for the payment of the
1436
+ // invoice 1 to simulate the case where the payment address is wrong.
1437
+ route := alice .RPC .BuildRoute (
1438
+ & routerrpc.BuildRouteRequest {
1439
+ PaymentAddr : payReq2 .PaymentAddr ,
1440
+ AmtMsat : invoiceAmt ,
1441
+ FinalCltvDelta : finalCltvDelta ,
1442
+ HopPubkeys : [][]byte {bob .PubKey [:]},
1443
+ },
1444
+ )
1445
+
1446
+ // Send the payment and expect it to fail the payment.
1447
+ htlcAttempt := alice .RPC .SendToRouteV2 (
1448
+ & routerrpc.SendToRouteRequest {
1449
+ Route : route .Route ,
1450
+ PaymentHash : request1 .RHash ,
1451
+ },
1452
+ )
1453
+ require .Equal (ht , lnrpc .HTLCAttempt_FAILED , htlcAttempt .Status )
1454
+
1455
+ // Make sure the payment is marked as failed also in the database.
1456
+ ht .AssertPaymentStatus (
1457
+ alice , lntypes .Hash (request1 .RHash ), lnrpc .Payment_FAILED ,
1458
+ )
1459
+ }
0 commit comments