Skip to content

Commit

Permalink
itest: end to end route blinding invoices test
Browse files Browse the repository at this point in the history
Update one of the route blinding itests to do a full end-to-end test
where the recipient generates and invoice with a blinded path and the
sender just provides that invoice to SendPayment.

The tests also covers the edge case where the recipient is the
introduction node.
  • Loading branch information
ellemouton committed Jul 26, 2024
1 parent 735d7d9 commit 64a99d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ var allTestCases = []*lntest.TestCase{
TestFunc: testQueryBlindedRoutes,
},
{
Name: "forward and receive blinded",
TestFunc: testForwardAndReceiveBlindedRoute,
Name: "route blinding invoices",
TestFunc: testBlindedRouteInvoices,
},
{
Name: "receiver blinded error",
Expand Down
50 changes: 40 additions & 10 deletions itest/lnd_route_blinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,24 +600,54 @@ func setupFourHopNetwork(ht *lntest.HarnessTest,
}
}

// testForwardAndReceiveBlindedRoute tests lnd's ability to create a blinded
// payment path, forward payments in a blinded route and receive the payment.
func testForwardAndReceiveBlindedRoute(ht *lntest.HarnessTest) {
// testBlindedRouteInvoices tests lnd's ability to create a blinded payment path
// which it then inserts into an invoice, sending to an invoice with a blinded
// path and forward payments in a blinded route and finally, receiving the
// payment.
func testBlindedRouteInvoices(ht *lntest.HarnessTest) {
ctx, testCase := newBlindedForwardTest(ht)
defer testCase.cleanup()

// Set up the 4 hop network and let Dave create an invoice with a
// blinded path that uses Bob as an introduction node.
testCase.setupNetwork(ctx, false)
blindedPaymentPath := testCase.buildBlindedPath()

// Construct a full route from Alice to Dave using the blinded payment
// path.
route := testCase.createRouteToBlinded(10_000_000, blindedPaymentPath)
// Let Dave add a blinded invoice.
invoice := testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{
Memo: "test",
ValueMsat: 10_000_000,
Blind: true,
})

// Let Alice send to the constructed route and assert that the payment
// succeeds.
testCase.sendToRoute(route, true)
// Now let Alice pay the invoice.
ht.CompletePaymentRequests(ht.Alice, []string{invoice.PaymentRequest})

// Restart Dave with blinded path restrictions that will result in him
// creating a blinded path that uses himself as the introduction node.
ht.RestartNodeWithExtraArgs(testCase.dave, []string{
"--invoices.blinding.min-num-real-hops=0",
"--invoices.blinding.num-hops=0",
})
ht.EnsureConnected(testCase.dave, testCase.carol)

// Let Dave add a blinded invoice.
// Once again let Dave create a blinded invoice.
invoice = testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{
Memo: "test",
ValueMsat: 10_000_000,
Blind: true,
})

// Assert that it contains a single blinded path with only an
// introduction node hop where the introduction node is Dave.
payReq := testCase.dave.RPC.DecodePayReq(invoice.PaymentRequest)
require.Len(ht, payReq.BlindedPaths, 1)
path := payReq.BlindedPaths[0].BlindedPath
require.Len(ht, path.BlindedHops, 1)
require.EqualValues(ht, path.IntroductionNode, testCase.dave.PubKey[:])

// Now let Alice pay the invoice.
ht.CompletePaymentRequests(ht.Alice, []string{invoice.PaymentRequest})
}

// testReceiverBlindedError tests handling of errors from the receiving node in
Expand Down

0 comments on commit 64a99d4

Please sign in to comment.