From 4ac6f82b5ed95dc0648ab8ecd6a7005e5faa96e5 Mon Sep 17 00:00:00 2001 From: carla Date: Mon, 7 Feb 2022 09:03:09 +0200 Subject: [PATCH] itest: fix lack of hop hint coverage in hold invoice test Update our test to assert that we have hop hints present when we expect them, and fix the "alice is a private node" issue that was previously preventing us from adding hop hints. Asserting that we have hop hints present in this itest ensures that we'll fail our itests if a change to SelectHopHints results in our no longer having hints in this secnario. --- lntest/itest/lnd_hold_persistence_test.go | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lntest/itest/lnd_hold_persistence_test.go b/lntest/itest/lnd_hold_persistence_test.go index f60121742..0782c87ab 100644 --- a/lntest/itest/lnd_hold_persistence_test.go +++ b/lntest/itest/lnd_hold_persistence_test.go @@ -60,6 +60,26 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { "timeout: %v", err) } + // For Carol to include her private channel with Alice as a hop hint, + // we need Alice to be perceived as a "public" node, meaning that she + // has at least one public channel in the graph. We open a public + // channel from Alice -> Bob and wait for Carol to see it. + chanPointBob := openChannelAndAssert( + t, net, net.Alice, net.Bob, + lntest.OpenChannelParams{ + Amt: chanAmt, + }, + ) + + // Wait for Alice and Carol to see the open channel + err = net.Alice.WaitForNetworkChannelOpen(chanPointBob) + require.NoError(t.t, err, "alice didn't see the alice->bob "+ + "channel before timeout") + + err = carol.WaitForNetworkChannelOpen(chanPointBob) + require.NoError(t.t, err, "carol didn't see the alice->bob "+ + "channel before timeout") + // Create preimages for all payments we are going to initiate. var preimages []lntypes.Preimage for i := 0; i < numPayments; i++ { @@ -109,6 +129,18 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { t.Fatalf("unable to subscribe to invoice: %v", err) } + // We expect all of our invoices to have hop hints attached, + // since Carol and Alice are connected with a private channel. + // We assert that we have one hop hint present to ensure that + // we've got coverage for hop hints. + ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + decodeReq := &lnrpc.PayReqString{ + PayReq: resp.PaymentRequest, + } + invoice, err := net.Alice.DecodePayReq(ctxt, decodeReq) + require.NoError(t.t, err, "could not decode invoice") + require.Len(t.t, invoice.RouteHints, 1) + invoiceStreams = append(invoiceStreams, stream) payReqs = append(payReqs, resp.PaymentRequest) } @@ -229,7 +261,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) { } // Now after a restart, we must re-track the payments. We set up a - // goroutine for each to track thir status updates. + // goroutine for each to track their status updates. var ( statusUpdates []chan *lnrpc.Payment wg sync.WaitGroup