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

lightningnetwork / lnd / 15759452760

19 Jun 2025 01:48PM UTC coverage: 69.436% (+1.3%) from 68.161%
15759452760

Pull #9625

github

web-flow
Merge 469117657 into e0a9705d5
Pull Request #9625: Add DeleteInvoice gRPC call

88 of 164 new or added lines in 5 files covered. (53.66%)

65 existing lines in 22 files now uncovered.

137612 of 198185 relevant lines covered (69.44%)

22066.8 hits per line

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

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

3
import (
4
        "context"
5
        "strings"
6

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

12
// =====================
13
// LightningClient related RPCs.
14
// =====================
15

16
// NewAddress makes a RPC call to NewAddress and asserts.
17
func (h *HarnessRPC) NewAddress(
18
        req *lnrpc.NewAddressRequest) *lnrpc.NewAddressResponse {
×
19

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

×
23
        resp, err := h.LN.NewAddress(ctxt, req)
×
24
        h.NoError(err, "NewAddress")
×
25

×
26
        return resp
×
27
}
×
28

29
// WalletBalance makes a RPC call to WalletBalance and asserts.
30
func (h *HarnessRPC) WalletBalance() *lnrpc.WalletBalanceResponse {
×
31
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
32
        defer cancel()
×
33

×
34
        req := &lnrpc.WalletBalanceRequest{}
×
35
        resp, err := h.LN.WalletBalance(ctxt, req)
×
36
        h.NoError(err, "WalletBalance")
×
37

×
38
        return resp
×
39
}
×
40

41
// ListPeers makes a RPC call to the node's ListPeers and asserts.
42
func (h *HarnessRPC) ListPeers() *lnrpc.ListPeersResponse {
×
43
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
44
        defer cancel()
×
45

×
46
        resp, err := h.LN.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
×
47
        h.NoError(err, "ListPeers")
×
48

×
49
        return resp
×
50
}
×
51

52
// DisconnectPeer calls the DisconnectPeer RPC on a given node with a specified
53
// public key string and asserts there's no error.
54
func (h *HarnessRPC) DisconnectPeer(
55
        pubkey string) *lnrpc.DisconnectPeerResponse {
×
56

×
57
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
58
        defer cancel()
×
59

×
60
        req := &lnrpc.DisconnectPeerRequest{PubKey: pubkey}
×
61

×
62
        resp, err := h.LN.DisconnectPeer(ctxt, req)
×
63
        h.NoError(err, "DisconnectPeer")
×
64

×
65
        return resp
×
66
}
×
67

68
// DeleteAllPayments makes a RPC call to the node's DeleteAllPayments and
69
// asserts.
70
func (h *HarnessRPC) DeleteAllPayments() {
×
71
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
72
        defer cancel()
×
73

×
74
        req := &lnrpc.DeleteAllPaymentsRequest{AllPayments: true}
×
75
        _, err := h.LN.DeleteAllPayments(ctxt, req)
×
76
        h.NoError(err, "DeleteAllPayments")
×
77
}
×
78

79
// GetInfo calls the GetInfo RPC on a given node and asserts there's no error.
80
func (h *HarnessRPC) GetInfo() *lnrpc.GetInfoResponse {
×
81
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
82
        defer cancel()
×
83

×
84
        info, err := h.LN.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
×
85
        h.NoError(err, "GetInfo")
×
86

×
87
        return info
×
88
}
×
89

90
// ConnectPeer makes a RPC call to ConnectPeer and asserts there's no error.
91
func (h *HarnessRPC) ConnectPeer(
92
        req *lnrpc.ConnectPeerRequest) *lnrpc.ConnectPeerResponse {
×
93

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

×
97
        resp, err := h.LN.ConnectPeer(ctxt, req)
×
98
        h.NoError(err, "ConnectPeer")
×
99

×
100
        return resp
×
101
}
×
102

103
// ConnectPeerAssertErr makes a RPC call to ConnectPeer and asserts an error
104
// returned.
105
func (h *HarnessRPC) ConnectPeerAssertErr(req *lnrpc.ConnectPeerRequest) error {
×
106
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
107
        defer cancel()
×
108

×
109
        _, err := h.LN.ConnectPeer(ctxt, req)
×
110
        require.Error(h, err, "expected an error from ConnectPeer")
×
111

×
112
        return err
×
113
}
×
114

115
// ListChannels list the channels for the given node and asserts it's
116
// successful.
117
func (h *HarnessRPC) ListChannels(
118
        req *lnrpc.ListChannelsRequest) *lnrpc.ListChannelsResponse {
×
119

×
120
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
121
        defer cancel()
×
122

×
123
        resp, err := h.LN.ListChannels(ctxt, req)
×
124
        h.NoError(err, "ListChannels")
×
125

×
126
        return resp
×
127
}
×
128

129
// PendingChannels makes a RPC request to PendingChannels and asserts there's
130
// no error.
131
func (h *HarnessRPC) PendingChannels() *lnrpc.PendingChannelsResponse {
×
132
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
133
        defer cancel()
×
134

×
135
        pendingChansRequest := &lnrpc.PendingChannelsRequest{
×
136
                IncludeRawTx: true,
×
137
        }
×
138
        resp, err := h.LN.PendingChannels(ctxt, pendingChansRequest)
×
139

×
140
        // TODO(yy): We may get a `unable to find arbitrator` error from the
×
141
        // rpc point, due to a timing issue in rpcserver,
×
142
        // 1. `r.server.chanStateDB.FetchClosedChannels` fetches
×
143
        //    the pending force close channel.
×
144
        // 2. `r.arbitratorPopulateForceCloseResp` relies on the
×
145
        //    channel arbitrator to get the report, and,
×
146
        // 3. the arbitrator may be deleted due to the force close
×
147
        //    channel being resolved.
×
148
        // Somewhere along the line is missing a lock to keep the data
×
149
        // consistent.
×
150
        //
×
151
        // Return if there's no error.
×
152
        if err == nil {
×
153
                return resp
×
154
        }
×
155

156
        // Otherwise, give it a second shot if it's the arbitrator error.
157
        if strings.Contains(err.Error(), "unable to find arbitrator") {
×
158
                resp, err = h.LN.PendingChannels(ctxt, pendingChansRequest)
×
159
        }
×
160

161
        // It's very unlikely we'd get the arbitrator not found error again.
162
        h.NoError(err, "PendingChannels")
×
163

×
164
        return resp
×
165
}
166

167
// ClosedChannels makes a RPC call to node's ClosedChannels and asserts.
168
func (h *HarnessRPC) ClosedChannels(
169
        req *lnrpc.ClosedChannelsRequest) *lnrpc.ClosedChannelsResponse {
×
170

×
171
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
172
        defer cancel()
×
173

×
174
        resp, err := h.LN.ClosedChannels(ctxt, req)
×
175
        h.NoError(err, "ClosedChannels")
×
176

×
177
        return resp
×
178
}
×
179

180
// ListPayments lists the node's payments and asserts.
181
func (h *HarnessRPC) ListPayments(
182
        req *lnrpc.ListPaymentsRequest) *lnrpc.ListPaymentsResponse {
×
183

×
184
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
185
        defer cancel()
×
186

×
187
        resp, err := h.LN.ListPayments(ctxt, req)
×
188
        h.NoError(err, "ListPayments")
×
189

×
190
        return resp
×
191
}
×
192

193
// ListInvoices list the node's invoice using the request and asserts.
194
func (h *HarnessRPC) ListInvoices(
195
        req *lnrpc.ListInvoiceRequest) *lnrpc.ListInvoiceResponse {
×
196

×
197
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
198
        defer cancel()
×
199

×
200
        if req == nil {
×
201
                req = &lnrpc.ListInvoiceRequest{}
×
202
        }
×
203

204
        resp, err := h.LN.ListInvoices(ctxt, req)
×
205
        h.NoError(err, "ListInvoice")
×
206

×
207
        return resp
×
208
}
209

210
// DescribeGraph makes a RPC call to the node's DescribeGraph and asserts. It
211
// takes a bool to indicate whether we want to include private edges or not.
212
func (h *HarnessRPC) DescribeGraph(
213
        req *lnrpc.ChannelGraphRequest) *lnrpc.ChannelGraph {
×
214

×
215
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
216
        defer cancel()
×
217

×
218
        resp, err := h.LN.DescribeGraph(ctxt, req)
×
219
        h.NoError(err, "DescribeGraph")
×
220

×
221
        return resp
×
222
}
×
223

224
// ChannelBalance gets the channel balance and asserts.
225
func (h *HarnessRPC) ChannelBalance() *lnrpc.ChannelBalanceResponse {
×
226
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
227
        defer cancel()
×
228

×
229
        req := &lnrpc.ChannelBalanceRequest{}
×
230
        resp, err := h.LN.ChannelBalance(ctxt, req)
×
231
        h.NoError(err, "ChannelBalance")
×
232

×
233
        return resp
×
234
}
×
235

236
type OpenChanClient lnrpc.Lightning_OpenChannelClient
237

238
// OpenChannel makes a rpc call to LightningClient and returns the open channel
239
// client.
240
func (h *HarnessRPC) OpenChannel(req *lnrpc.OpenChannelRequest) OpenChanClient {
×
241
        stream, err := h.LN.OpenChannel(h.runCtx, req)
×
242
        h.NoError(err, "OpenChannel")
×
243

×
244
        return stream
×
245
}
×
246

247
type CloseChanClient lnrpc.Lightning_CloseChannelClient
248

249
// CloseChannel makes a rpc call to LightningClient and returns the close
250
// channel client.
251
func (h *HarnessRPC) CloseChannel(
252
        req *lnrpc.CloseChannelRequest) CloseChanClient {
×
253

×
254
        // Use runCtx here instead of a timeout context to keep the client
×
255
        // alive for the entire test case.
×
256
        stream, err := h.LN.CloseChannel(h.runCtx, req)
×
257
        h.NoError(err, "CloseChannel")
×
258

×
259
        return stream
×
260
}
×
261

262
// FundingStateStep makes a RPC call to FundingStateStep and asserts.
263
func (h *HarnessRPC) FundingStateStep(
264
        msg *lnrpc.FundingTransitionMsg) *lnrpc.FundingStateStepResp {
×
265

×
266
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
267
        defer cancel()
×
268

×
269
        resp, err := h.LN.FundingStateStep(ctxt, msg)
×
270
        h.NoError(err, "FundingStateStep")
×
271

×
272
        return resp
×
273
}
×
274

275
// FundingStateStepAssertErr makes a RPC call to FundingStateStep and asserts
276
// there's an error.
277
func (h *HarnessRPC) FundingStateStepAssertErr(m *lnrpc.FundingTransitionMsg) {
×
278
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
279
        defer cancel()
×
280

×
281
        _, err := h.LN.FundingStateStep(ctxt, m)
×
282
        require.Error(h, err, "expected an error from FundingStateStep")
×
283
}
×
284

285
// AddInvoice adds a invoice for the given node and asserts.
286
func (h *HarnessRPC) AddInvoice(req *lnrpc.Invoice) *lnrpc.AddInvoiceResponse {
×
287
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
288
        defer cancel()
×
289

×
290
        invoice, err := h.LN.AddInvoice(ctxt, req)
×
291
        h.NoError(err, "AddInvoice")
×
292

×
293
        return invoice
×
294
}
×
295

296
// AddInvoiceAssertErr makes a RPC call to AddInvoice and asserts an error
297
// has returned with a specific error message.
298
func (h *HarnessRPC) AddInvoiceAssertErr(req *lnrpc.Invoice, errStr string) {
×
299
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
300
        defer cancel()
×
301

×
302
        _, err := h.LN.AddInvoice(ctxt, req)
×
303
        require.ErrorContains(h, err, errStr)
×
304
}
×
305

306
// AbandonChannel makes a RPC call to AbandonChannel and asserts.
307
func (h *HarnessRPC) AbandonChannel(
308
        req *lnrpc.AbandonChannelRequest) *lnrpc.AbandonChannelResponse {
×
309

×
310
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
311
        defer cancel()
×
312

×
313
        resp, err := h.LN.AbandonChannel(ctxt, req)
×
314
        h.NoError(err, "AbandonChannel")
×
315

×
316
        return resp
×
317
}
×
318

319
// ExportAllChanBackups makes a RPC call to the node's ExportAllChannelBackups
320
// and asserts.
321
func (h *HarnessRPC) ExportAllChanBackups() *lnrpc.ChanBackupSnapshot {
×
322
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
323
        defer cancel()
×
324

×
325
        req := &lnrpc.ChanBackupExportRequest{}
×
326
        chanBackup, err := h.LN.ExportAllChannelBackups(ctxt, req)
×
327
        h.NoError(err, "ExportAllChannelBackups")
×
328

×
329
        return chanBackup
×
330
}
×
331

332
// ExportChanBackup makes a RPC call to the node's ExportChannelBackup
333
// and asserts.
334
func (h *HarnessRPC) ExportChanBackup(
335
        chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelBackup {
×
336

×
337
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
338
        defer cancel()
×
339

×
340
        req := &lnrpc.ExportChannelBackupRequest{
×
341
                ChanPoint: chanPoint,
×
342
        }
×
343
        chanBackup, err := h.LN.ExportChannelBackup(ctxt, req)
×
344
        h.NoError(err, "ExportChannelBackup")
×
345

×
346
        return chanBackup
×
347
}
×
348

349
// RestoreChanBackups makes a RPC call to the node's RestoreChannelBackups and
350
// asserts.
351
func (h *HarnessRPC) RestoreChanBackups(
352
        req *lnrpc.RestoreChanBackupRequest) *lnrpc.RestoreBackupResponse {
×
353

×
354
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
355
        defer cancel()
×
356

×
357
        resp, err := h.LN.RestoreChannelBackups(ctxt, req)
×
358
        h.NoError(err, "RestoreChannelBackups")
×
359

×
360
        return resp
×
361
}
×
362

363
type AcceptorClient lnrpc.Lightning_ChannelAcceptorClient
364

365
// ChannelAcceptor makes a RPC call to the node's ChannelAcceptor and asserts.
366
func (h *HarnessRPC) ChannelAcceptor() (AcceptorClient, context.CancelFunc) {
×
367
        // Use runCtx here instead of a timeout context to keep the client
×
368
        // alive for the entire test case.
×
369
        ctxt, cancel := context.WithCancel(h.runCtx)
×
370
        resp, err := h.LN.ChannelAcceptor(ctxt)
×
371
        h.NoError(err, "ChannelAcceptor")
×
372

×
373
        return resp, cancel
×
374
}
×
375

376
// SendCoins sends a given amount of money to the specified address from the
377
// passed node.
378
func (h *HarnessRPC) SendCoins(
379
        req *lnrpc.SendCoinsRequest) *lnrpc.SendCoinsResponse {
×
380

×
381
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
382
        defer cancel()
×
383

×
384
        resp, err := h.LN.SendCoins(ctxt, req)
×
385
        h.NoError(err, "SendCoins")
×
386

×
387
        return resp
×
388
}
×
389

390
// SendCoinsAssertErr sends a given amount of money to the specified address
391
// from the passed node and asserts an error has returned.
392
func (h *HarnessRPC) SendCoinsAssertErr(req *lnrpc.SendCoinsRequest) error {
×
393
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
394
        defer cancel()
×
395

×
396
        _, err := h.LN.SendCoins(ctxt, req)
×
397
        require.Error(h, err, "node %s didn't not return an error", h.Name)
×
398

×
399
        return err
×
400
}
×
401

402
// GetTransactions makes a RPC call to GetTransactions and asserts.
403
func (h *HarnessRPC) GetTransactions(
404
        req *lnrpc.GetTransactionsRequest) *lnrpc.TransactionDetails {
×
405

×
406
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
407
        defer cancel()
×
408

×
409
        if req == nil {
×
410
                req = &lnrpc.GetTransactionsRequest{}
×
411
        }
×
412

413
        resp, err := h.LN.GetTransactions(ctxt, req)
×
414
        h.NoError(err, "GetTransactions")
×
415

×
416
        return resp
×
417
}
418

419
// SignMessage makes a RPC call to node's SignMessage and asserts.
420
func (h *HarnessRPC) SignMessage(msg []byte) *lnrpc.SignMessageResponse {
×
421
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
422
        defer cancel()
×
423

×
424
        req := &lnrpc.SignMessageRequest{Msg: msg}
×
425
        resp, err := h.LN.SignMessage(ctxt, req)
×
426
        h.NoError(err, "SignMessage")
×
427

×
428
        return resp
×
429
}
×
430

431
// VerifyMessage makes a RPC call to node's VerifyMessage and asserts.
432
func (h *HarnessRPC) VerifyMessage(msg []byte,
433
        sig string) *lnrpc.VerifyMessageResponse {
×
434

×
435
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
436
        defer cancel()
×
437

×
438
        req := &lnrpc.VerifyMessageRequest{Msg: msg, Signature: sig}
×
439
        resp, err := h.LN.VerifyMessage(ctxt, req)
×
440
        h.NoError(err, "VerifyMessage")
×
441

×
442
        return resp
×
443
}
×
444

445
// GetRecoveryInfo uses the specified node to make a RPC call to
446
// GetRecoveryInfo and asserts.
447
func (h *HarnessRPC) GetRecoveryInfo(
448
        req *lnrpc.GetRecoveryInfoRequest) *lnrpc.GetRecoveryInfoResponse {
×
449

×
450
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
451
        defer cancel()
×
452

×
453
        if req == nil {
×
454
                req = &lnrpc.GetRecoveryInfoRequest{}
×
455
        }
×
456

457
        resp, err := h.LN.GetRecoveryInfo(ctxt, req)
×
458
        h.NoError(err, "GetRecoveryInfo")
×
459

×
460
        return resp
×
461
}
462

463
// BatchOpenChannel makes a RPC call to BatchOpenChannel and asserts.
464
func (h *HarnessRPC) BatchOpenChannel(
465
        req *lnrpc.BatchOpenChannelRequest) *lnrpc.BatchOpenChannelResponse {
×
466

×
467
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
468
        defer cancel()
×
469

×
470
        resp, err := h.LN.BatchOpenChannel(ctxt, req)
×
471
        h.NoError(err, "BatchOpenChannel")
×
472

×
473
        return resp
×
474
}
×
475

476
// BatchOpenChannelAssertErr makes a RPC call to BatchOpenChannel and asserts
477
// there's an error returned.
478
func (h *HarnessRPC) BatchOpenChannelAssertErr(
479
        req *lnrpc.BatchOpenChannelRequest) error {
×
480

×
481
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
482
        defer cancel()
×
483

×
484
        _, err := h.LN.BatchOpenChannel(ctxt, req)
×
485
        require.Error(h, err, "expecte batch open channel fail")
×
486

×
487
        return err
×
488
}
×
489

490
// QueryRoutes makes a RPC call to QueryRoutes and asserts.
491
func (h *HarnessRPC) QueryRoutes(
492
        req *lnrpc.QueryRoutesRequest) *lnrpc.QueryRoutesResponse {
×
493

×
494
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
495
        defer cancel()
×
496

×
497
        routes, err := h.LN.QueryRoutes(ctxt, req)
×
498
        h.NoError(err, "QueryRoutes")
×
499

×
500
        return routes
×
501
}
×
502

503
type SendToRouteClient lnrpc.Lightning_SendToRouteClient
504

505
// SendToRoute makes a RPC call to SendToRoute and asserts.
506
func (h *HarnessRPC) SendToRoute() SendToRouteClient {
×
507
        // SendToRoute needs to have the context alive for the entire test case
×
508
        // as the returned client will be used for send and receive payment
×
509
        // stream. Thus we use runCtx here instead of a timeout context.
×
510
        client, err := h.LN.SendToRoute(h.runCtx)
×
511
        h.NoError(err, "SendToRoute")
×
512

×
513
        return client
×
514
}
×
515

516
// SendToRouteSync makes a RPC call to SendToRouteSync and asserts.
517
func (h *HarnessRPC) SendToRouteSync(
518
        req *lnrpc.SendToRouteRequest) *lnrpc.SendResponse {
×
519

×
520
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
521
        defer cancel()
×
522

×
523
        resp, err := h.LN.SendToRouteSync(ctxt, req)
×
524
        h.NoError(err, "SendToRouteSync")
×
525

×
526
        return resp
×
527
}
×
528

529
// UpdateChannelPolicy makes a RPC call to UpdateChannelPolicy and asserts.
530
func (h *HarnessRPC) UpdateChannelPolicy(
531
        req *lnrpc.PolicyUpdateRequest) *lnrpc.PolicyUpdateResponse {
×
532

×
533
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
534
        defer cancel()
×
535

×
536
        resp, err := h.LN.UpdateChannelPolicy(ctxt, req)
×
537
        h.NoError(err, "UpdateChannelPolicy")
×
538

×
539
        return resp
×
540
}
×
541

542
type InvoiceUpdateClient lnrpc.Lightning_SubscribeInvoicesClient
543

544
// SubscribeInvoices creates a subscription client for invoice events and
545
// asserts its creation.
546
//
547
// NOTE: make sure to subscribe an invoice as early as possible as it takes
548
// some time for the lnd to create the subscription client. If an invoice is
549
// added right after the subscription, it may be missed. However, if AddIndex
550
// or SettleIndex is used in the request, it will be fine as a backlog will
551
// always be sent.
552
func (h *HarnessRPC) SubscribeInvoices(
553
        req *lnrpc.InvoiceSubscription) InvoiceUpdateClient {
×
554

×
555
        // SubscribeInvoices needs to have the context alive for the
×
556
        // entire test case as the returned client will be used for send and
×
557
        // receive events stream. Thus we use runCtx here instead of a timeout
×
558
        // context.
×
559
        client, err := h.LN.SubscribeInvoices(h.runCtx, req)
×
560
        h.NoError(err, "SubscribeInvoices")
×
561

×
562
        return client
×
563
}
×
564

565
type BackupSubscriber lnrpc.Lightning_SubscribeChannelBackupsClient
566

567
// SubscribeChannelBackups creates a client to listen to channel backup stream.
568
func (h *HarnessRPC) SubscribeChannelBackups() BackupSubscriber {
×
569
        // Use runCtx here instead of timeout context to keep the stream client
×
570
        // alive.
×
571
        backupStream, err := h.LN.SubscribeChannelBackups(
×
572
                h.runCtx, &lnrpc.ChannelBackupSubscription{},
×
573
        )
×
574
        h.NoError(err, "SubscribeChannelBackups")
×
575

×
576
        return backupStream
×
577
}
×
578

579
// VerifyChanBackup makes a RPC call to node's VerifyChanBackup and asserts.
580
func (h *HarnessRPC) VerifyChanBackup(
581
        ss *lnrpc.ChanBackupSnapshot) *lnrpc.VerifyChanBackupResponse {
×
582

×
583
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
584
        defer cancel()
×
585

×
586
        resp, err := h.LN.VerifyChanBackup(ctxt, ss)
×
587
        h.NoError(err, "VerifyChanBackup")
×
588

×
589
        return resp
×
590
}
×
591

592
// LookupInvoice queries the node's invoices using the specified rHash.
593
func (h *HarnessRPC) LookupInvoice(rHash []byte) *lnrpc.Invoice {
×
594
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
595
        defer cancel()
×
596

×
597
        payHash := &lnrpc.PaymentHash{RHash: rHash}
×
598
        resp, err := h.LN.LookupInvoice(ctxt, payHash)
×
599
        h.NoError(err, "LookupInvoice")
×
600

×
601
        return resp
×
602
}
×
603

604
// LookupInvoiceAssertErr makes a RPC call to the node's
605
// LookupInvoice and asserts an RPC error is returned.
NEW
606
func (h *HarnessRPC) LookupInvoiceAssertErr(rHash []byte, errStr string) {
×
NEW
607
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
NEW
608
        defer cancel()
×
NEW
609

×
NEW
610
        payHash := &lnrpc.PaymentHash{RHash: rHash}
×
NEW
611
        _, err := h.LN.LookupInvoice(ctxt, payHash)
×
NEW
612
        require.ErrorContains(h, err, errStr)
×
NEW
613
}
×
614

615
// DecodePayReq makes a RPC call to node's DecodePayReq and asserts.
616
func (h *HarnessRPC) DecodePayReq(req string) *lnrpc.PayReq {
×
617
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
618
        defer cancel()
×
619

×
620
        payReq := &lnrpc.PayReqString{PayReq: req}
×
621
        resp, err := h.LN.DecodePayReq(ctxt, payReq)
×
622
        h.NoError(err, "DecodePayReq")
×
623

×
624
        return resp
×
625
}
×
626

627
// ForwardingHistory makes a RPC call to the node's ForwardingHistory and
628
// asserts.
629
func (h *HarnessRPC) ForwardingHistory(
630
        req *lnrpc.ForwardingHistoryRequest) *lnrpc.ForwardingHistoryResponse {
×
631

×
632
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
633
        defer cancel()
×
634

×
635
        if req == nil {
×
636
                req = &lnrpc.ForwardingHistoryRequest{}
×
637
        }
×
638

639
        resp, err := h.LN.ForwardingHistory(ctxt, req)
×
640
        h.NoError(err, "ForwardingHistory")
×
641

×
642
        return resp
×
643
}
644

645
type MiddlewareClient lnrpc.Lightning_RegisterRPCMiddlewareClient
646

647
// RegisterRPCMiddleware makes a RPC call to the node's RegisterRPCMiddleware
648
// and asserts. It also returns a cancel context which can cancel the context
649
// used by the client.
650
func (h *HarnessRPC) RegisterRPCMiddleware() (MiddlewareClient,
651
        context.CancelFunc) {
×
652

×
653
        ctxt, cancel := context.WithCancel(h.runCtx)
×
654

×
655
        stream, err := h.LN.RegisterRPCMiddleware(ctxt)
×
656
        h.NoError(err, "RegisterRPCMiddleware")
×
657

×
658
        return stream, cancel
×
659
}
×
660

661
type ChannelEventsClient lnrpc.Lightning_SubscribeChannelEventsClient
662

663
// SubscribeChannelEvents creates a subscription client for channel events and
664
// asserts its creation.
665
func (h *HarnessRPC) SubscribeChannelEvents() ChannelEventsClient {
×
666
        req := &lnrpc.ChannelEventSubscription{}
×
667

×
668
        // SubscribeChannelEvents needs to have the context alive for the
×
669
        // entire test case as the returned client will be used for send and
×
670
        // receive events stream. Thus we use runCtx here instead of a timeout
×
671
        // context.
×
672
        client, err := h.LN.SubscribeChannelEvents(h.runCtx, req)
×
673
        h.NoError(err, "SubscribeChannelEvents")
×
674

×
675
        return client
×
676
}
×
677

678
type CustomMessageClient lnrpc.Lightning_SubscribeCustomMessagesClient
679

680
// SubscribeCustomMessages creates a subscription client for custom messages.
681
func (h *HarnessRPC) SubscribeCustomMessages() (CustomMessageClient,
682
        context.CancelFunc) {
×
683

×
684
        ctxt, cancel := context.WithCancel(h.runCtx)
×
685

×
686
        req := &lnrpc.SubscribeCustomMessagesRequest{}
×
687

×
688
        // SubscribeCustomMessages needs to have the context alive for the
×
689
        // entire test case as the returned client will be used for send and
×
690
        // receive events stream. Thus we use runCtx here instead of a timeout
×
691
        // context.
×
692
        stream, err := h.LN.SubscribeCustomMessages(ctxt, req)
×
693
        h.NoError(err, "SubscribeCustomMessages")
×
694

×
695
        return stream, cancel
×
696
}
×
697

698
// SendCustomMessage makes a RPC call to the node's SendCustomMessage and
699
// returns the response.
700
func (h *HarnessRPC) SendCustomMessage(
701
        req *lnrpc.SendCustomMessageRequest) *lnrpc.SendCustomMessageResponse {
×
702

×
703
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
704
        defer cancel()
×
705

×
706
        resp, err := h.LN.SendCustomMessage(ctxt, req)
×
707
        h.NoError(err, "SendCustomMessage")
×
708

×
709
        return resp
×
710
}
×
711

712
// GetChanInfo makes a RPC call to the node's GetChanInfo and returns the
713
// response.
714
func (h *HarnessRPC) GetChanInfo(
715
        req *lnrpc.ChanInfoRequest) *lnrpc.ChannelEdge {
×
716

×
717
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
718
        defer cancel()
×
719

×
720
        resp, err := h.LN.GetChanInfo(ctxt, req)
×
721
        h.NoError(err, "GetChanInfo")
×
722

×
723
        return resp
×
724
}
×
725

726
// LookupHtlcResolution makes a RPC call to the node's LookupHtlcResolution and
727
// returns the response.
728
//
729
//nolint:ll
730
func (h *HarnessRPC) LookupHtlcResolution(
731
        req *lnrpc.LookupHtlcResolutionRequest) *lnrpc.LookupHtlcResolutionResponse {
×
732

×
733
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
734
        defer cancel()
×
735

×
736
        resp, err := h.LN.LookupHtlcResolution(ctxt, req)
×
737
        h.NoError(err, "LookupHtlcResolution")
×
738

×
739
        return resp
×
740
}
×
741

742
// LookupHtlcResolutionAssertErr makes a RPC call to the node's
743
// LookupHtlcResolution and asserts an RPC error is returned.
744
func (h *HarnessRPC) LookupHtlcResolutionAssertErr(
745
        req *lnrpc.LookupHtlcResolutionRequest) error {
×
746

×
747
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
748
        defer cancel()
×
749

×
750
        _, err := h.LN.LookupHtlcResolution(ctxt, req)
×
751
        require.Error(h, err, "expected an error")
×
752

×
753
        return err
×
754
}
×
755

756
// Quiesce makes an RPC call to the node's Quiesce method and returns the
757
// response.
758
func (h *HarnessRPC) Quiesce(
759
        req *devrpc.QuiescenceRequest) *devrpc.QuiescenceResponse {
×
760

×
761
        ctx, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
762
        defer cancel()
×
763

×
764
        res, err := h.Dev.Quiesce(ctx, req)
×
765
        h.NoError(err, "Quiesce returned an error")
×
766

×
767
        return res
×
768
}
×
769

770
// DeleteCanceledInvoices makes a RPC call to the node's DeleteCanceledInvoices
771
// and asserts.
772
func (h *HarnessRPC) DeleteCanceledInvoices(
NEW
773
        req *lnrpc.DeleteInvoicesRequest) *lnrpc.DeleteInvoicesResponse {
×
NEW
774

×
NEW
775
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
NEW
776
        defer cancel()
×
NEW
777

×
NEW
778
        resp, err := h.LN.DeleteCanceledInvoices(ctxt, req)
×
NEW
779
        h.NoError(err, "DeleteCanceledInvoices")
×
NEW
780

×
NEW
781
        return resp
×
NEW
782
}
×
783

784
// DeleteCanceledInvoicesAssertErr makes a RPC call to the node's
785
// DeleteCanceledInvoices and asserts an RPC error is returned.
786
func (h *HarnessRPC) DeleteCanceledInvoicesAssertErr(
NEW
787
        req *lnrpc.DeleteInvoicesRequest, errStr string) {
×
NEW
788

×
NEW
789
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
NEW
790
        defer cancel()
×
NEW
791

×
NEW
792
        _, err := h.LN.DeleteCanceledInvoices(ctxt, req)
×
NEW
793
        require.ErrorContains(h, err, errStr)
×
NEW
794
}
×
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