From 3353643006e6f206877e1adab74a8f7dd5b4f988 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 8 Dec 2022 17:54:39 +0800 Subject: [PATCH] itest: fix test `testListPayments` --- lntemp/harness.go | 6 +++--- lntemp/rpc/lnd.go | 4 ++++ lntest/itest/lnd_payment_test.go | 22 ++++++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lntemp/harness.go b/lntemp/harness.go index 75454c105..233495a41 100644 --- a/lntemp/harness.go +++ b/lntemp/harness.go @@ -294,6 +294,9 @@ func (h *HarnessTest) resetStandbyNodes(t *testing.T) { // config for the coming test. This will also inherit the // test's running context. h.RestartNodeWithExtraArgs(hn, hn.Cfg.OriginalExtraArgs) + + // Update the node's internal state. + hn.UpdateState() } } @@ -405,9 +408,6 @@ func (h *HarnessTest) cleanupStandbyNode(hn *node.HarnessNode) { // Delete all payments made from this test. hn.RPC.DeleteAllPayments() - // Update the node's internal state. - hn.UpdateState() - // Finally, check the node is in a clean state for the following tests. h.validateNodeState(hn) } diff --git a/lntemp/rpc/lnd.go b/lntemp/rpc/lnd.go index 894bfdbd3..7a95fbe35 100644 --- a/lntemp/rpc/lnd.go +++ b/lntemp/rpc/lnd.go @@ -194,6 +194,10 @@ func (h *HarnessRPC) ListInvoices( ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) defer cancel() + if req == nil { + req = &lnrpc.ListInvoiceRequest{} + } + resp, err := h.LN.ListInvoices(ctxt, req) h.NoError(err, "ListInvoice") diff --git a/lntest/itest/lnd_payment_test.go b/lntest/itest/lnd_payment_test.go index e965b7c3c..65343825e 100644 --- a/lntest/itest/lnd_payment_test.go +++ b/lntest/itest/lnd_payment_test.go @@ -1,7 +1,6 @@ package itest import ( - "bytes" "context" "crypto/sha256" "encoding/hex" @@ -31,11 +30,18 @@ func testListPayments(ht *lntemp.HarnessTest) { alice, bob, lntemp.OpenChannelParams{Amt: chanAmt}, ) + // Get the number of invoices Bob already has. + // + // TODO(yy): we can remove this check once the `DeleteAllInvoices` rpc + // is added. + invResp := bob.RPC.ListInvoices(nil) + numOldInvoices := len(invResp.Invoices) + // Now that the channel is open, create an invoice for Bob which // expects a payment of 1000 satoshis from Alice paid via a particular // preimage. const paymentAmt = 1000 - preimage := bytes.Repeat([]byte("B"), 32) + preimage := ht.Random32Bytes() invoice := &lnrpc.Invoice{ Memo: "testing", RPreimage: preimage, @@ -43,6 +49,10 @@ func testListPayments(ht *lntemp.HarnessTest) { } invoiceResp := bob.RPC.AddInvoice(invoice) + // Check that Bob has added the invoice. + numInvoices := numOldInvoices + 1 + ht.AssertNumInvoices(bob, 1) + // With the invoice for Bob added, send a payment towards Alice paying // to the above generated invoice. payReqs := []string{invoiceResp.PaymentRequest} @@ -113,8 +123,8 @@ func testListPayments(ht *lntemp.HarnessTest) { invReq := &lnrpc.ListInvoiceRequest{ CreationDateStart: 1227035905, } - invResp := bob.RPC.ListInvoices(invReq) - require.Len(ht, invResp.Invoices, 1) + invResp = bob.RPC.ListInvoices(invReq) + require.Len(ht, invResp.Invoices, numInvoices) // Use an end date long time ago should return us nothing. invReq = &lnrpc.ListInvoiceRequest{ @@ -135,7 +145,7 @@ func testListPayments(ht *lntemp.HarnessTest) { CreationDateEnd: 5392552705, } invResp = bob.RPC.ListInvoices(invReq) - require.Len(ht, invResp.Invoices, 1) + require.Len(ht, invResp.Invoices, numInvoices) // Delete all payments from Alice. DB should have no payments. alice.RPC.DeleteAllPayments() @@ -152,7 +162,7 @@ func testListPayments(ht *lntemp.HarnessTest) { time.Sleep(2 * time.Second) // Close the channel. - defer ht.CloseChannel(alice, chanPoint) + ht.CloseChannel(alice, chanPoint) } // testPaymentFollowingChannelOpen tests that the channel transition from