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

lightningnetwork / lnd / 17774622768

16 Sep 2025 05:57PM UTC coverage: 66.505% (-0.2%) from 66.657%
17774622768

Pull #10067

github

web-flow
Merge 4ec7abb62 into cbed86e21
Pull Request #10067: add sats_per_kweight option when crafting a transaction (continue)

72 of 233 new or added lines in 13 files covered. (30.9%)

355 existing lines in 32 files now uncovered.

136113 of 204666 relevant lines covered (66.5%)

21396.84 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
// GetChanInfoAssertErr makes an RPC call to GetChanInfo and asserts an error
307
// has returned with a specific error message.
308
func (h *HarnessRPC) GetChanInfoAssertErr(req *lnrpc.ChanInfoRequest,
309
        errStr string) {
×
310

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

×
314
        _, err := h.LN.GetChanInfo(ctxt, req)
×
315
        require.ErrorContains(h, err, errStr)
×
316
}
×
317

318
// GetNodeInfoAssertErr makes an RPC call to GetNodeInfo and asserts an error
319
// has returned with a specific error message.
320
func (h *HarnessRPC) GetNodeInfoAssertErr(req *lnrpc.NodeInfoRequest,
321
        errStr string) {
×
322

×
323
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
324
        defer cancel()
×
325

×
326
        _, err := h.LN.GetNodeInfo(ctxt, req)
×
327
        require.ErrorContains(h, err, errStr)
×
328
}
×
329

330
// SendCustomMessageAssertErr makes an RPC call to SendCustomMessage and asserts
331
// an error has returned with a specific error message.
332
func (h *HarnessRPC) SendCustomMessageAssertErr(
333
        req *lnrpc.SendCustomMessageRequest, errStr string) {
×
334

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

×
338
        _, err := h.LN.SendCustomMessage(ctxt, req)
×
339
        require.ErrorContains(h, err, errStr)
×
340
}
×
341

342
// LookupInvoiceAssertErr makes an RPC call to LookupInvoice and asserts an
343
// error has returned with a specific error message.
344
func (h *HarnessRPC) LookupInvoiceAssertErr(req *lnrpc.PaymentHash,
345
        errStr string) {
×
346

×
347
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
348
        defer cancel()
×
349

×
350
        _, err := h.LN.LookupInvoice(ctxt, req)
×
351
        require.ErrorContains(h, err, errStr)
×
352
}
×
353

354
// LookupHTLCResolutionAssertErr makes an RPC call to LookupHTLCResolution and
355
// asserts an error has returned with a specific error message.
356
func (h *HarnessRPC) LookupHTLCResolutionAssertErr(
357
        req *lnrpc.LookupHtlcResolutionRequest, errStr string) {
×
358

×
359
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
360
        defer cancel()
×
361

×
362
        _, err := h.LN.LookupHtlcResolution(ctxt, req)
×
363
        require.ErrorContains(h, err, errStr)
×
364
}
×
365

366
// AbandonChannel makes a RPC call to AbandonChannel and asserts.
367
func (h *HarnessRPC) AbandonChannel(
368
        req *lnrpc.AbandonChannelRequest) *lnrpc.AbandonChannelResponse {
×
369

×
370
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
371
        defer cancel()
×
372

×
373
        resp, err := h.LN.AbandonChannel(ctxt, req)
×
374
        h.NoError(err, "AbandonChannel")
×
375

×
376
        return resp
×
377
}
×
378

379
// ExportAllChanBackups makes a RPC call to the node's ExportAllChannelBackups
380
// and asserts.
381
func (h *HarnessRPC) ExportAllChanBackups() *lnrpc.ChanBackupSnapshot {
×
382
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
383
        defer cancel()
×
384

×
385
        req := &lnrpc.ChanBackupExportRequest{}
×
386
        chanBackup, err := h.LN.ExportAllChannelBackups(ctxt, req)
×
387
        h.NoError(err, "ExportAllChannelBackups")
×
388

×
389
        return chanBackup
×
390
}
×
391

392
// ExportChanBackup makes a RPC call to the node's ExportChannelBackup
393
// and asserts.
394
func (h *HarnessRPC) ExportChanBackup(
395
        chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelBackup {
×
396

×
397
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
398
        defer cancel()
×
399

×
400
        req := &lnrpc.ExportChannelBackupRequest{
×
401
                ChanPoint: chanPoint,
×
402
        }
×
403
        chanBackup, err := h.LN.ExportChannelBackup(ctxt, req)
×
404
        h.NoError(err, "ExportChannelBackup")
×
405

×
406
        return chanBackup
×
407
}
×
408

409
// RestoreChanBackups makes a RPC call to the node's RestoreChannelBackups and
410
// asserts.
411
func (h *HarnessRPC) RestoreChanBackups(
412
        req *lnrpc.RestoreChanBackupRequest) *lnrpc.RestoreBackupResponse {
×
413

×
414
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
415
        defer cancel()
×
416

×
417
        resp, err := h.LN.RestoreChannelBackups(ctxt, req)
×
418
        h.NoError(err, "RestoreChannelBackups")
×
419

×
420
        return resp
×
421
}
×
422

423
type AcceptorClient lnrpc.Lightning_ChannelAcceptorClient
424

425
// ChannelAcceptor makes a RPC call to the node's ChannelAcceptor and asserts.
426
func (h *HarnessRPC) ChannelAcceptor() (AcceptorClient, context.CancelFunc) {
×
427
        // Use runCtx here instead of a timeout context to keep the client
×
428
        // alive for the entire test case.
×
429
        ctxt, cancel := context.WithCancel(h.runCtx)
×
430
        resp, err := h.LN.ChannelAcceptor(ctxt)
×
431
        h.NoError(err, "ChannelAcceptor")
×
432

×
433
        return resp, cancel
×
434
}
×
435

436
// SendCoins sends a given amount of money to the specified address from the
437
// passed node.
438
func (h *HarnessRPC) SendCoins(
439
        req *lnrpc.SendCoinsRequest) *lnrpc.SendCoinsResponse {
×
440

×
441
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
442
        defer cancel()
×
443

×
444
        resp, err := h.LN.SendCoins(ctxt, req)
×
445
        h.NoError(err, "SendCoins")
×
446

×
447
        return resp
×
448
}
×
449

450
// SendCoinsAssertErr sends a given amount of money to the specified address
451
// from the passed node and asserts an error has returned.
452
func (h *HarnessRPC) SendCoinsAssertErr(req *lnrpc.SendCoinsRequest) error {
×
453
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
454
        defer cancel()
×
455

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

×
459
        return err
×
460
}
×
461

462
// SendMany sends a given amount of money to the specified address from the
463
// passed node.
464
func (h *HarnessRPC) SendMany(
NEW
465
        req *lnrpc.SendManyRequest) *lnrpc.SendManyResponse {
×
NEW
466

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

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

×
NEW
473
        return resp
×
NEW
474
}
×
475

476
// SendManyAssertErr sends a given amount of money to the specified address
477
// from the passed node and asserts an error has returned.
NEW
478
func (h *HarnessRPC) SendManyAssertErr(req *lnrpc.SendManyRequest) {
×
NEW
479
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
NEW
480
        defer cancel()
×
NEW
481

×
NEW
482
        _, err := h.LN.SendMany(ctxt, req)
×
NEW
483
        require.Error(h, err, "node %s didn't not return an error", h.Name)
×
NEW
484
}
×
485

486
// GetTransactions makes a RPC call to GetTransactions and asserts.
487
func (h *HarnessRPC) GetTransactions(
488
        req *lnrpc.GetTransactionsRequest) *lnrpc.TransactionDetails {
×
489

×
490
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
491
        defer cancel()
×
492

×
493
        if req == nil {
×
494
                req = &lnrpc.GetTransactionsRequest{}
×
495
        }
×
496

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

×
500
        return resp
×
501
}
502

503
// SignMessage makes a RPC call to node's SignMessage and asserts.
504
func (h *HarnessRPC) SignMessage(msg []byte) *lnrpc.SignMessageResponse {
×
505
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
506
        defer cancel()
×
507

×
508
        req := &lnrpc.SignMessageRequest{Msg: msg}
×
509
        resp, err := h.LN.SignMessage(ctxt, req)
×
510
        h.NoError(err, "SignMessage")
×
511

×
512
        return resp
×
513
}
×
514

515
// VerifyMessage makes a RPC call to node's VerifyMessage and asserts.
516
func (h *HarnessRPC) VerifyMessage(msg []byte,
517
        sig string) *lnrpc.VerifyMessageResponse {
×
518

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

×
522
        req := &lnrpc.VerifyMessageRequest{Msg: msg, Signature: sig}
×
523
        resp, err := h.LN.VerifyMessage(ctxt, req)
×
524
        h.NoError(err, "VerifyMessage")
×
525

×
526
        return resp
×
527
}
×
528

529
// GetRecoveryInfo uses the specified node to make a RPC call to
530
// GetRecoveryInfo and asserts.
531
func (h *HarnessRPC) GetRecoveryInfo(
532
        req *lnrpc.GetRecoveryInfoRequest) *lnrpc.GetRecoveryInfoResponse {
×
533

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

×
537
        if req == nil {
×
538
                req = &lnrpc.GetRecoveryInfoRequest{}
×
539
        }
×
540

541
        resp, err := h.LN.GetRecoveryInfo(ctxt, req)
×
542
        h.NoError(err, "GetRecoveryInfo")
×
543

×
544
        return resp
×
545
}
546

547
// BatchOpenChannel makes a RPC call to BatchOpenChannel and asserts.
548
func (h *HarnessRPC) BatchOpenChannel(
549
        req *lnrpc.BatchOpenChannelRequest) *lnrpc.BatchOpenChannelResponse {
×
550

×
551
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
552
        defer cancel()
×
553

×
554
        resp, err := h.LN.BatchOpenChannel(ctxt, req)
×
555
        h.NoError(err, "BatchOpenChannel")
×
556

×
557
        return resp
×
558
}
×
559

560
// BatchOpenChannelAssertErr makes a RPC call to BatchOpenChannel and asserts
561
// there's an error returned.
562
func (h *HarnessRPC) BatchOpenChannelAssertErr(
563
        req *lnrpc.BatchOpenChannelRequest) error {
×
564

×
565
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
566
        defer cancel()
×
567

×
568
        _, err := h.LN.BatchOpenChannel(ctxt, req)
×
569
        require.Error(h, err, "expecte batch open channel fail")
×
570

×
571
        return err
×
572
}
×
573

574
// QueryRoutes makes a RPC call to QueryRoutes and asserts.
575
func (h *HarnessRPC) QueryRoutes(
576
        req *lnrpc.QueryRoutesRequest) *lnrpc.QueryRoutesResponse {
×
577

×
578
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
579
        defer cancel()
×
580

×
581
        routes, err := h.LN.QueryRoutes(ctxt, req)
×
582
        h.NoError(err, "QueryRoutes")
×
583

×
584
        return routes
×
585
}
×
586

587
type SendToRouteClient lnrpc.Lightning_SendToRouteClient
588

589
// SendToRoute makes a RPC call to SendToRoute and asserts.
590
func (h *HarnessRPC) SendToRoute() SendToRouteClient {
×
591
        // SendToRoute needs to have the context alive for the entire test case
×
592
        // as the returned client will be used for send and receive payment
×
593
        // stream. Thus we use runCtx here instead of a timeout context.
×
594
        client, err := h.LN.SendToRoute(h.runCtx)
×
595
        h.NoError(err, "SendToRoute")
×
596

×
597
        return client
×
598
}
×
599

600
// SendToRouteSync makes a RPC call to SendToRouteSync and asserts.
601
func (h *HarnessRPC) SendToRouteSync(
602
        req *lnrpc.SendToRouteRequest) *lnrpc.SendResponse {
×
603

×
604
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
605
        defer cancel()
×
606

×
607
        resp, err := h.LN.SendToRouteSync(ctxt, req)
×
608
        h.NoError(err, "SendToRouteSync")
×
609

×
610
        return resp
×
611
}
×
612

613
// UpdateChannelPolicy makes a RPC call to UpdateChannelPolicy and asserts.
614
func (h *HarnessRPC) UpdateChannelPolicy(
615
        req *lnrpc.PolicyUpdateRequest) *lnrpc.PolicyUpdateResponse {
×
616

×
617
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
618
        defer cancel()
×
619

×
620
        resp, err := h.LN.UpdateChannelPolicy(ctxt, req)
×
621
        h.NoError(err, "UpdateChannelPolicy")
×
622

×
623
        return resp
×
624
}
×
625

626
type InvoiceUpdateClient lnrpc.Lightning_SubscribeInvoicesClient
627

628
// SubscribeInvoices creates a subscription client for invoice events and
629
// asserts its creation.
630
//
631
// NOTE: make sure to subscribe an invoice as early as possible as it takes
632
// some time for the lnd to create the subscription client. If an invoice is
633
// added right after the subscription, it may be missed. However, if AddIndex
634
// or SettleIndex is used in the request, it will be fine as a backlog will
635
// always be sent.
636
func (h *HarnessRPC) SubscribeInvoices(
637
        req *lnrpc.InvoiceSubscription) InvoiceUpdateClient {
×
638

×
639
        // SubscribeInvoices needs to have the context alive for the
×
640
        // entire test case as the returned client will be used for send and
×
641
        // receive events stream. Thus we use runCtx here instead of a timeout
×
642
        // context.
×
643
        client, err := h.LN.SubscribeInvoices(h.runCtx, req)
×
644
        h.NoError(err, "SubscribeInvoices")
×
645

×
646
        return client
×
647
}
×
648

649
type BackupSubscriber lnrpc.Lightning_SubscribeChannelBackupsClient
650

651
// SubscribeChannelBackups creates a client to listen to channel backup stream.
652
func (h *HarnessRPC) SubscribeChannelBackups() BackupSubscriber {
×
653
        // Use runCtx here instead of timeout context to keep the stream client
×
654
        // alive.
×
655
        backupStream, err := h.LN.SubscribeChannelBackups(
×
656
                h.runCtx, &lnrpc.ChannelBackupSubscription{},
×
657
        )
×
658
        h.NoError(err, "SubscribeChannelBackups")
×
659

×
660
        return backupStream
×
661
}
×
662

663
// VerifyChanBackup makes a RPC call to node's VerifyChanBackup and asserts.
664
func (h *HarnessRPC) VerifyChanBackup(
665
        ss *lnrpc.ChanBackupSnapshot) *lnrpc.VerifyChanBackupResponse {
×
666

×
667
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
668
        defer cancel()
×
669

×
670
        resp, err := h.LN.VerifyChanBackup(ctxt, ss)
×
671
        h.NoError(err, "VerifyChanBackup")
×
672

×
673
        return resp
×
674
}
×
675

676
// LookupInvoice queries the node's invoices using the specified rHash.
677
func (h *HarnessRPC) LookupInvoice(rHash []byte) *lnrpc.Invoice {
×
678
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
679
        defer cancel()
×
680

×
681
        payHash := &lnrpc.PaymentHash{RHash: rHash}
×
682
        resp, err := h.LN.LookupInvoice(ctxt, payHash)
×
683
        h.NoError(err, "LookupInvoice")
×
684

×
685
        return resp
×
686
}
×
687

688
// DecodePayReq makes a RPC call to node's DecodePayReq and asserts.
689
func (h *HarnessRPC) DecodePayReq(req string) *lnrpc.PayReq {
×
690
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
691
        defer cancel()
×
692

×
693
        payReq := &lnrpc.PayReqString{PayReq: req}
×
694
        resp, err := h.LN.DecodePayReq(ctxt, payReq)
×
695
        h.NoError(err, "DecodePayReq")
×
696

×
697
        return resp
×
698
}
×
699

700
// ForwardingHistory makes a RPC call to the node's ForwardingHistory and
701
// asserts.
702
func (h *HarnessRPC) ForwardingHistory(
703
        req *lnrpc.ForwardingHistoryRequest) *lnrpc.ForwardingHistoryResponse {
×
704

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

×
708
        if req == nil {
×
709
                req = &lnrpc.ForwardingHistoryRequest{}
×
710
        }
×
711

712
        resp, err := h.LN.ForwardingHistory(ctxt, req)
×
713
        h.NoError(err, "ForwardingHistory")
×
714

×
715
        return resp
×
716
}
717

718
type MiddlewareClient lnrpc.Lightning_RegisterRPCMiddlewareClient
719

720
// RegisterRPCMiddleware makes a RPC call to the node's RegisterRPCMiddleware
721
// and asserts. It also returns a cancel context which can cancel the context
722
// used by the client.
723
func (h *HarnessRPC) RegisterRPCMiddleware() (MiddlewareClient,
724
        context.CancelFunc) {
×
725

×
726
        ctxt, cancel := context.WithCancel(h.runCtx)
×
727

×
728
        stream, err := h.LN.RegisterRPCMiddleware(ctxt)
×
729
        h.NoError(err, "RegisterRPCMiddleware")
×
730

×
731
        return stream, cancel
×
732
}
×
733

734
type ChannelEventsClient lnrpc.Lightning_SubscribeChannelEventsClient
735

736
// SubscribeChannelEvents creates a subscription client for channel events and
737
// asserts its creation.
738
func (h *HarnessRPC) SubscribeChannelEvents() ChannelEventsClient {
×
739
        req := &lnrpc.ChannelEventSubscription{}
×
740

×
741
        // SubscribeChannelEvents needs to have the context alive for the
×
742
        // entire test case as the returned client will be used for send and
×
743
        // receive events stream. Thus we use runCtx here instead of a timeout
×
744
        // context.
×
745
        client, err := h.LN.SubscribeChannelEvents(h.runCtx, req)
×
746
        h.NoError(err, "SubscribeChannelEvents")
×
747

×
748
        return client
×
749
}
×
750

751
type CustomMessageClient lnrpc.Lightning_SubscribeCustomMessagesClient
752

753
// SubscribeCustomMessages creates a subscription client for custom messages.
754
func (h *HarnessRPC) SubscribeCustomMessages() (CustomMessageClient,
755
        context.CancelFunc) {
×
756

×
757
        ctxt, cancel := context.WithCancel(h.runCtx)
×
758

×
759
        req := &lnrpc.SubscribeCustomMessagesRequest{}
×
760

×
761
        // SubscribeCustomMessages needs to have the context alive for the
×
762
        // entire test case as the returned client will be used for send and
×
763
        // receive events stream. Thus we use runCtx here instead of a timeout
×
764
        // context.
×
765
        stream, err := h.LN.SubscribeCustomMessages(ctxt, req)
×
766
        h.NoError(err, "SubscribeCustomMessages")
×
767

×
768
        return stream, cancel
×
769
}
×
770

771
// SendCustomMessage makes a RPC call to the node's SendCustomMessage and
772
// returns the response.
773
func (h *HarnessRPC) SendCustomMessage(
774
        req *lnrpc.SendCustomMessageRequest) *lnrpc.SendCustomMessageResponse {
×
775

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

×
779
        resp, err := h.LN.SendCustomMessage(ctxt, req)
×
780
        h.NoError(err, "SendCustomMessage")
×
781

×
782
        return resp
×
783
}
×
784

785
// GetChanInfo makes a RPC call to the node's GetChanInfo and returns the
786
// response.
787
func (h *HarnessRPC) GetChanInfo(
788
        req *lnrpc.ChanInfoRequest) *lnrpc.ChannelEdge {
×
789

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

×
793
        resp, err := h.LN.GetChanInfo(ctxt, req)
×
794
        h.NoError(err, "GetChanInfo")
×
795

×
796
        return resp
×
797
}
×
798

799
// LookupHtlcResolution makes a RPC call to the node's LookupHtlcResolution and
800
// returns the response.
801
//
802
//nolint:ll
803
func (h *HarnessRPC) LookupHtlcResolution(
804
        req *lnrpc.LookupHtlcResolutionRequest) *lnrpc.LookupHtlcResolutionResponse {
×
805

×
806
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
807
        defer cancel()
×
808

×
809
        resp, err := h.LN.LookupHtlcResolution(ctxt, req)
×
810
        h.NoError(err, "LookupHtlcResolution")
×
811

×
812
        return resp
×
813
}
×
814

815
// LookupHtlcResolutionAssertErr makes a RPC call to the node's
816
// LookupHtlcResolution and asserts an RPC error is returned.
817
func (h *HarnessRPC) LookupHtlcResolutionAssertErr(
818
        req *lnrpc.LookupHtlcResolutionRequest) error {
×
819

×
820
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
821
        defer cancel()
×
822

×
823
        _, err := h.LN.LookupHtlcResolution(ctxt, req)
×
824
        require.Error(h, err, "expected an error")
×
825

×
826
        return err
×
827
}
×
828

829
// Quiesce makes an RPC call to the node's Quiesce method and returns the
830
// response.
831
func (h *HarnessRPC) Quiesce(
832
        req *devrpc.QuiescenceRequest) *devrpc.QuiescenceResponse {
×
833

×
834
        ctx, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
835
        defer cancel()
×
836

×
837
        res, err := h.Dev.Quiesce(ctx, req)
×
838
        h.NoError(err, "Quiesce returned an error")
×
839

×
840
        return res
×
841
}
×
842

843
type PeerEventsClient lnrpc.Lightning_SubscribePeerEventsClient
844

845
// SubscribePeerEvents makes a RPC call to the node's SubscribePeerEvents and
846
// returns the stream client.
847
func (h *HarnessRPC) SubscribePeerEvents(
848
        req *lnrpc.PeerEventSubscription) PeerEventsClient {
×
849

×
850
        // SubscribePeerEvents needs to have the context alive for the entire
×
851
        // test case as the returned client will be used for send and receive
×
852
        // events stream. Thus we use runCtx here instead of a timeout context.
×
853
        resp, err := h.LN.SubscribePeerEvents(h.runCtx, req)
×
854
        h.NoError(err, "SubscribePeerEvents")
×
855

×
856
        return resp
×
857
}
×
858

859
// DeleteCanceledInvoice makes a RPC call to the node's DeleteCanceledInvoice
860
// and asserts.
861
func (h *HarnessRPC) DeleteCanceledInvoice(
862
        req *lnrpc.DelCanceledInvoiceReq) *lnrpc.DelCanceledInvoiceResp {
×
863

×
864
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
865
        defer cancel()
×
866

×
867
        resp, err := h.LN.DeleteCanceledInvoice(ctxt, req)
×
868
        h.NoError(err, "DeleteCanceledInvoice")
×
869

×
870
        return resp
×
871
}
×
872

873
// DeleteCanceledInvoiceAssertErr makes a RPC call to the node's
874
// DeleteCanceledInvoice and asserts if an RPC error is returned.
875
func (h *HarnessRPC) DeleteCanceledInvoiceAssertErr(
876
        req *lnrpc.DelCanceledInvoiceReq, errStr string) {
×
877

×
878
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
879
        defer cancel()
×
880

×
881
        _, err := h.LN.DeleteCanceledInvoice(ctxt, req)
×
882
        require.ErrorContains(h, err, errStr)
×
883
}
×
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