Skip to content

Commit 02714f7

Browse files
committed
multi: increase test coverage payments
The BOLT spec was updated and now requires the payment address for the writer and reader. We increase the test coverage for payments setting a wrong payment address.
1 parent 6b80796 commit 02714f7

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

invoices/invoiceregistry.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,11 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
10381038
)
10391039
switch {
10401040
case errors.Is(err, ErrInvoiceNotFound) ||
1041-
errors.Is(err, ErrNoInvoicesCreated):
1041+
errors.Is(err, ErrNoInvoicesCreated) ||
1042+
errors.Is(err, ErrInvRefEquivocation):
1043+
1044+
log.Debugf("Invoice not found with error: %v, failing htlc",
1045+
err)
10421046

10431047
// If the invoice was not found, return a failure resolution
10441048
// with an invoice not found result.

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ var allTestCases = []*lntest.TestCase{
683683
Name: "invoice migration",
684684
TestFunc: testInvoiceMigration,
685685
},
686+
{
687+
Name: "payment address mismatch",
688+
TestFunc: testWrongPaymentAddr,
689+
},
686690
{
687691
Name: "fee replacement",
688692
TestFunc: testFeeReplacement,

itest/lnd_payment_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,3 +1396,64 @@ func testSendPaymentKeysendMPPFail(ht *lntest.HarnessTest) {
13961396
_, err = ht.ReceivePaymentUpdate(client)
13971397
require.Error(ht, err)
13981398
}
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

Comments
 (0)