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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 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
// AbandonChannel makes a RPC call to AbandonChannel and asserts.
297
func (h *HarnessRPC) AbandonChannel(
298
        req *lnrpc.AbandonChannelRequest) *lnrpc.AbandonChannelResponse {
×
299

×
300
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
301
        defer cancel()
×
302

×
303
        resp, err := h.LN.AbandonChannel(ctxt, req)
×
304
        h.NoError(err, "AbandonChannel")
×
305

×
306
        return resp
×
307
}
×
308

309
// ExportAllChanBackups makes a RPC call to the node's ExportAllChannelBackups
310
// and asserts.
311
func (h *HarnessRPC) ExportAllChanBackups() *lnrpc.ChanBackupSnapshot {
×
312
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
313
        defer cancel()
×
314

×
315
        req := &lnrpc.ChanBackupExportRequest{}
×
316
        chanBackup, err := h.LN.ExportAllChannelBackups(ctxt, req)
×
317
        h.NoError(err, "ExportAllChannelBackups")
×
318

×
319
        return chanBackup
×
320
}
×
321

322
// ExportChanBackup makes a RPC call to the node's ExportChannelBackup
323
// and asserts.
324
func (h *HarnessRPC) ExportChanBackup(
325
        chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelBackup {
×
326

×
327
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
328
        defer cancel()
×
329

×
330
        req := &lnrpc.ExportChannelBackupRequest{
×
331
                ChanPoint: chanPoint,
×
332
        }
×
333
        chanBackup, err := h.LN.ExportChannelBackup(ctxt, req)
×
334
        h.NoError(err, "ExportChannelBackup")
×
335

×
336
        return chanBackup
×
337
}
×
338

339
// RestoreChanBackups makes a RPC call to the node's RestoreChannelBackups and
340
// asserts.
341
func (h *HarnessRPC) RestoreChanBackups(
342
        req *lnrpc.RestoreChanBackupRequest) *lnrpc.RestoreBackupResponse {
×
343

×
344
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
345
        defer cancel()
×
346

×
347
        resp, err := h.LN.RestoreChannelBackups(ctxt, req)
×
348
        h.NoError(err, "RestoreChannelBackups")
×
349

×
350
        return resp
×
351
}
×
352

353
type AcceptorClient lnrpc.Lightning_ChannelAcceptorClient
354

355
// ChannelAcceptor makes a RPC call to the node's ChannelAcceptor and asserts.
356
func (h *HarnessRPC) ChannelAcceptor() (AcceptorClient, context.CancelFunc) {
×
357
        // Use runCtx here instead of a timeout context to keep the client
×
358
        // alive for the entire test case.
×
359
        ctxt, cancel := context.WithCancel(h.runCtx)
×
360
        resp, err := h.LN.ChannelAcceptor(ctxt)
×
361
        h.NoError(err, "ChannelAcceptor")
×
362

×
363
        return resp, cancel
×
364
}
×
365

366
// SendCoins sends a given amount of money to the specified address from the
367
// passed node.
368
func (h *HarnessRPC) SendCoins(
369
        req *lnrpc.SendCoinsRequest) *lnrpc.SendCoinsResponse {
×
370

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

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

×
377
        return resp
×
378
}
×
379

380
// SendCoinsAssertErr sends a given amount of money to the specified address
381
// from the passed node and asserts an error has returned.
382
func (h *HarnessRPC) SendCoinsAssertErr(req *lnrpc.SendCoinsRequest) error {
×
383
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
384
        defer cancel()
×
385

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

×
389
        return err
×
390
}
×
391

392
// GetTransactions makes a RPC call to GetTransactions and asserts.
393
func (h *HarnessRPC) GetTransactions(
394
        req *lnrpc.GetTransactionsRequest) *lnrpc.TransactionDetails {
×
395

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

×
399
        if req == nil {
×
400
                req = &lnrpc.GetTransactionsRequest{}
×
401
        }
×
402

403
        resp, err := h.LN.GetTransactions(ctxt, req)
×
404
        h.NoError(err, "GetTransactions")
×
405

×
406
        return resp
×
407
}
408

409
// SignMessage makes a RPC call to node's SignMessage and asserts.
410
func (h *HarnessRPC) SignMessage(msg []byte) *lnrpc.SignMessageResponse {
×
411
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
412
        defer cancel()
×
413

×
414
        req := &lnrpc.SignMessageRequest{Msg: msg}
×
415
        resp, err := h.LN.SignMessage(ctxt, req)
×
416
        h.NoError(err, "SignMessage")
×
417

×
418
        return resp
×
419
}
×
420

421
// VerifyMessage makes a RPC call to node's VerifyMessage and asserts.
422
func (h *HarnessRPC) VerifyMessage(msg []byte,
423
        sig string) *lnrpc.VerifyMessageResponse {
×
424

×
425
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
426
        defer cancel()
×
427

×
428
        req := &lnrpc.VerifyMessageRequest{Msg: msg, Signature: sig}
×
429
        resp, err := h.LN.VerifyMessage(ctxt, req)
×
430
        h.NoError(err, "VerifyMessage")
×
431

×
432
        return resp
×
433
}
×
434

435
// GetRecoveryInfo uses the specified node to make a RPC call to
436
// GetRecoveryInfo and asserts.
437
func (h *HarnessRPC) GetRecoveryInfo(
438
        req *lnrpc.GetRecoveryInfoRequest) *lnrpc.GetRecoveryInfoResponse {
×
439

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

×
443
        if req == nil {
×
444
                req = &lnrpc.GetRecoveryInfoRequest{}
×
445
        }
×
446

447
        resp, err := h.LN.GetRecoveryInfo(ctxt, req)
×
448
        h.NoError(err, "GetRecoveryInfo")
×
449

×
450
        return resp
×
451
}
452

453
// BatchOpenChannel makes a RPC call to BatchOpenChannel and asserts.
454
func (h *HarnessRPC) BatchOpenChannel(
455
        req *lnrpc.BatchOpenChannelRequest) *lnrpc.BatchOpenChannelResponse {
×
456

×
457
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
458
        defer cancel()
×
459

×
460
        resp, err := h.LN.BatchOpenChannel(ctxt, req)
×
461
        h.NoError(err, "BatchOpenChannel")
×
462

×
463
        return resp
×
464
}
×
465

466
// BatchOpenChannelAssertErr makes a RPC call to BatchOpenChannel and asserts
467
// there's an error returned.
468
func (h *HarnessRPC) BatchOpenChannelAssertErr(
469
        req *lnrpc.BatchOpenChannelRequest) error {
×
470

×
471
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
472
        defer cancel()
×
473

×
474
        _, err := h.LN.BatchOpenChannel(ctxt, req)
×
475
        require.Error(h, err, "expecte batch open channel fail")
×
476

×
477
        return err
×
478
}
×
479

480
// QueryRoutes makes a RPC call to QueryRoutes and asserts.
481
func (h *HarnessRPC) QueryRoutes(
482
        req *lnrpc.QueryRoutesRequest) *lnrpc.QueryRoutesResponse {
×
483

×
484
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
485
        defer cancel()
×
486

×
487
        routes, err := h.LN.QueryRoutes(ctxt, req)
×
488
        h.NoError(err, "QueryRoutes")
×
489

×
490
        return routes
×
491
}
×
492

493
type SendToRouteClient lnrpc.Lightning_SendToRouteClient
494

495
// SendToRoute makes a RPC call to SendToRoute and asserts.
496
func (h *HarnessRPC) SendToRoute() SendToRouteClient {
×
497
        // SendToRoute needs to have the context alive for the entire test case
×
498
        // as the returned client will be used for send and receive payment
×
499
        // stream. Thus we use runCtx here instead of a timeout context.
×
500
        client, err := h.LN.SendToRoute(h.runCtx)
×
501
        h.NoError(err, "SendToRoute")
×
502

×
503
        return client
×
504
}
×
505

506
// SendToRouteSync makes a RPC call to SendToRouteSync and asserts.
507
func (h *HarnessRPC) SendToRouteSync(
508
        req *lnrpc.SendToRouteRequest) *lnrpc.SendResponse {
×
509

×
510
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
511
        defer cancel()
×
512

×
513
        resp, err := h.LN.SendToRouteSync(ctxt, req)
×
514
        h.NoError(err, "SendToRouteSync")
×
515

×
516
        return resp
×
517
}
×
518

519
// UpdateChannelPolicy makes a RPC call to UpdateChannelPolicy and asserts.
520
func (h *HarnessRPC) UpdateChannelPolicy(
521
        req *lnrpc.PolicyUpdateRequest) *lnrpc.PolicyUpdateResponse {
×
522

×
523
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
524
        defer cancel()
×
525

×
526
        resp, err := h.LN.UpdateChannelPolicy(ctxt, req)
×
527
        h.NoError(err, "UpdateChannelPolicy")
×
528

×
529
        return resp
×
530
}
×
531

532
type InvoiceUpdateClient lnrpc.Lightning_SubscribeInvoicesClient
533

534
// SubscribeInvoices creates a subscription client for invoice events and
535
// asserts its creation.
536
//
537
// NOTE: make sure to subscribe an invoice as early as possible as it takes
538
// some time for the lnd to create the subscription client. If an invoice is
539
// added right after the subscription, it may be missed. However, if AddIndex
540
// or SettleIndex is used in the request, it will be fine as a backlog will
541
// always be sent.
542
func (h *HarnessRPC) SubscribeInvoices(
543
        req *lnrpc.InvoiceSubscription) InvoiceUpdateClient {
×
544

×
545
        // SubscribeInvoices needs to have the context alive for the
×
546
        // entire test case as the returned client will be used for send and
×
547
        // receive events stream. Thus we use runCtx here instead of a timeout
×
548
        // context.
×
549
        client, err := h.LN.SubscribeInvoices(h.runCtx, req)
×
550
        h.NoError(err, "SubscribeInvoices")
×
551

×
552
        return client
×
553
}
×
554

555
type BackupSubscriber lnrpc.Lightning_SubscribeChannelBackupsClient
556

557
// SubscribeChannelBackups creates a client to listen to channel backup stream.
558
func (h *HarnessRPC) SubscribeChannelBackups() BackupSubscriber {
×
559
        // Use runCtx here instead of timeout context to keep the stream client
×
560
        // alive.
×
561
        backupStream, err := h.LN.SubscribeChannelBackups(
×
562
                h.runCtx, &lnrpc.ChannelBackupSubscription{},
×
563
        )
×
564
        h.NoError(err, "SubscribeChannelBackups")
×
565

×
566
        return backupStream
×
567
}
×
568

569
// VerifyChanBackup makes a RPC call to node's VerifyChanBackup and asserts.
570
func (h *HarnessRPC) VerifyChanBackup(
571
        ss *lnrpc.ChanBackupSnapshot) *lnrpc.VerifyChanBackupResponse {
×
572

×
573
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
574
        defer cancel()
×
575

×
576
        resp, err := h.LN.VerifyChanBackup(ctxt, ss)
×
577
        h.NoError(err, "VerifyChanBackup")
×
578

×
579
        return resp
×
580
}
×
581

582
// LookupInvoice queries the node's invoices using the specified rHash.
583
func (h *HarnessRPC) LookupInvoice(rHash []byte) *lnrpc.Invoice {
×
584
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
585
        defer cancel()
×
586

×
587
        payHash := &lnrpc.PaymentHash{RHash: rHash}
×
588
        resp, err := h.LN.LookupInvoice(ctxt, payHash)
×
589
        h.NoError(err, "LookupInvoice")
×
590

×
591
        return resp
×
592
}
×
593

594
// DecodePayReq makes a RPC call to node's DecodePayReq and asserts.
595
func (h *HarnessRPC) DecodePayReq(req string) *lnrpc.PayReq {
×
596
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
597
        defer cancel()
×
598

×
599
        payReq := &lnrpc.PayReqString{PayReq: req}
×
600
        resp, err := h.LN.DecodePayReq(ctxt, payReq)
×
601
        h.NoError(err, "DecodePayReq")
×
602

×
603
        return resp
×
604
}
×
605

606
// ForwardingHistory makes a RPC call to the node's ForwardingHistory and
607
// asserts.
608
func (h *HarnessRPC) ForwardingHistory(
609
        req *lnrpc.ForwardingHistoryRequest) *lnrpc.ForwardingHistoryResponse {
×
610

×
611
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
612
        defer cancel()
×
613

×
614
        if req == nil {
×
615
                req = &lnrpc.ForwardingHistoryRequest{}
×
616
        }
×
617

618
        resp, err := h.LN.ForwardingHistory(ctxt, req)
×
619
        h.NoError(err, "ForwardingHistory")
×
620

×
621
        return resp
×
622
}
623

624
type MiddlewareClient lnrpc.Lightning_RegisterRPCMiddlewareClient
625

626
// RegisterRPCMiddleware makes a RPC call to the node's RegisterRPCMiddleware
627
// and asserts. It also returns a cancel context which can cancel the context
628
// used by the client.
629
func (h *HarnessRPC) RegisterRPCMiddleware() (MiddlewareClient,
630
        context.CancelFunc) {
×
631

×
632
        ctxt, cancel := context.WithCancel(h.runCtx)
×
633

×
634
        stream, err := h.LN.RegisterRPCMiddleware(ctxt)
×
635
        h.NoError(err, "RegisterRPCMiddleware")
×
636

×
637
        return stream, cancel
×
638
}
×
639

640
type ChannelEventsClient lnrpc.Lightning_SubscribeChannelEventsClient
641

642
// SubscribeChannelEvents creates a subscription client for channel events and
643
// asserts its creation.
644
func (h *HarnessRPC) SubscribeChannelEvents() ChannelEventsClient {
×
645
        req := &lnrpc.ChannelEventSubscription{}
×
646

×
647
        // SubscribeChannelEvents needs to have the context alive for the
×
648
        // entire test case as the returned client will be used for send and
×
649
        // receive events stream. Thus we use runCtx here instead of a timeout
×
650
        // context.
×
651
        client, err := h.LN.SubscribeChannelEvents(h.runCtx, req)
×
652
        h.NoError(err, "SubscribeChannelEvents")
×
653

×
654
        return client
×
655
}
×
656

657
type CustomMessageClient lnrpc.Lightning_SubscribeCustomMessagesClient
658

659
// SubscribeCustomMessages creates a subscription client for custom messages.
660
func (h *HarnessRPC) SubscribeCustomMessages() (CustomMessageClient,
661
        context.CancelFunc) {
×
662

×
663
        ctxt, cancel := context.WithCancel(h.runCtx)
×
664

×
665
        req := &lnrpc.SubscribeCustomMessagesRequest{}
×
666

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

×
674
        return stream, cancel
×
675
}
×
676

677
// SendCustomMessage makes a RPC call to the node's SendCustomMessage and
678
// returns the response.
679
func (h *HarnessRPC) SendCustomMessage(
680
        req *lnrpc.SendCustomMessageRequest) *lnrpc.SendCustomMessageResponse {
×
681

×
682
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
683
        defer cancel()
×
684

×
685
        resp, err := h.LN.SendCustomMessage(ctxt, req)
×
686
        h.NoError(err, "SendCustomMessage")
×
687

×
688
        return resp
×
689
}
×
690

691
// GetChanInfo makes a RPC call to the node's GetChanInfo and returns the
692
// response.
693
func (h *HarnessRPC) GetChanInfo(
694
        req *lnrpc.ChanInfoRequest) *lnrpc.ChannelEdge {
×
695

×
696
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
697
        defer cancel()
×
698

×
699
        resp, err := h.LN.GetChanInfo(ctxt, req)
×
700
        h.NoError(err, "GetChanInfo")
×
701

×
702
        return resp
×
703
}
×
704

705
// LookupHtlcResolution makes a RPC call to the node's LookupHtlcResolution and
706
// returns the response.
707
//
708
//nolint:lll
709
func (h *HarnessRPC) LookupHtlcResolution(
710
        req *lnrpc.LookupHtlcResolutionRequest) *lnrpc.LookupHtlcResolutionResponse {
×
711

×
712
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
713
        defer cancel()
×
714

×
715
        resp, err := h.LN.LookupHtlcResolution(ctxt, req)
×
716
        h.NoError(err, "LookupHtlcResolution")
×
717

×
718
        return resp
×
719
}
×
720

721
// LookupHtlcResolutionAssertErr makes a RPC call to the node's
722
// LookupHtlcResolution and asserts an RPC error is returned.
723
func (h *HarnessRPC) LookupHtlcResolutionAssertErr(
724
        req *lnrpc.LookupHtlcResolutionRequest) error {
×
725

×
726
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
727
        defer cancel()
×
728

×
729
        _, err := h.LN.LookupHtlcResolution(ctxt, req)
×
730
        require.Error(h, err, "expected an error")
×
731

×
732
        return err
×
733
}
×
734

735
// Quiesce makes an RPC call to the node's Quiesce method and returns the
736
// response.
737
func (h *HarnessRPC) Quiesce(
NEW
738
        req *devrpc.QuiescenceRequest) *devrpc.QuiescenceResponse {
×
NEW
739

×
NEW
740
        ctx, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
NEW
741
        defer cancel()
×
NEW
742

×
NEW
743
        res, err := h.Dev.Quiesce(ctx, req)
×
NEW
744
        h.NoError(err, "Quiesce returned an error")
×
NEW
745

×
NEW
746
        return res
×
NEW
747
}
×
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