• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 10207481183

01 Aug 2024 11:52PM UTC coverage: 58.679% (+0.09%) from 58.591%
10207481183

push

github

web-flow
Merge pull request #8836 from hieblmi/payment-failure-reason-cancel

routing: add payment failure reason `FailureReasonCancel`

7 of 30 new or added lines in 5 files covered. (23.33%)

1662 existing lines in 21 files now uncovered.

125454 of 213798 relevant lines covered (58.68%)

28679.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lntest/rpc/router.go
1
package rpc
2

3
import (
4
        "context"
5

6
        "github.com/lightningnetwork/lnd/lnrpc"
7
        "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
8
        "github.com/stretchr/testify/require"
9
)
10

11
// =====================
12
// RouterClient related RPCs.
13
// =====================
14

15
// UpdateChanStatus makes a UpdateChanStatus RPC call to node's RouterClient
16
// and asserts.
17
//
18
//nolint:lll
19
func (h *HarnessRPC) UpdateChanStatus(
20
        req *routerrpc.UpdateChanStatusRequest) *routerrpc.UpdateChanStatusResponse {
×
21

×
22
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
23
        defer cancel()
×
24

×
25
        resp, err := h.Router.UpdateChanStatus(ctxt, req)
×
26
        h.NoError(err, "UpdateChanStatus")
×
27

×
28
        return resp
×
29
}
×
30

31
type PaymentClient routerrpc.Router_SendPaymentV2Client
32

33
// SendPayment sends a payment using the given node and payment request. It
34
// also asserts the payment being sent successfully.
35
func (h *HarnessRPC) SendPayment(
36
        req *routerrpc.SendPaymentRequest) PaymentClient {
×
37

×
38
        // SendPayment needs to have the context alive for the entire test case
×
NEW
39
        // as the router relies on the context to propagate HTLCs. Thus, we use
×
40
        // runCtx here instead of a timeout context.
×
41
        stream, err := h.Router.SendPaymentV2(h.runCtx, req)
×
42
        h.NoError(err, "SendPaymentV2")
×
43

×
44
        return stream
×
45
}
×
46

47
// SendPaymentWithContext sends a payment using the given node and payment
48
// request and does so with the passed in context.
49
func (h *HarnessRPC) SendPaymentWithContext(context context.Context,
NEW
50
        req *routerrpc.SendPaymentRequest) PaymentClient {
×
NEW
51

×
NEW
52
        require.NotNil(h.T, context, "context must not be nil")
×
NEW
53

×
NEW
54
        // SendPayment needs to have the context alive for the entire test case
×
NEW
55
        // as the router relies on the context to propagate HTLCs.
×
NEW
56
        stream, err := h.Router.SendPaymentV2(context, req)
×
NEW
57
        h.NoError(err, "SendPaymentV2")
×
NEW
58

×
NEW
59
        return stream
×
NEW
60
}
×
61

62
type HtlcEventsClient routerrpc.Router_SubscribeHtlcEventsClient
63

64
// SubscribeHtlcEvents makes a subscription to the HTLC events and returns a
65
// htlc event client.
66
func (h *HarnessRPC) SubscribeHtlcEvents() HtlcEventsClient {
×
67
        // Use runCtx here to keep the client alive for the scope of the test.
×
68
        client, err := h.Router.SubscribeHtlcEvents(
×
69
                h.runCtx, &routerrpc.SubscribeHtlcEventsRequest{},
×
70
        )
×
71
        h.NoError(err, "SubscribeHtlcEvents")
×
72

×
73
        return client
×
74
}
×
75

76
// GetMissionControlConfig makes a RPC call to the node's
77
// GetMissionControlConfig and asserts.
78
//
79
//nolint:lll
80
func (h *HarnessRPC) GetMissionControlConfig() *routerrpc.GetMissionControlConfigResponse {
×
81
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
82
        defer cancel()
×
83

×
84
        req := &routerrpc.GetMissionControlConfigRequest{}
×
85
        resp, err := h.Router.GetMissionControlConfig(ctxt, req)
×
86
        h.NoError(err, "GetMissionControlConfig")
×
87

×
88
        return resp
×
89
}
×
90

91
// SetMissionControlConfig makes a RPC call to the node's
92
// SetMissionControlConfig and asserts.
93
func (h *HarnessRPC) SetMissionControlConfig(
94
        config *routerrpc.MissionControlConfig) {
×
95

×
96
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
97
        defer cancel()
×
98

×
99
        req := &routerrpc.SetMissionControlConfigRequest{Config: config}
×
100
        _, err := h.Router.SetMissionControlConfig(ctxt, req)
×
101
        h.NoError(err, "SetMissionControlConfig")
×
102
}
×
103

104
// SetMissionControlConfigAssertErr makes a RPC call to the node's
105
// SetMissionControlConfig and asserts that we error.
106
func (h *HarnessRPC) SetMissionControlConfigAssertErr(
107
        config *routerrpc.MissionControlConfig) {
×
108

×
109
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
110
        defer cancel()
×
111

×
112
        req := &routerrpc.SetMissionControlConfigRequest{Config: config}
×
113
        _, err := h.Router.SetMissionControlConfig(ctxt, req)
×
114
        require.Error(h, err, "expect an error from setting import mission "+
×
115
                "control")
×
116
}
×
117

118
// ResetMissionControl makes a RPC call to the node's ResetMissionControl and
119
// asserts.
120
func (h *HarnessRPC) ResetMissionControl() {
×
121
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
122
        defer cancel()
×
123

×
124
        req := &routerrpc.ResetMissionControlRequest{}
×
125
        _, err := h.Router.ResetMissionControl(ctxt, req)
×
126
        h.NoError(err, "ResetMissionControl")
×
127
}
×
128

129
// SendToRouteV2 makes a RPC call to SendToRouteV2 and asserts.
130
func (h *HarnessRPC) SendToRouteV2(
131
        req *routerrpc.SendToRouteRequest) *lnrpc.HTLCAttempt {
×
132

×
133
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
134
        defer cancel()
×
135

×
136
        resp, err := h.Router.SendToRouteV2(ctxt, req)
×
137
        h.NoError(err, "SendToRouteV2")
×
138

×
139
        return resp
×
140
}
×
141

142
// QueryProbability makes a RPC call to the node's QueryProbability and
143
// asserts.
144
//
145
//nolint:lll
146
func (h *HarnessRPC) QueryProbability(
147
        req *routerrpc.QueryProbabilityRequest) *routerrpc.QueryProbabilityResponse {
×
148

×
149
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
150
        defer cancel()
×
151

×
152
        resp, err := h.Router.QueryProbability(ctxt, req)
×
153
        h.NoError(err, "QueryProbability")
×
154

×
155
        return resp
×
156
}
×
157

158
// XImportMissionControl makes a RPC call to the node's XImportMissionControl
159
// and asserts.
160
func (h *HarnessRPC) XImportMissionControl(
161
        req *routerrpc.XImportMissionControlRequest) {
×
162

×
163
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
164
        defer cancel()
×
165

×
166
        _, err := h.Router.XImportMissionControl(ctxt, req)
×
167
        h.NoError(err, "XImportMissionControl")
×
168
}
×
169

170
// XImportMissionControlAssertErr makes a RPC call to the node's
171
// XImportMissionControl
172
// and asserts an error occurred.
173
func (h *HarnessRPC) XImportMissionControlAssertErr(
174
        req *routerrpc.XImportMissionControlRequest) {
×
175

×
176
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
177
        defer cancel()
×
178

×
179
        _, err := h.Router.XImportMissionControl(ctxt, req)
×
180
        require.Error(h, err, "expect an error from x import mission control")
×
181
}
×
182

183
// BuildRoute makes a RPC call to the node's RouterClient and asserts.
184
func (h *HarnessRPC) BuildRoute(
185
        req *routerrpc.BuildRouteRequest) *routerrpc.BuildRouteResponse {
×
186

×
187
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
188
        defer cancel()
×
189

×
190
        resp, err := h.Router.BuildRoute(ctxt, req)
×
191
        h.NoError(err, "BuildRoute")
×
192

×
193
        return resp
×
194
}
×
195

196
type InterceptorClient routerrpc.Router_HtlcInterceptorClient
197

198
// HtlcInterceptor makes a RPC call to the node's RouterClient and asserts.
199
func (h *HarnessRPC) HtlcInterceptor() (InterceptorClient, context.CancelFunc) {
×
200
        // HtlcInterceptor needs to have the context alive for the entire test
×
201
        // case as the returned client will be used for send and receive events
×
202
        // stream. Thus we use cancel context here instead of a timeout
×
203
        // context.
×
204
        ctxt, cancel := context.WithCancel(h.runCtx)
×
205
        resp, err := h.Router.HtlcInterceptor(ctxt)
×
206
        h.NoError(err, "HtlcInterceptor")
×
207

×
208
        return resp, cancel
×
209
}
×
210

211
type TrackPaymentsClient routerrpc.Router_TrackPaymentsClient
212

213
// TrackPayments makes a RPC call to the node's RouterClient and asserts.
214
func (h *HarnessRPC) TrackPayments(
215
        req *routerrpc.TrackPaymentsRequest) TrackPaymentsClient {
×
216

×
217
        resp, err := h.Router.TrackPayments(h.runCtx, req)
×
218
        h.NoError(err, "TrackPayments")
×
219

×
220
        return resp
×
221
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc