lntest: retry finding the payment from ListPayments

This commit is contained in:
yyforyongyu committed 2024-11-12 23:55:40 +08:00
1 parent 4506fd30cb
commit 90bca1022b
1 file changed
+14 -11
+14 -11
View File
@@ -1640,23 +1640,18 @@ func (h *HarnessTest) AssertNumHTLCsAndStage(hn *node.HarnessNode,
// findPayment queries the payment from the node's ListPayments which matches // findPayment queries the payment from the node's ListPayments which matches
// the specified preimage hash. // the specified preimage hash.
func (h *HarnessTest) findPayment(hn *node.HarnessNode, func (h *HarnessTest) findPayment(hn *node.HarnessNode,
paymentHash string) *lnrpc.Payment { paymentHash string) (*lnrpc.Payment, error) {
req := &lnrpc.ListPaymentsRequest{IncludeIncomplete: true} req := &lnrpc.ListPaymentsRequest{IncludeIncomplete: true}
paymentsResp := hn.RPC.ListPayments(req) paymentsResp := hn.RPC.ListPayments(req)
for _, p := range paymentsResp.Payments { for _, p := range paymentsResp.Payments {
if p.PaymentHash != paymentHash { if p.PaymentHash == paymentHash {
continue return p, nil
} }
return p
} }
require.Failf(h, "payment not found", "payment %v cannot be found", return nil, fmt.Errorf("payment %v cannot be found", paymentHash)
paymentHash)
return nil
} }
// PaymentCheck is a function that checks a payment for a specific condition. // PaymentCheck is a function that checks a payment for a specific condition.
@@ -1674,7 +1669,11 @@ func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
payHash := preimage.Hash() payHash := preimage.Hash()
err := wait.NoError(func() error { err := wait.NoError(func() error {
p := h.findPayment(hn, payHash.String()) p, err := h.findPayment(hn, payHash.String())
if err != nil {
return err
}
if status == p.Status { if status == p.Status {
target = p target = p
return nil return nil
@@ -1713,7 +1712,11 @@ func (h *HarnessTest) AssertPaymentFailureReason(hn *node.HarnessNode,
payHash := preimage.Hash() payHash := preimage.Hash()
err := wait.NoError(func() error { err := wait.NoError(func() error {
p := h.findPayment(hn, payHash.String()) p, err := h.findPayment(hn, payHash.String())
if err != nil {
return err
}
if reason == p.FailureReason { if reason == p.FailureReason {
return nil return nil
} }