itest: fix test testListPayments

This commit is contained in:
yyforyongyu 2022-12-08 17:54:39 +08:00
parent fe376385d1
commit 3353643006
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
3 changed files with 23 additions and 9 deletions

View File

@ -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)
}

View File

@ -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")

View File

@ -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