From 29652d88eeedd2c63306707c6603c99df667c1e7 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sat, 19 Nov 2022 03:30:28 +0800 Subject: [PATCH] lntest: add itest for timestamp filters --- lntemp/harness_assertion.go | 3 +- lntest/itest/lnd_payment_test.go | 64 +++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/lntemp/harness_assertion.go b/lntemp/harness_assertion.go index ab93af89a..d48c5ada2 100644 --- a/lntemp/harness_assertion.go +++ b/lntemp/harness_assertion.go @@ -1273,7 +1273,8 @@ func (h *HarnessTest) findPayment(hn *node.HarnessNode, return p } - require.Fail(h, "payment: %v not found", paymentHash) + require.Failf(h, "payment not found", "payment %v cannot be found", + paymentHash) return nil } diff --git a/lntest/itest/lnd_payment_test.go b/lntest/itest/lnd_payment_test.go index 01627fecd..e965b7c3c 100644 --- a/lntest/itest/lnd_payment_test.go +++ b/lntest/itest/lnd_payment_test.go @@ -72,11 +72,71 @@ func testListPayments(ht *lntemp.HarnessTest) { require.Zero(ht, p.FeeSat, "fee should be 0") require.Zero(ht, p.FeeMsat, "fee should be 0") - // Finally, verify that the payment request returned by the rpc matches - // the invoice that we paid. + // Now verify that the payment request returned by the rpc matches the + // invoice that we paid. require.Equal(ht, invoiceResp.PaymentRequest, p.PaymentRequest, "incorrect payreq") + // We now check the timestamp filters in `ListPayments`. + // + // Use a start date long time ago should return us the payment. + req := &lnrpc.ListPaymentsRequest{ + CreationDateStart: 1227035905, + } + resp := alice.RPC.ListPayments(req) + require.Len(ht, resp.Payments, 1) + + // Use an end date long time ago should return us nothing. + req = &lnrpc.ListPaymentsRequest{ + CreationDateEnd: 1227035905, + } + resp = alice.RPC.ListPayments(req) + require.Empty(ht, resp.Payments) + + // Use a start date far in the future should return us nothing. + req = &lnrpc.ListPaymentsRequest{ + CreationDateStart: 5392552705, + } + resp = alice.RPC.ListPayments(req) + require.Empty(ht, resp.Payments) + + // Use an end date far in the future should return us the payment. + req = &lnrpc.ListPaymentsRequest{ + CreationDateEnd: 5392552705, + } + resp = alice.RPC.ListPayments(req) + require.Len(ht, resp.Payments, 1) + + // We now do the same check for `ListInvoices` + // + // Use a start date long time ago should return us the invoice. + invReq := &lnrpc.ListInvoiceRequest{ + CreationDateStart: 1227035905, + } + invResp := bob.RPC.ListInvoices(invReq) + require.Len(ht, invResp.Invoices, 1) + + // Use an end date long time ago should return us nothing. + invReq = &lnrpc.ListInvoiceRequest{ + CreationDateEnd: 1227035905, + } + invResp = bob.RPC.ListInvoices(invReq) + require.Empty(ht, invResp.Invoices) + + // Use a start date far in the future should return us nothing. + invReq = &lnrpc.ListInvoiceRequest{ + CreationDateStart: 5392552705, + } + invResp = bob.RPC.ListInvoices(invReq) + require.Empty(ht, invResp.Invoices) + + // Use an end date far in the future should return us the invoice. + invReq = &lnrpc.ListInvoiceRequest{ + CreationDateEnd: 5392552705, + } + invResp = bob.RPC.ListInvoices(invReq) + require.Len(ht, invResp.Invoices, 1) + // Delete all payments from Alice. DB should have no payments. alice.RPC.DeleteAllPayments()