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

lightningnetwork / lnd / 15438307945

04 Jun 2025 09:08AM UTC coverage: 68.507% (+10.2%) from 58.311%
15438307945

Pull #9880

github

web-flow
Merge 472236409 into aec16eee9
Pull Request #9880: Improve access control in peer connections

138 of 173 new or added lines in 5 files covered. (79.77%)

27 existing lines in 9 files now uncovered.

134256 of 195974 relevant lines covered (68.51%)

21846.49 hits per line

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

0.0
/lntest/harness_assertion.go
1
package lntest
2

3
import (
4
        "bytes"
5
        "context"
6
        "crypto/rand"
7
        "encoding/hex"
8
        "encoding/json"
9
        "fmt"
10
        "math"
11
        "sort"
12
        "strings"
13
        "time"
14

15
        "github.com/btcsuite/btcd/btcec/v2"
16
        "github.com/btcsuite/btcd/btcec/v2/schnorr"
17
        "github.com/btcsuite/btcd/btcutil"
18
        "github.com/btcsuite/btcd/chaincfg/chainhash"
19
        "github.com/btcsuite/btcd/txscript"
20
        "github.com/btcsuite/btcd/wire"
21
        "github.com/lightningnetwork/lnd/channeldb"
22
        "github.com/lightningnetwork/lnd/lnrpc"
23
        "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
24
        "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
25
        "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
26
        "github.com/lightningnetwork/lnd/lntest/miner"
27
        "github.com/lightningnetwork/lnd/lntest/node"
28
        "github.com/lightningnetwork/lnd/lntest/rpc"
29
        "github.com/lightningnetwork/lnd/lntest/wait"
30
        "github.com/lightningnetwork/lnd/lntypes"
31
        "github.com/lightningnetwork/lnd/lnutils"
32
        "github.com/stretchr/testify/require"
33
        "google.golang.org/protobuf/proto"
34
)
35

36
// FindChannelOption is a functional type for an option that modifies a
37
// ListChannelsRequest.
38
type ListChannelOption func(r *lnrpc.ListChannelsRequest)
39

40
// WithPeerAliasLookup is an option for setting the peer alias lookup flag on a
41
// ListChannelsRequest.
42
func WithPeerAliasLookup() ListChannelOption {
×
43
        return func(r *lnrpc.ListChannelsRequest) {
×
44
                r.PeerAliasLookup = true
×
45
        }
×
46
}
47

48
// WaitForBlockchainSync waits until the node is synced to chain.
49
func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
×
50
        err := wait.NoError(func() error {
×
51
                resp := hn.RPC.GetInfo()
×
52
                if resp.SyncedToChain {
×
53
                        return nil
×
54
                }
×
55

56
                return fmt.Errorf("%s is not synced to chain", hn.Name())
×
57
        }, DefaultTimeout)
58

59
        require.NoError(h, err, "timeout waiting for blockchain sync")
×
60
}
61

62
// WaitForBlockchainSyncTo waits until the node is synced to bestBlock.
63
func (h *HarnessTest) WaitForBlockchainSyncTo(hn *node.HarnessNode,
64
        bestBlock chainhash.Hash) {
×
65

×
66
        bestBlockHash := bestBlock.String()
×
67
        err := wait.NoError(func() error {
×
68
                resp := hn.RPC.GetInfo()
×
69
                if resp.SyncedToChain {
×
70
                        if resp.BlockHash == bestBlockHash {
×
71
                                return nil
×
72
                        }
×
73

74
                        return fmt.Errorf("%s's backend is synced to the "+
×
75
                                "wrong block (expected=%s, actual=%s)",
×
76
                                hn.Name(), bestBlockHash, resp.BlockHash)
×
77
                }
78

79
                return fmt.Errorf("%s is not synced to chain", hn.Name())
×
80
        }, DefaultTimeout)
81

82
        require.NoError(h, err, "timeout waiting for blockchain sync")
×
83
}
84

85
// AssertPeerConnected asserts that the given node b is connected to a.
86
func (h *HarnessTest) AssertPeerConnected(a, b *node.HarnessNode) {
×
87
        err := wait.NoError(func() error {
×
88
                // We require the RPC call to be succeeded and won't wait for
×
89
                // it as it's an unexpected behavior.
×
90
                resp := a.RPC.ListPeers()
×
91

×
92
                // If node B is seen in the ListPeers response from node A,
×
93
                // then we can return true as the connection has been fully
×
94
                // established.
×
95
                for _, peer := range resp.Peers {
×
96
                        if peer.PubKey == b.PubKeyStr {
×
97
                                return nil
×
98
                        }
×
99
                }
100

101
                return fmt.Errorf("%s not found in %s's ListPeers",
×
102
                        b.Name(), a.Name())
×
103
        }, DefaultTimeout)
104

105
        require.NoError(h, err, "unable to connect %s to %s, got error: "+
×
106
                "peers not connected within %v seconds",
×
107
                a.Name(), b.Name(), DefaultTimeout)
×
108
}
109

110
// ConnectNodes creates a connection between the two nodes and asserts the
111
// connection is succeeded.
112
func (h *HarnessTest) ConnectNodes(a, b *node.HarnessNode) {
×
113
        bobInfo := b.RPC.GetInfo()
×
114

×
115
        req := &lnrpc.ConnectPeerRequest{
×
116
                Addr: &lnrpc.LightningAddress{
×
117
                        Pubkey: bobInfo.IdentityPubkey,
×
118
                        Host:   b.Cfg.P2PAddr(),
×
119
                },
×
120
        }
×
121
        a.RPC.ConnectPeer(req)
×
NEW
122
        h.AssertConnected(a, b)
×
123
}
×
124

125
// ConnectNodesPerm creates a persistent connection between the two nodes and
126
// asserts the connection is succeeded.
127
func (h *HarnessTest) ConnectNodesPerm(a, b *node.HarnessNode) {
×
128
        bobInfo := b.RPC.GetInfo()
×
129

×
130
        req := &lnrpc.ConnectPeerRequest{
×
131
                Addr: &lnrpc.LightningAddress{
×
132
                        Pubkey: bobInfo.IdentityPubkey,
×
133
                        Host:   b.Cfg.P2PAddr(),
×
134
                },
×
135
                Perm: true,
×
136
        }
×
137
        a.RPC.ConnectPeer(req)
×
138
        h.AssertPeerConnected(a, b)
×
139
}
×
140

141
// DisconnectNodes disconnects the given two nodes and asserts the
142
// disconnection is succeeded. The request is made from node a and sent to node
143
// b.
144
func (h *HarnessTest) DisconnectNodes(a, b *node.HarnessNode) {
×
145
        bobInfo := b.RPC.GetInfo()
×
146
        a.RPC.DisconnectPeer(bobInfo.IdentityPubkey)
×
147

×
148
        // Assert disconnected.
×
149
        h.AssertPeerNotConnected(a, b)
×
150
}
×
151

152
// EnsureConnected will try to connect to two nodes, returning no error if they
153
// are already connected. If the nodes were not connected previously, this will
154
// behave the same as ConnectNodes. If a pending connection request has already
155
// been made, the method will block until the two nodes appear in each other's
156
// peers list, or until the DefaultTimeout expires.
157
func (h *HarnessTest) EnsureConnected(a, b *node.HarnessNode) {
×
158
        // errConnectionRequested is used to signal that a connection was
×
159
        // requested successfully, which is distinct from already being
×
160
        // connected to the peer.
×
161
        errConnectionRequested := "connection request in progress"
×
162

×
163
        // windowsErr is an error we've seen from windows build where
×
164
        // connecting to an already connected node gives such error from the
×
165
        // receiver side.
×
166
        windowsErr := "An established connection was aborted by the software " +
×
167
                "in your host machine."
×
168

×
169
        tryConnect := func(a, b *node.HarnessNode) error {
×
170
                bInfo := b.RPC.GetInfo()
×
171

×
172
                req := &lnrpc.ConnectPeerRequest{
×
173
                        Addr: &lnrpc.LightningAddress{
×
174
                                Pubkey: bInfo.IdentityPubkey,
×
175
                                Host:   b.Cfg.P2PAddr(),
×
176
                        },
×
177
                }
×
178

×
179
                ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
180
                defer cancel()
×
181

×
182
                _, err := a.RPC.LN.ConnectPeer(ctxt, req)
×
183

×
184
                // Request was successful.
×
185
                if err == nil {
×
186
                        return nil
×
187
                }
×
188

189
                // If the two are already connected, we return early with no
190
                // error.
191
                if strings.Contains(err.Error(), "already connected to peer") {
×
192
                        return nil
×
193
                }
×
194

195
                // Otherwise we log the error to console.
196
                h.Logf("EnsureConnected %s=>%s got err: %v", a.Name(),
×
197
                        b.Name(), err)
×
198

×
199
                // If the connection is in process, we return no error.
×
200
                if strings.Contains(err.Error(), errConnectionRequested) {
×
201
                        return nil
×
202
                }
×
203

204
                // We may get connection refused error if we happens to be in
205
                // the middle of a previous node disconnection, e.g., a restart
206
                // from one of the nodes.
207
                if strings.Contains(err.Error(), "connection refused") {
×
208
                        return nil
×
209
                }
×
210

211
                // Check for windows error. If Alice connects to Bob, Alice
212
                // will throw "i/o timeout" and Bob will give windowsErr.
213
                if strings.Contains(err.Error(), windowsErr) {
×
214
                        return nil
×
215
                }
×
216

217
                if strings.Contains(err.Error(), "i/o timeout") {
×
218
                        return nil
×
219
                }
×
220

221
                return err
×
222
        }
223

224
        // Return any critical errors returned by either alice or bob.
225
        require.NoError(h, tryConnect(a, b), "connection failed between %s "+
×
226
                "and %s", a.Cfg.Name, b.Cfg.Name)
×
227

×
228
        // When Alice and Bob each makes a connection to the other side at the
×
229
        // same time, it's likely neither connections could succeed. Bob's
×
230
        // connection will be canceled by Alice since she has an outbound
×
231
        // connection to Bob already, and same happens to Alice's. Thus the two
×
232
        // connections cancel each other out.
×
233
        // TODO(yy): move this back when the above issue is fixed.
×
234
        // require.NoError(h, tryConnect(b, a), "connection failed between %s "+
×
235
        //         "and %s", a.Cfg.Name, b.Cfg.Name)
×
236

×
237
        // Otherwise one or both requested a connection, so we wait for the
×
238
        // peers lists to reflect the connection.
×
239
        h.AssertPeerConnected(a, b)
×
240
        h.AssertPeerConnected(b, a)
×
241
}
242

243
// ConnectNodesNoAssert creates a connection from node A to node B.
244
func (h *HarnessTest) ConnectNodesNoAssert(a, b *node.HarnessNode) (
NEW
245
        *lnrpc.ConnectPeerResponse, error) {
×
NEW
246

×
NEW
247
        bobInfo := b.RPC.GetInfo()
×
NEW
248

×
NEW
249
        req := &lnrpc.ConnectPeerRequest{
×
NEW
250
                Addr: &lnrpc.LightningAddress{
×
NEW
251
                        Pubkey: bobInfo.IdentityPubkey,
×
NEW
252
                        Host:   b.Cfg.P2PAddr(),
×
NEW
253
                },
×
NEW
254
        }
×
NEW
255
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
NEW
256
        defer cancel()
×
NEW
257

×
NEW
258
        return a.RPC.LN.ConnectPeer(ctxt, req)
×
NEW
259
}
×
260

261
// AssertNumEdges checks that an expected number of edges can be found in the
262
// node specified.
263
func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode,
264
        expected int, includeUnannounced bool) []*lnrpc.ChannelEdge {
×
265

×
266
        var edges []*lnrpc.ChannelEdge
×
267

×
268
        old := hn.State.Edge.Public
×
269
        if includeUnannounced {
×
270
                old = hn.State.Edge.Total
×
271
        }
×
272

273
        err := wait.NoError(func() error {
×
274
                req := &lnrpc.ChannelGraphRequest{
×
275
                        IncludeUnannounced: includeUnannounced,
×
276
                }
×
277
                resp := hn.RPC.DescribeGraph(req)
×
278
                total := len(resp.Edges)
×
279

×
280
                if total-old == expected {
×
281
                        if expected != 0 {
×
282
                                // NOTE: assume edges come in ascending order
×
283
                                // that the old edges are at the front of the
×
284
                                // slice.
×
285
                                edges = resp.Edges[old:]
×
286
                        }
×
287

288
                        return nil
×
289
                }
290

291
                return errNumNotMatched(hn.Name(), "num of channel edges",
×
292
                        expected, total-old, total, old)
×
293
        }, DefaultTimeout)
294

295
        require.NoError(h, err, "timeout while checking for edges")
×
296

×
297
        return edges
×
298
}
299

300
// ReceiveOpenChannelUpdate waits until a message is received on the stream or
301
// the timeout is reached.
302
func (h *HarnessTest) ReceiveOpenChannelUpdate(
303
        stream rpc.OpenChanClient) *lnrpc.OpenStatusUpdate {
×
304

×
305
        update, err := h.receiveOpenChannelUpdate(stream)
×
306
        require.NoError(h, err, "received err from open channel stream")
×
307

×
308
        return update
×
309
}
×
310

311
// ReceiveOpenChannelError waits for the expected error during the open channel
312
// flow from the peer or times out.
313
func (h *HarnessTest) ReceiveOpenChannelError(
314
        stream rpc.OpenChanClient, expectedErr error) {
×
315

×
316
        _, err := h.receiveOpenChannelUpdate(stream)
×
317
        require.Contains(h, err.Error(), expectedErr.Error(),
×
318
                "error not matched")
×
319
}
×
320

321
// receiveOpenChannelUpdate waits until a message or an error is received on
322
// the stream or the timeout is reached.
323
//
324
// TODO(yy): use generics to unify all receiving stream update once go@1.18 is
325
// used.
326
func (h *HarnessTest) receiveOpenChannelUpdate(
327
        stream rpc.OpenChanClient) (*lnrpc.OpenStatusUpdate, error) {
×
328

×
329
        chanMsg := make(chan *lnrpc.OpenStatusUpdate)
×
330
        errChan := make(chan error)
×
331
        go func() {
×
332
                // Consume one message. This will block until the message is
×
333
                // received.
×
334
                resp, err := stream.Recv()
×
335
                if err != nil {
×
336
                        errChan <- err
×
337
                        return
×
338
                }
×
339
                chanMsg <- resp
×
340
        }()
341

342
        select {
×
343
        case <-time.After(DefaultTimeout):
×
344
                require.Fail(h, "timeout", "timeout waiting for open channel "+
×
345
                        "update sent")
×
346
                return nil, nil
×
347

348
        case err := <-errChan:
×
349
                return nil, err
×
350

351
        case updateMsg := <-chanMsg:
×
352
                return updateMsg, nil
×
353
        }
354
}
355

356
// WaitForChannelOpenEvent waits for a notification that a channel is open by
357
// consuming a message from the passed open channel stream.
358
func (h HarnessTest) WaitForChannelOpenEvent(
359
        stream rpc.OpenChanClient) *lnrpc.ChannelPoint {
×
360

×
361
        // Consume one event.
×
362
        event := h.ReceiveOpenChannelUpdate(stream)
×
363

×
364
        resp, ok := event.Update.(*lnrpc.OpenStatusUpdate_ChanOpen)
×
365
        require.Truef(h, ok, "expected channel open update, instead got %v",
×
366
                resp)
×
367

×
368
        return resp.ChanOpen.ChannelPoint
×
369
}
×
370

371
// AssertChannelExists asserts that an active channel identified by the
372
// specified channel point exists from the point-of-view of the node.
373
func (h *HarnessTest) AssertChannelExists(hn *node.HarnessNode,
374
        cp *lnrpc.ChannelPoint) *lnrpc.Channel {
×
375

×
376
        return h.assertChannelStatus(hn, cp, true)
×
377
}
×
378

379
// AssertChannelActive checks if a channel identified by the specified channel
380
// point is active.
381
func (h *HarnessTest) AssertChannelActive(hn *node.HarnessNode,
382
        cp *lnrpc.ChannelPoint) *lnrpc.Channel {
×
383

×
384
        return h.assertChannelStatus(hn, cp, true)
×
385
}
×
386

387
// AssertChannelInactive checks if a channel identified by the specified channel
388
// point is inactive.
389
func (h *HarnessTest) AssertChannelInactive(hn *node.HarnessNode,
390
        cp *lnrpc.ChannelPoint) *lnrpc.Channel {
×
391

×
392
        return h.assertChannelStatus(hn, cp, false)
×
393
}
×
394

395
// assertChannelStatus asserts that a channel identified by the specified
396
// channel point exists from the point-of-view of the node and that it is either
397
// active or inactive depending on the value of the active parameter.
398
func (h *HarnessTest) assertChannelStatus(hn *node.HarnessNode,
399
        cp *lnrpc.ChannelPoint, active bool) *lnrpc.Channel {
×
400

×
401
        var (
×
402
                channel *lnrpc.Channel
×
403
                err     error
×
404
        )
×
405

×
406
        err = wait.NoError(func() error {
×
407
                channel, err = h.findChannel(hn, cp)
×
408
                if err != nil {
×
409
                        return err
×
410
                }
×
411

412
                // Check whether the channel is active, exit early if it is.
413
                if channel.Active == active {
×
414
                        return nil
×
415
                }
×
416

417
                return fmt.Errorf("expected channel_active=%v, got %v",
×
418
                        active, channel.Active)
×
419
        }, DefaultTimeout)
420

421
        require.NoErrorf(h, err, "%s: timeout checking for channel point: %v",
×
422
                hn.Name(), h.OutPointFromChannelPoint(cp))
×
423

×
424
        return channel
×
425
}
426

427
// AssertOutputScriptClass checks that the specified transaction output has the
428
// expected script class.
429
func (h *HarnessTest) AssertOutputScriptClass(tx *btcutil.Tx,
430
        outputIndex uint32, scriptClass txscript.ScriptClass) {
×
431

×
432
        require.Greater(h, len(tx.MsgTx().TxOut), int(outputIndex))
×
433

×
434
        txOut := tx.MsgTx().TxOut[outputIndex]
×
435

×
436
        pkScript, err := txscript.ParsePkScript(txOut.PkScript)
×
437
        require.NoError(h, err)
×
438
        require.Equal(h, scriptClass, pkScript.Class())
×
439
}
×
440

441
// findChannel tries to find a target channel in the node using the given
442
// channel point.
443
func (h *HarnessTest) findChannel(hn *node.HarnessNode,
444
        chanPoint *lnrpc.ChannelPoint,
445
        opts ...ListChannelOption) (*lnrpc.Channel, error) {
×
446

×
447
        // Get the funding point.
×
448
        fp := h.OutPointFromChannelPoint(chanPoint)
×
449

×
450
        req := &lnrpc.ListChannelsRequest{}
×
451

×
452
        for _, opt := range opts {
×
453
                opt(req)
×
454
        }
×
455

456
        channelInfo := hn.RPC.ListChannels(req)
×
457

×
458
        // Find the target channel.
×
459
        for _, channel := range channelInfo.Channels {
×
460
                if channel.ChannelPoint == fp.String() {
×
461
                        return channel, nil
×
462
                }
×
463
        }
464

465
        return nil, fmt.Errorf("%s: channel not found using %s", hn.Name(),
×
466
                fp.String())
×
467
}
468

469
// ReceiveCloseChannelUpdate waits until a message or an error is received on
470
// the subscribe channel close stream or the timeout is reached.
471
func (h *HarnessTest) ReceiveCloseChannelUpdate(
472
        stream rpc.CloseChanClient) (*lnrpc.CloseStatusUpdate, error) {
×
473

×
474
        chanMsg := make(chan *lnrpc.CloseStatusUpdate)
×
475
        errChan := make(chan error)
×
476
        go func() {
×
477
                // Consume one message. This will block until the message is
×
478
                // received.
×
479
                resp, err := stream.Recv()
×
480
                if err != nil {
×
481
                        errChan <- err
×
482
                        return
×
483
                }
×
484
                chanMsg <- resp
×
485
        }()
486

487
        select {
×
488
        case <-time.After(DefaultTimeout):
×
489
                require.Fail(h, "timeout", "timeout waiting for close channel "+
×
490
                        "update sent")
×
491

×
492
                return nil, nil
×
493

494
        case err := <-errChan:
×
495
                return nil, fmt.Errorf("received err from close channel "+
×
496
                        "stream: %v", err)
×
497

498
        case updateMsg := <-chanMsg:
×
499
                return updateMsg, nil
×
500
        }
501
}
502

503
type WaitingCloseChannel *lnrpc.PendingChannelsResponse_WaitingCloseChannel
504

505
// AssertChannelWaitingClose asserts that the given channel found in the node
506
// is waiting close. Returns the WaitingCloseChannel if found.
507
func (h *HarnessTest) AssertChannelWaitingClose(hn *node.HarnessNode,
508
        chanPoint *lnrpc.ChannelPoint) WaitingCloseChannel {
×
509

×
510
        var target WaitingCloseChannel
×
511

×
512
        op := h.OutPointFromChannelPoint(chanPoint)
×
513

×
514
        err := wait.NoError(func() error {
×
515
                resp := hn.RPC.PendingChannels()
×
516

×
517
                for _, waitingClose := range resp.WaitingCloseChannels {
×
518
                        if waitingClose.Channel.ChannelPoint == op.String() {
×
519
                                target = waitingClose
×
520
                                return nil
×
521
                        }
×
522
                }
523

524
                return fmt.Errorf("%v: channel %s not found in waiting close",
×
525
                        hn.Name(), op)
×
526
        }, DefaultTimeout)
527
        require.NoError(h, err, "assert channel waiting close timed out")
×
528

×
529
        return target
×
530
}
531

532
// AssertTopologyChannelClosed asserts a given channel is closed by checking
533
// the graph topology subscription of the specified node. Returns the closed
534
// channel update if found.
535
func (h *HarnessTest) AssertTopologyChannelClosed(hn *node.HarnessNode,
536
        chanPoint *lnrpc.ChannelPoint) *lnrpc.ClosedChannelUpdate {
×
537

×
538
        closedChan, err := hn.Watcher.WaitForChannelClose(chanPoint)
×
539
        require.NoError(h, err, "failed to wait for channel close")
×
540

×
541
        return closedChan
×
542
}
×
543

544
// WaitForChannelCloseEvent waits for a notification that a channel is closed
545
// by consuming a message from the passed close channel stream. Returns the
546
// closing txid if found.
547
func (h HarnessTest) WaitForChannelCloseEvent(
548
        stream rpc.CloseChanClient) chainhash.Hash {
×
549

×
550
        // Consume one event.
×
551
        event, err := h.ReceiveCloseChannelUpdate(stream)
×
552
        require.NoError(h, err)
×
553

×
554
        resp, ok := event.Update.(*lnrpc.CloseStatusUpdate_ChanClose)
×
555
        require.Truef(h, ok, "expected channel close update, instead got %v",
×
556
                event.Update)
×
557

×
558
        txid, err := chainhash.NewHash(resp.ChanClose.ClosingTxid)
×
559
        require.NoErrorf(h, err, "wrong format found in closing txid: %v",
×
560
                resp.ChanClose.ClosingTxid)
×
561

×
562
        return *txid
×
563
}
×
564

565
// AssertNumWaitingClose checks that a PendingChannels response from the node
566
// reports the expected number of waiting close channels.
567
func (h *HarnessTest) AssertNumWaitingClose(hn *node.HarnessNode,
568
        num int) []*lnrpc.PendingChannelsResponse_WaitingCloseChannel {
×
569

×
570
        var channels []*lnrpc.PendingChannelsResponse_WaitingCloseChannel
×
571
        oldWaiting := hn.State.CloseChannel.WaitingClose
×
572

×
573
        err := wait.NoError(func() error {
×
574
                resp := hn.RPC.PendingChannels()
×
575
                channels = resp.WaitingCloseChannels
×
576
                total := len(channels)
×
577

×
578
                got := total - oldWaiting
×
579
                if got == num {
×
580
                        return nil
×
581
                }
×
582

583
                return errNumNotMatched(hn.Name(), "waiting close channels",
×
584
                        num, got, total, oldWaiting)
×
585
        }, DefaultTimeout)
586

587
        require.NoErrorf(h, err, "%s: assert waiting close timeout",
×
588
                hn.Name())
×
589

×
590
        return channels
×
591
}
592

593
// AssertNumPendingForceClose checks that a PendingChannels response from the
594
// node reports the expected number of pending force close channels.
595
func (h *HarnessTest) AssertNumPendingForceClose(hn *node.HarnessNode,
596
        num int) []*lnrpc.PendingChannelsResponse_ForceClosedChannel {
×
597

×
598
        var channels []*lnrpc.PendingChannelsResponse_ForceClosedChannel
×
599
        oldForce := hn.State.CloseChannel.PendingForceClose
×
600

×
601
        err := wait.NoError(func() error {
×
602
                // TODO(yy): we should be able to use `hn.RPC.PendingChannels`
×
603
                // here to avoid checking the RPC error. However, we may get a
×
604
                // `unable to find arbitrator` error from the rpc point, due to
×
605
                // a timing issue in rpcserver,
×
606
                // 1. `r.server.chanStateDB.FetchClosedChannels` fetches
×
607
                //    the pending force close channel.
×
608
                // 2. `r.arbitratorPopulateForceCloseResp` relies on the
×
609
                //    channel arbitrator to get the report, and,
×
610
                // 3. the arbitrator may be deleted due to the force close
×
611
                //    channel being resolved.
×
612
                // Somewhere along the line is missing a lock to keep the data
×
613
                // consistent.
×
614
                req := &lnrpc.PendingChannelsRequest{}
×
615
                resp, err := hn.RPC.LN.PendingChannels(h.runCtx, req)
×
616
                if err != nil {
×
617
                        return fmt.Errorf("PendingChannels got: %w", err)
×
618
                }
×
619

620
                channels = resp.PendingForceClosingChannels
×
621
                total := len(channels)
×
622

×
623
                got := total - oldForce
×
624
                if got == num {
×
625
                        return nil
×
626
                }
×
627

628
                return errNumNotMatched(hn.Name(), "pending force close "+
×
629
                        "channels", num, got, total, oldForce)
×
630
        }, DefaultTimeout)
631

632
        require.NoErrorf(h, err, "%s: assert pending force close timeout",
×
633
                hn.Name())
×
634

×
635
        return channels
×
636
}
637

638
// AssertStreamChannelCoopClosed reads an update from the close channel client
639
// stream and asserts that the mempool state and node's topology match a coop
640
// close. In specific,
641
// - assert the channel is waiting close and has the expected ChanStatusFlags.
642
// - assert the mempool has the closing txes and anchor sweeps.
643
// - mine a block and assert the closing txid is mined.
644
// - assert the node has zero waiting close channels.
645
// - assert the node has seen the channel close update.
646
func (h *HarnessTest) AssertStreamChannelCoopClosed(hn *node.HarnessNode,
647
        cp *lnrpc.ChannelPoint, anchors bool,
648
        stream rpc.CloseChanClient) chainhash.Hash {
×
649

×
650
        // Assert the channel is waiting close.
×
651
        resp := h.AssertChannelWaitingClose(hn, cp)
×
652

×
653
        // Assert that the channel is in coop broadcasted.
×
654
        require.Contains(h, resp.Channel.ChanStatusFlags,
×
655
                channeldb.ChanStatusCoopBroadcasted.String(),
×
656
                "channel not coop broadcasted")
×
657

×
658
        // We'll now, generate a single block, wait for the final close status
×
659
        // update, then ensure that the closing transaction was included in the
×
660
        // block. If there are anchors, we also expect an anchor sweep.
×
661
        expectedTxes := 1
×
662
        if anchors {
×
663
                expectedTxes = 2
×
664
        }
×
665
        block := h.MineBlocksAndAssertNumTxes(1, expectedTxes)[0]
×
666

×
667
        // Consume one close event and assert the closing txid can be found in
×
668
        // the block.
×
669
        closingTxid := h.WaitForChannelCloseEvent(stream)
×
670
        h.AssertTxInBlock(block, closingTxid)
×
671

×
672
        // We should see zero waiting close channels now.
×
673
        h.AssertNumWaitingClose(hn, 0)
×
674

×
675
        // Finally, check that the node's topology graph has seen this channel
×
676
        // closed if it's a public channel.
×
677
        if !resp.Channel.Private {
×
678
                h.AssertTopologyChannelClosed(hn, cp)
×
679
        }
×
680

681
        return closingTxid
×
682
}
683

684
// AssertStreamChannelForceClosed reads an update from the close channel client
685
// stream and asserts that the mempool state and node's topology match a local
686
// force close. In specific,
687
//   - assert the channel is waiting close and has the expected ChanStatusFlags.
688
//   - assert the mempool has the closing txes.
689
//   - mine a block and assert the closing txid is mined.
690
//   - assert the channel is pending force close.
691
//   - assert the node has seen the channel close update.
692
//   - assert there's a pending anchor sweep request once the force close tx is
693
//     confirmed.
694
func (h *HarnessTest) AssertStreamChannelForceClosed(hn *node.HarnessNode,
695
        cp *lnrpc.ChannelPoint, anchorSweep bool,
696
        stream rpc.CloseChanClient) chainhash.Hash {
×
697

×
698
        // Assert the channel is waiting close.
×
699
        resp := h.AssertChannelWaitingClose(hn, cp)
×
700

×
701
        // Assert that the channel is in local force broadcasted.
×
702
        require.Contains(h, resp.Channel.ChanStatusFlags,
×
703
                channeldb.ChanStatusLocalCloseInitiator.String(),
×
704
                "channel not coop broadcasted")
×
705

×
706
        // Get the closing txid.
×
707
        closeTxid, err := chainhash.NewHashFromStr(resp.ClosingTxid)
×
708
        require.NoError(h, err)
×
709

×
710
        // We'll now, generate a single block, wait for the final close status
×
711
        // update, then ensure that the closing transaction was included in the
×
712
        // block.
×
713
        closeTx := h.AssertTxInMempool(*closeTxid)
×
714
        h.MineBlockWithTx(closeTx)
×
715

×
716
        // Consume one close event and assert the closing txid can be found in
×
717
        // the block.
×
718
        closingTxid := h.WaitForChannelCloseEvent(stream)
×
719

×
720
        // We should see zero waiting close channels and 1 pending force close
×
721
        // channels now.
×
722
        h.AssertNumWaitingClose(hn, 0)
×
723
        h.AssertNumPendingForceClose(hn, 1)
×
724

×
725
        // Finally, check that the node's topology graph has seen this channel
×
726
        // closed if it's a public channel.
×
727
        if !resp.Channel.Private {
×
728
                h.AssertTopologyChannelClosed(hn, cp)
×
729
        }
×
730

731
        // Assert there's a pending anchor sweep.
732
        //
733
        // NOTE: We may have a local sweep here, that's why we use
734
        // AssertAtLeastNumPendingSweeps instead of AssertNumPendingSweeps.
735
        if anchorSweep {
×
736
                h.AssertAtLeastNumPendingSweeps(hn, 1)
×
737
        }
×
738

739
        return closingTxid
×
740
}
741

742
// AssertChannelPolicyUpdate checks that the required policy update has
743
// happened on the given node.
744
func (h *HarnessTest) AssertChannelPolicyUpdate(hn *node.HarnessNode,
745
        advertisingNode *node.HarnessNode, policy *lnrpc.RoutingPolicy,
746
        chanPoint *lnrpc.ChannelPoint, includeUnannounced bool) {
×
747

×
748
        require.NoError(
×
749
                h, hn.Watcher.WaitForChannelPolicyUpdate(
×
750
                        advertisingNode, policy,
×
751
                        chanPoint, includeUnannounced,
×
752
                ), "%s: error while waiting for channel update", hn.Name(),
×
753
        )
×
754
}
×
755

756
// WaitForGraphSync waits until the node is synced to graph or times out.
757
func (h *HarnessTest) WaitForGraphSync(hn *node.HarnessNode) {
×
758
        err := wait.NoError(func() error {
×
759
                resp := hn.RPC.GetInfo()
×
760
                if resp.SyncedToGraph {
×
761
                        return nil
×
762
                }
×
763

764
                return fmt.Errorf("node not synced to graph")
×
765
        }, DefaultTimeout)
766
        require.NoError(h, err, "%s: timeout while sync to graph", hn.Name())
×
767
}
768

769
// AssertNumUTXOsWithConf waits for the given number of UTXOs with the
770
// specified confirmations range to be available or fails if that isn't the
771
// case before the default timeout.
772
func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode,
773
        expectedUtxos int, max, min int32) []*lnrpc.Utxo {
×
774

×
775
        var unconfirmed bool
×
776

×
777
        if max == 0 {
×
778
                unconfirmed = true
×
779
        }
×
780

781
        var utxos []*lnrpc.Utxo
×
782
        err := wait.NoError(func() error {
×
783
                req := &walletrpc.ListUnspentRequest{
×
784
                        Account:         "",
×
785
                        MaxConfs:        max,
×
786
                        MinConfs:        min,
×
787
                        UnconfirmedOnly: unconfirmed,
×
788
                }
×
789
                resp := hn.RPC.ListUnspent(req)
×
790
                total := len(resp.Utxos)
×
791

×
792
                if total == expectedUtxos {
×
793
                        utxos = resp.Utxos
×
794

×
795
                        return nil
×
796
                }
×
797

798
                desc := "has UTXOs:\n"
×
799
                for _, utxo := range resp.Utxos {
×
800
                        desc += fmt.Sprintf("%v\n", utxo)
×
801
                }
×
802

803
                return fmt.Errorf("%s: assert num of UTXOs failed: want %d, "+
×
804
                        "got: %d, %s", hn.Name(), expectedUtxos, total, desc)
×
805
        }, DefaultTimeout)
806
        require.NoError(h, err, "timeout waiting for UTXOs")
×
807

×
808
        return utxos
×
809
}
810

811
// AssertNumUTXOsUnconfirmed asserts the expected num of unconfirmed utxos are
812
// seen.
813
func (h *HarnessTest) AssertNumUTXOsUnconfirmed(hn *node.HarnessNode,
814
        num int) []*lnrpc.Utxo {
×
815

×
816
        return h.AssertNumUTXOsWithConf(hn, num, 0, 0)
×
817
}
×
818

819
// AssertNumUTXOsConfirmed asserts the expected num of confirmed utxos are
820
// seen, which means the returned utxos have at least one confirmation.
821
func (h *HarnessTest) AssertNumUTXOsConfirmed(hn *node.HarnessNode,
822
        num int) []*lnrpc.Utxo {
×
823

×
824
        return h.AssertNumUTXOsWithConf(hn, num, math.MaxInt32, 1)
×
825
}
×
826

827
// AssertNumUTXOs asserts the expected num of utxos are seen, including
828
// confirmed and unconfirmed outputs.
829
func (h *HarnessTest) AssertNumUTXOs(hn *node.HarnessNode,
830
        num int) []*lnrpc.Utxo {
×
831

×
832
        return h.AssertNumUTXOsWithConf(hn, num, math.MaxInt32, 0)
×
833
}
×
834

835
// getUTXOs gets the number of newly created UTOXs within the current test
836
// scope.
837
func (h *HarnessTest) getUTXOs(hn *node.HarnessNode, account string,
838
        max, min int32) []*lnrpc.Utxo {
×
839

×
840
        var unconfirmed bool
×
841

×
842
        if max == 0 {
×
843
                unconfirmed = true
×
844
        }
×
845

846
        req := &walletrpc.ListUnspentRequest{
×
847
                Account:         account,
×
848
                MaxConfs:        max,
×
849
                MinConfs:        min,
×
850
                UnconfirmedOnly: unconfirmed,
×
851
        }
×
852
        resp := hn.RPC.ListUnspent(req)
×
853

×
854
        return resp.Utxos
×
855
}
856

857
// GetUTXOs returns all the UTXOs for the given node's account, including
858
// confirmed and unconfirmed.
859
func (h *HarnessTest) GetUTXOs(hn *node.HarnessNode,
860
        account string) []*lnrpc.Utxo {
×
861

×
862
        return h.getUTXOs(hn, account, math.MaxInt32, 0)
×
863
}
×
864

865
// GetUTXOsConfirmed returns the confirmed UTXOs for the given node's account.
866
func (h *HarnessTest) GetUTXOsConfirmed(hn *node.HarnessNode,
867
        account string) []*lnrpc.Utxo {
×
868

×
869
        return h.getUTXOs(hn, account, math.MaxInt32, 1)
×
870
}
×
871

872
// GetUTXOsUnconfirmed returns the unconfirmed UTXOs for the given node's
873
// account.
874
func (h *HarnessTest) GetUTXOsUnconfirmed(hn *node.HarnessNode,
875
        account string) []*lnrpc.Utxo {
×
876

×
877
        return h.getUTXOs(hn, account, 0, 0)
×
878
}
×
879

880
// WaitForBalanceConfirmed waits until the node sees the expected confirmed
881
// balance in its wallet.
882
func (h *HarnessTest) WaitForBalanceConfirmed(hn *node.HarnessNode,
883
        expected btcutil.Amount) {
×
884

×
885
        var lastBalance btcutil.Amount
×
886
        err := wait.NoError(func() error {
×
887
                resp := hn.RPC.WalletBalance()
×
888

×
889
                lastBalance = btcutil.Amount(resp.ConfirmedBalance)
×
890
                if lastBalance == expected {
×
891
                        return nil
×
892
                }
×
893

894
                return fmt.Errorf("expected %v, only have %v", expected,
×
895
                        lastBalance)
×
896
        }, DefaultTimeout)
897

898
        require.NoError(h, err, "timeout waiting for confirmed balances")
×
899
}
900

901
// WaitForBalanceUnconfirmed waits until the node sees the expected unconfirmed
902
// balance in its wallet.
903
func (h *HarnessTest) WaitForBalanceUnconfirmed(hn *node.HarnessNode,
904
        expected btcutil.Amount) {
×
905

×
906
        var lastBalance btcutil.Amount
×
907
        err := wait.NoError(func() error {
×
908
                resp := hn.RPC.WalletBalance()
×
909

×
910
                lastBalance = btcutil.Amount(resp.UnconfirmedBalance)
×
911
                if lastBalance == expected {
×
912
                        return nil
×
913
                }
×
914

915
                return fmt.Errorf("expected %v, only have %v", expected,
×
916
                        lastBalance)
×
917
        }, DefaultTimeout)
918

919
        require.NoError(h, err, "timeout waiting for unconfirmed balances")
×
920
}
921

922
// Random32Bytes generates a random 32 bytes which can be used as a pay hash,
923
// preimage, etc.
924
func (h *HarnessTest) Random32Bytes() []byte {
×
925
        randBuf := make([]byte, lntypes.HashSize)
×
926

×
927
        _, err := rand.Read(randBuf)
×
928
        require.NoErrorf(h, err, "internal error, cannot generate random bytes")
×
929

×
930
        return randBuf
×
931
}
×
932

933
// RandomPreimage generates a random preimage which can be used as a payment
934
// preimage.
935
func (h *HarnessTest) RandomPreimage() lntypes.Preimage {
×
936
        var preimage lntypes.Preimage
×
937
        copy(preimage[:], h.Random32Bytes())
×
938

×
939
        return preimage
×
940
}
×
941

942
// DecodeAddress decodes a given address and asserts there's no error.
943
func (h *HarnessTest) DecodeAddress(addr string) btcutil.Address {
×
944
        resp, err := btcutil.DecodeAddress(addr, miner.HarnessNetParams)
×
945
        require.NoError(h, err, "DecodeAddress failed")
×
946

×
947
        return resp
×
948
}
×
949

950
// PayToAddrScript creates a new script from the given address and asserts
951
// there's no error.
952
func (h *HarnessTest) PayToAddrScript(addr btcutil.Address) []byte {
×
953
        addrScript, err := txscript.PayToAddrScript(addr)
×
954
        require.NoError(h, err, "PayToAddrScript failed")
×
955

×
956
        return addrScript
×
957
}
×
958

959
// AssertChannelBalanceResp makes a ChannelBalance request and checks the
960
// returned response matches the expected.
961
func (h *HarnessTest) AssertChannelBalanceResp(hn *node.HarnessNode,
962
        expected *lnrpc.ChannelBalanceResponse) {
×
963

×
964
        resp := hn.RPC.ChannelBalance()
×
965

×
966
        // Ignore custom channel data of both expected and actual responses.
×
967
        expected.CustomChannelData = nil
×
968
        resp.CustomChannelData = nil
×
969

×
970
        require.True(h, proto.Equal(expected, resp), "balance is incorrect "+
×
971
                "got: %v, want: %v", resp, expected)
×
972
}
×
973

974
// GetChannelByChanPoint tries to find a channel matching the channel point and
975
// asserts. It returns the channel found.
976
func (h *HarnessTest) GetChannelByChanPoint(hn *node.HarnessNode,
977
        chanPoint *lnrpc.ChannelPoint) *lnrpc.Channel {
×
978

×
979
        channel, err := h.findChannel(hn, chanPoint)
×
980
        require.NoErrorf(h, err, "channel not found using %v", chanPoint)
×
981

×
982
        return channel
×
983
}
×
984

985
// GetChannelCommitType retrieves the active channel commitment type for the
986
// given chan point.
987
func (h *HarnessTest) GetChannelCommitType(hn *node.HarnessNode,
988
        chanPoint *lnrpc.ChannelPoint) lnrpc.CommitmentType {
×
989

×
990
        c := h.GetChannelByChanPoint(hn, chanPoint)
×
991

×
992
        return c.CommitmentType
×
993
}
×
994

995
// AssertNumPendingOpenChannels asserts that a given node have the expected
996
// number of pending open channels.
997
func (h *HarnessTest) AssertNumPendingOpenChannels(hn *node.HarnessNode,
998
        expected int) []*lnrpc.PendingChannelsResponse_PendingOpenChannel {
×
999

×
1000
        var channels []*lnrpc.PendingChannelsResponse_PendingOpenChannel
×
1001

×
1002
        oldNum := hn.State.OpenChannel.Pending
×
1003

×
1004
        err := wait.NoError(func() error {
×
1005
                resp := hn.RPC.PendingChannels()
×
1006
                channels = resp.PendingOpenChannels
×
1007
                total := len(channels)
×
1008

×
1009
                numChans := total - oldNum
×
1010

×
1011
                if numChans != expected {
×
1012
                        return errNumNotMatched(hn.Name(),
×
1013
                                "pending open channels", expected,
×
1014
                                numChans, total, oldNum)
×
1015
                }
×
1016

1017
                return nil
×
1018
        }, DefaultTimeout)
1019

1020
        require.NoError(h, err, "num of pending open channels not match")
×
1021

×
1022
        return channels
×
1023
}
1024

1025
// AssertNodesNumPendingOpenChannels asserts that both of the nodes have the
1026
// expected number of pending open channels.
1027
func (h *HarnessTest) AssertNodesNumPendingOpenChannels(a, b *node.HarnessNode,
1028
        expected int) {
×
1029

×
1030
        h.AssertNumPendingOpenChannels(a, expected)
×
1031
        h.AssertNumPendingOpenChannels(b, expected)
×
1032
}
×
1033

1034
// AssertPaymentStatusFromStream takes a client stream and asserts the payment
1035
// is in desired status before default timeout. The payment found is returned
1036
// once succeeded.
1037
func (h *HarnessTest) AssertPaymentStatusFromStream(stream rpc.PaymentClient,
1038
        status lnrpc.Payment_PaymentStatus) *lnrpc.Payment {
×
1039

×
1040
        return h.assertPaymentStatusWithTimeout(
×
1041
                stream, status, wait.PaymentTimeout,
×
1042
        )
×
1043
}
×
1044

1045
// AssertPaymentSucceedWithTimeout asserts that a payment is succeeded within
1046
// the specified timeout.
1047
func (h *HarnessTest) AssertPaymentSucceedWithTimeout(stream rpc.PaymentClient,
1048
        timeout time.Duration) *lnrpc.Payment {
×
1049

×
1050
        return h.assertPaymentStatusWithTimeout(
×
1051
                stream, lnrpc.Payment_SUCCEEDED, timeout,
×
1052
        )
×
1053
}
×
1054

1055
// assertPaymentStatusWithTimeout takes a client stream and asserts the payment
1056
// is in desired status before the specified timeout. The payment found is
1057
// returned once succeeded.
1058
func (h *HarnessTest) assertPaymentStatusWithTimeout(stream rpc.PaymentClient,
1059
        status lnrpc.Payment_PaymentStatus,
1060
        timeout time.Duration) *lnrpc.Payment {
×
1061

×
1062
        var target *lnrpc.Payment
×
1063
        err := wait.NoError(func() error {
×
1064
                // Consume one message. This will raise an error if the message
×
1065
                // is not received within DefaultTimeout.
×
1066
                payment, err := h.receivePaymentUpdateWithTimeout(
×
1067
                        stream, timeout,
×
1068
                )
×
1069
                if err != nil {
×
1070
                        return fmt.Errorf("received error from payment "+
×
1071
                                "stream: %s", err)
×
1072
                }
×
1073

1074
                // Return if the desired payment state is reached.
1075
                if payment.Status == status {
×
1076
                        target = payment
×
1077

×
1078
                        return nil
×
1079
                }
×
1080

1081
                // Return the err so that it can be used for debugging when
1082
                // timeout is reached.
1083
                return fmt.Errorf("payment %v status, got %v, want %v",
×
1084
                        payment.PaymentHash, payment.Status, status)
×
1085
        }, timeout)
1086

1087
        require.NoError(h, err, "timeout while waiting payment")
×
1088

×
1089
        return target
×
1090
}
1091

1092
// ReceivePaymentUpdate waits until a message is received on the payment client
1093
// stream or the timeout is reached.
1094
func (h *HarnessTest) ReceivePaymentUpdate(
1095
        stream rpc.PaymentClient) (*lnrpc.Payment, error) {
×
1096

×
1097
        return h.receivePaymentUpdateWithTimeout(stream, DefaultTimeout)
×
1098
}
×
1099

1100
// receivePaymentUpdateWithTimeout waits until a message is received on the
1101
// payment client stream or the timeout is reached.
1102
func (h *HarnessTest) receivePaymentUpdateWithTimeout(stream rpc.PaymentClient,
1103
        timeout time.Duration) (*lnrpc.Payment, error) {
×
1104

×
1105
        chanMsg := make(chan *lnrpc.Payment, 1)
×
1106
        errChan := make(chan error, 1)
×
1107

×
1108
        go func() {
×
1109
                // Consume one message. This will block until the message is
×
1110
                // received.
×
1111
                resp, err := stream.Recv()
×
1112
                if err != nil {
×
1113
                        errChan <- err
×
1114

×
1115
                        return
×
1116
                }
×
1117
                chanMsg <- resp
×
1118
        }()
1119

1120
        select {
×
1121
        case <-time.After(timeout):
×
1122
                require.Fail(h, "timeout", "timeout waiting for payment update")
×
1123
                return nil, nil
×
1124

1125
        case err := <-errChan:
×
1126
                return nil, err
×
1127

1128
        case updateMsg := <-chanMsg:
×
1129
                return updateMsg, nil
×
1130
        }
1131
}
1132

1133
// AssertInvoiceSettled asserts a given invoice specified by its payment
1134
// address is settled.
1135
func (h *HarnessTest) AssertInvoiceSettled(hn *node.HarnessNode, addr []byte) {
×
1136
        msg := &invoicesrpc.LookupInvoiceMsg{
×
1137
                InvoiceRef: &invoicesrpc.LookupInvoiceMsg_PaymentAddr{
×
1138
                        PaymentAddr: addr,
×
1139
                },
×
1140
        }
×
1141

×
1142
        err := wait.NoError(func() error {
×
1143
                invoice := hn.RPC.LookupInvoiceV2(msg)
×
1144
                if invoice.State == lnrpc.Invoice_SETTLED {
×
1145
                        return nil
×
1146
                }
×
1147

1148
                return fmt.Errorf("%s: invoice with payment address %x not "+
×
1149
                        "settled", hn.Name(), addr)
×
1150
        }, DefaultTimeout)
1151
        require.NoError(h, err, "timeout waiting for invoice settled state")
×
1152
}
1153

1154
// AssertNodeNumChannels polls the provided node's list channels rpc until it
1155
// reaches the desired number of total channels.
1156
func (h *HarnessTest) AssertNodeNumChannels(hn *node.HarnessNode,
1157
        numChannels int) {
×
1158

×
1159
        // Get the total number of channels.
×
1160
        old := hn.State.OpenChannel.Active + hn.State.OpenChannel.Inactive
×
1161

×
1162
        err := wait.NoError(func() error {
×
1163
                // We require the RPC call to be succeeded and won't wait for
×
1164
                // it as it's an unexpected behavior.
×
1165
                chanInfo := hn.RPC.ListChannels(&lnrpc.ListChannelsRequest{})
×
1166

×
1167
                // Return true if the query returned the expected number of
×
1168
                // channels.
×
1169
                num := len(chanInfo.Channels) - old
×
1170
                if num != numChannels {
×
1171
                        return fmt.Errorf("expected %v channels, got %v",
×
1172
                                numChannels, num)
×
1173
                }
×
1174

1175
                return nil
×
1176
        }, DefaultTimeout)
1177

1178
        require.NoError(h, err, "timeout checking node's num of channels")
×
1179
}
1180

1181
// AssertChannelLocalBalance checks the local balance of the given channel is
1182
// expected. The channel found using the specified channel point is returned.
1183
func (h *HarnessTest) AssertChannelLocalBalance(hn *node.HarnessNode,
1184
        cp *lnrpc.ChannelPoint, balance int64) *lnrpc.Channel {
×
1185

×
1186
        var result *lnrpc.Channel
×
1187

×
1188
        // Get the funding point.
×
1189
        err := wait.NoError(func() error {
×
1190
                // Find the target channel first.
×
1191
                target, err := h.findChannel(hn, cp)
×
1192

×
1193
                // Exit early if the channel is not found.
×
1194
                if err != nil {
×
1195
                        return fmt.Errorf("check balance failed: %w", err)
×
1196
                }
×
1197

1198
                result = target
×
1199

×
1200
                // Check local balance.
×
1201
                if target.LocalBalance == balance {
×
1202
                        return nil
×
1203
                }
×
1204

1205
                return fmt.Errorf("balance is incorrect, got %v, expected %v",
×
1206
                        target.LocalBalance, balance)
×
1207
        }, DefaultTimeout)
1208

1209
        require.NoError(h, err, "timeout while checking for balance")
×
1210

×
1211
        return result
×
1212
}
1213

1214
// AssertChannelNumUpdates checks the num of updates is expected from the given
1215
// channel.
1216
func (h *HarnessTest) AssertChannelNumUpdates(hn *node.HarnessNode,
1217
        num uint64, cp *lnrpc.ChannelPoint) {
×
1218

×
1219
        old := int(hn.State.OpenChannel.NumUpdates)
×
1220

×
1221
        // Find the target channel first.
×
1222
        target, err := h.findChannel(hn, cp)
×
1223
        require.NoError(h, err, "unable to find channel")
×
1224

×
1225
        err = wait.NoError(func() error {
×
1226
                total := int(target.NumUpdates)
×
1227
                if total-old == int(num) {
×
1228
                        return nil
×
1229
                }
×
1230

1231
                return errNumNotMatched(hn.Name(), "channel updates",
×
1232
                        int(num), total-old, total, old)
×
1233
        }, DefaultTimeout)
1234
        require.NoError(h, err, "timeout while checking for num of updates")
×
1235
}
1236

1237
// AssertNumActiveHtlcs asserts that a given number of HTLCs are seen in the
1238
// node's channels.
1239
func (h *HarnessTest) AssertNumActiveHtlcs(hn *node.HarnessNode, num int) {
×
1240
        old := hn.State.HTLC
×
1241

×
1242
        err := wait.NoError(func() error {
×
1243
                // pendingHTLCs is used to print unacked HTLCs, if found.
×
1244
                var pendingHTLCs []string
×
1245

×
1246
                // We require the RPC call to be succeeded and won't wait for
×
1247
                // it as it's an unexpected behavior.
×
1248
                req := &lnrpc.ListChannelsRequest{}
×
1249
                nodeChans := hn.RPC.ListChannels(req)
×
1250

×
1251
                total := 0
×
1252
                for _, channel := range nodeChans.Channels {
×
1253
                        for _, htlc := range channel.PendingHtlcs {
×
1254
                                if htlc.LockedIn {
×
1255
                                        total++
×
1256
                                }
×
1257

1258
                                rHash := fmt.Sprintf("%x", htlc.HashLock)
×
1259
                                pendingHTLCs = append(pendingHTLCs, rHash)
×
1260
                        }
1261
                }
1262
                if total-old != num {
×
1263
                        desc := fmt.Sprintf("active HTLCs: unacked HTLCs: %v",
×
1264
                                pendingHTLCs)
×
1265

×
1266
                        return errNumNotMatched(hn.Name(), desc,
×
1267
                                num, total-old, total, old)
×
1268
                }
×
1269

1270
                return nil
×
1271
        }, DefaultTimeout)
1272

1273
        require.NoErrorf(h, err, "%s timeout checking num active htlcs",
×
1274
                hn.Name())
×
1275
}
1276

1277
// AssertIncomingHTLCActive asserts the node has a pending incoming HTLC in the
1278
// given channel. Returns the HTLC if found and active.
1279
func (h *HarnessTest) AssertIncomingHTLCActive(hn *node.HarnessNode,
1280
        cp *lnrpc.ChannelPoint, payHash []byte) *lnrpc.HTLC {
×
1281

×
1282
        return h.assertHTLCActive(hn, cp, payHash, true)
×
1283
}
×
1284

1285
// AssertOutgoingHTLCActive asserts the node has a pending outgoing HTLC in the
1286
// given channel. Returns the HTLC if found and active.
1287
func (h *HarnessTest) AssertOutgoingHTLCActive(hn *node.HarnessNode,
1288
        cp *lnrpc.ChannelPoint, payHash []byte) *lnrpc.HTLC {
×
1289

×
1290
        return h.assertHTLCActive(hn, cp, payHash, false)
×
1291
}
×
1292

1293
// assertHLTCActive asserts the node has a pending HTLC in the given channel.
1294
// Returns the HTLC if found and active.
1295
func (h *HarnessTest) assertHTLCActive(hn *node.HarnessNode,
1296
        cp *lnrpc.ChannelPoint, payHash []byte, incoming bool) *lnrpc.HTLC {
×
1297

×
1298
        var result *lnrpc.HTLC
×
1299
        target := hex.EncodeToString(payHash)
×
1300

×
1301
        err := wait.NoError(func() error {
×
1302
                // We require the RPC call to be succeeded and won't wait for
×
1303
                // it as it's an unexpected behavior.
×
1304
                ch := h.GetChannelByChanPoint(hn, cp)
×
1305

×
1306
                // Check all payment hashes active for this channel.
×
1307
                for _, htlc := range ch.PendingHtlcs {
×
1308
                        rHash := hex.EncodeToString(htlc.HashLock)
×
1309
                        if rHash != target {
×
1310
                                continue
×
1311
                        }
1312

1313
                        // If the payment hash is found, check the incoming
1314
                        // field.
1315
                        if htlc.Incoming == incoming {
×
1316
                                // Return the result if it's locked in.
×
1317
                                if htlc.LockedIn {
×
1318
                                        result = htlc
×
1319
                                        return nil
×
1320
                                }
×
1321

1322
                                return fmt.Errorf("htlc(%x) not locked in",
×
1323
                                        payHash)
×
1324
                        }
1325

1326
                        // Otherwise we do have the HTLC but its direction is
1327
                        // not right.
1328
                        have, want := "outgoing", "incoming"
×
1329
                        if htlc.Incoming {
×
1330
                                have, want = "incoming", "outgoing"
×
1331
                        }
×
1332

1333
                        return fmt.Errorf("htlc(%x) has wrong direction - "+
×
1334
                                "want: %s, have: %s", payHash, want, have)
×
1335
                }
1336

1337
                return fmt.Errorf("htlc not found using payHash %x", payHash)
×
1338
        }, DefaultTimeout)
1339
        require.NoError(h, err, "%s: timeout checking pending HTLC", hn.Name())
×
1340

×
1341
        return result
×
1342
}
1343

1344
// AssertHLTCNotActive asserts the node doesn't have a pending HTLC in the
1345
// given channel, which mean either the HTLC never exists, or it was pending
1346
// and now settled. Returns the HTLC if found and active.
1347
//
1348
// NOTE: to check a pending HTLC becoming settled, first use AssertHLTCActive
1349
// then follow this check.
1350
func (h *HarnessTest) AssertHTLCNotActive(hn *node.HarnessNode,
1351
        cp *lnrpc.ChannelPoint, payHash []byte) *lnrpc.HTLC {
×
1352

×
1353
        var result *lnrpc.HTLC
×
1354
        target := hex.EncodeToString(payHash)
×
1355

×
1356
        err := wait.NoError(func() error {
×
1357
                // We require the RPC call to be succeeded and won't wait for
×
1358
                // it as it's an unexpected behavior.
×
1359
                ch := h.GetChannelByChanPoint(hn, cp)
×
1360

×
1361
                // Check all payment hashes active for this channel.
×
1362
                for _, htlc := range ch.PendingHtlcs {
×
1363
                        h := hex.EncodeToString(htlc.HashLock)
×
1364

×
1365
                        // Break if found the htlc.
×
1366
                        if h == target {
×
1367
                                result = htlc
×
1368
                                break
×
1369
                        }
1370
                }
1371

1372
                // If we've found nothing, we're done.
1373
                if result == nil {
×
1374
                        return nil
×
1375
                }
×
1376

1377
                // Otherwise return an error.
1378
                return fmt.Errorf("node [%s:%x] still has: the payHash %x",
×
1379
                        hn.Name(), hn.PubKey[:], payHash)
×
1380
        }, DefaultTimeout)
1381
        require.NoError(h, err, "timeout checking pending HTLC")
×
1382

×
1383
        return result
×
1384
}
1385

1386
// ReceiveSingleInvoice waits until a message is received on the subscribe
1387
// single invoice stream or the timeout is reached.
1388
func (h *HarnessTest) ReceiveSingleInvoice(
1389
        stream rpc.SingleInvoiceClient) *lnrpc.Invoice {
×
1390

×
1391
        chanMsg := make(chan *lnrpc.Invoice, 1)
×
1392
        errChan := make(chan error, 1)
×
1393
        go func() {
×
1394
                // Consume one message. This will block until the message is
×
1395
                // received.
×
1396
                resp, err := stream.Recv()
×
1397
                if err != nil {
×
1398
                        errChan <- err
×
1399

×
1400
                        return
×
1401
                }
×
1402
                chanMsg <- resp
×
1403
        }()
1404

1405
        select {
×
1406
        case <-time.After(DefaultTimeout):
×
1407
                require.Fail(h, "timeout", "timeout receiving single invoice")
×
1408

1409
        case err := <-errChan:
×
1410
                require.Failf(h, "err from stream",
×
1411
                        "received err from stream: %v", err)
×
1412

1413
        case updateMsg := <-chanMsg:
×
1414
                return updateMsg
×
1415
        }
1416

1417
        return nil
×
1418
}
1419

1420
// AssertInvoiceState takes a single invoice subscription stream and asserts
1421
// that a given invoice has became the desired state before timeout and returns
1422
// the invoice found.
1423
func (h *HarnessTest) AssertInvoiceState(stream rpc.SingleInvoiceClient,
1424
        state lnrpc.Invoice_InvoiceState) *lnrpc.Invoice {
×
1425

×
1426
        var invoice *lnrpc.Invoice
×
1427

×
1428
        err := wait.NoError(func() error {
×
1429
                invoice = h.ReceiveSingleInvoice(stream)
×
1430
                if invoice.State == state {
×
1431
                        return nil
×
1432
                }
×
1433

1434
                return fmt.Errorf("mismatched invoice state, want %v, got %v",
×
1435
                        state, invoice.State)
×
1436
        }, DefaultTimeout)
1437
        require.NoError(h, err, "timeout waiting for invoice state: %v", state)
×
1438

×
1439
        return invoice
×
1440
}
1441

1442
// assertAllTxesSpendFrom asserts that all txes in the list spend from the
1443
// given tx.
1444
func (h *HarnessTest) AssertAllTxesSpendFrom(txes []*wire.MsgTx,
1445
        prevTxid chainhash.Hash) {
×
1446

×
1447
        for _, tx := range txes {
×
1448
                if tx.TxIn[0].PreviousOutPoint.Hash != prevTxid {
×
1449
                        require.Failf(h, "", "tx %v did not spend from %v",
×
1450
                                tx.TxHash(), prevTxid)
×
1451
                }
×
1452
        }
1453
}
1454

1455
// AssertTxSpendFrom asserts that a given tx is spent from a previous tx.
1456
func (h *HarnessTest) AssertTxSpendFrom(tx *wire.MsgTx,
1457
        prevTxid chainhash.Hash) {
×
1458

×
1459
        if tx.TxIn[0].PreviousOutPoint.Hash != prevTxid {
×
1460
                require.Failf(h, "", "tx %v did not spend from %v",
×
1461
                        tx.TxHash(), prevTxid)
×
1462
        }
×
1463
}
1464

1465
type PendingForceClose *lnrpc.PendingChannelsResponse_ForceClosedChannel
1466

1467
// AssertChannelPendingForceClose asserts that the given channel found in the
1468
// node is pending force close. Returns the PendingForceClose if found.
1469
func (h *HarnessTest) AssertChannelPendingForceClose(hn *node.HarnessNode,
1470
        chanPoint *lnrpc.ChannelPoint) PendingForceClose {
×
1471

×
1472
        var target PendingForceClose
×
1473

×
1474
        op := h.OutPointFromChannelPoint(chanPoint)
×
1475

×
1476
        err := wait.NoError(func() error {
×
1477
                resp := hn.RPC.PendingChannels()
×
1478

×
1479
                forceCloseChans := resp.PendingForceClosingChannels
×
1480
                for _, ch := range forceCloseChans {
×
1481
                        if ch.Channel.ChannelPoint == op.String() {
×
1482
                                target = ch
×
1483

×
1484
                                return nil
×
1485
                        }
×
1486
                }
1487

1488
                return fmt.Errorf("%v: channel %s not found in pending "+
×
1489
                        "force close", hn.Name(), chanPoint)
×
1490
        }, DefaultTimeout)
1491
        require.NoError(h, err, "assert pending force close timed out")
×
1492

×
1493
        return target
×
1494
}
1495

1496
// AssertNumHTLCsAndStage takes a pending force close channel's channel point
1497
// and asserts the expected number of pending HTLCs and HTLC stage are matched.
1498
func (h *HarnessTest) AssertNumHTLCsAndStage(hn *node.HarnessNode,
1499
        chanPoint *lnrpc.ChannelPoint, num int, stage uint32) {
×
1500

×
1501
        // Get the channel output point.
×
1502
        cp := h.OutPointFromChannelPoint(chanPoint)
×
1503

×
1504
        var target PendingForceClose
×
1505
        checkStage := func() error {
×
1506
                resp := hn.RPC.PendingChannels()
×
1507
                if len(resp.PendingForceClosingChannels) == 0 {
×
1508
                        return fmt.Errorf("zero pending force closing channels")
×
1509
                }
×
1510

1511
                for _, ch := range resp.PendingForceClosingChannels {
×
1512
                        if ch.Channel.ChannelPoint == cp.String() {
×
1513
                                target = ch
×
1514

×
1515
                                break
×
1516
                        }
1517
                }
1518

1519
                if target == nil {
×
1520
                        return fmt.Errorf("cannot find pending force closing "+
×
1521
                                "channel using %v", cp)
×
1522
                }
×
1523

1524
                if target.LimboBalance == 0 {
×
1525
                        return fmt.Errorf("zero limbo balance")
×
1526
                }
×
1527

1528
                if len(target.PendingHtlcs) != num {
×
1529
                        return fmt.Errorf("got %d pending htlcs, want %d, %s",
×
1530
                                len(target.PendingHtlcs), num,
×
1531
                                lnutils.SpewLogClosure(target.PendingHtlcs)())
×
1532
                }
×
1533

1534
                for _, htlc := range target.PendingHtlcs {
×
1535
                        if htlc.Stage == stage {
×
1536
                                continue
×
1537
                        }
1538

1539
                        return fmt.Errorf("HTLC %s got stage: %v, "+
×
1540
                                "want stage: %v", htlc.Outpoint, htlc.Stage,
×
1541
                                stage)
×
1542
                }
1543

1544
                return nil
×
1545
        }
1546

1547
        require.NoErrorf(h, wait.NoError(checkStage, DefaultTimeout),
×
1548
                "timeout waiting for htlc stage")
×
1549
}
1550

1551
// findPayment queries the payment from the node's ListPayments which matches
1552
// the specified preimage hash.
1553
func (h *HarnessTest) findPayment(hn *node.HarnessNode,
1554
        paymentHash string) (*lnrpc.Payment, error) {
×
1555

×
1556
        req := &lnrpc.ListPaymentsRequest{IncludeIncomplete: true}
×
1557
        paymentsResp := hn.RPC.ListPayments(req)
×
1558

×
1559
        for _, p := range paymentsResp.Payments {
×
1560
                if p.PaymentHash == paymentHash {
×
1561
                        return p, nil
×
1562
                }
×
1563
        }
1564

1565
        return nil, fmt.Errorf("payment %v cannot be found", paymentHash)
×
1566
}
1567

1568
// PaymentCheck is a function that checks a payment for a specific condition.
1569
type PaymentCheck func(*lnrpc.Payment) error
1570

1571
// AssertPaymentStatus asserts that the given node list a payment with the given
1572
// payment hash has the expected status. It also checks that the payment has the
1573
// expected preimage, which is empty when it's not settled and matches the given
1574
// preimage when it's succeeded.
1575
func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
1576
        payHash lntypes.Hash, status lnrpc.Payment_PaymentStatus,
1577
        checks ...PaymentCheck) *lnrpc.Payment {
×
1578

×
1579
        var target *lnrpc.Payment
×
1580

×
1581
        err := wait.NoError(func() error {
×
1582
                p, err := h.findPayment(hn, payHash.String())
×
1583
                if err != nil {
×
1584
                        return err
×
1585
                }
×
1586

1587
                if status == p.Status {
×
1588
                        target = p
×
1589
                        return nil
×
1590
                }
×
1591

1592
                return fmt.Errorf("payment: %v status not match, want %s "+
×
1593
                        "got %s", payHash, status, p.Status)
×
1594
        }, DefaultTimeout)
1595
        require.NoError(h, err, "timeout checking payment status")
×
1596

×
1597
        switch status {
×
1598
        // If this expected status is SUCCEEDED, we expect the final
1599
        // preimage.
1600
        case lnrpc.Payment_SUCCEEDED:
×
1601
                preimage, err := lntypes.MakePreimageFromStr(
×
1602
                        target.PaymentPreimage,
×
1603
                )
×
1604
                require.NoError(h, err, "fail to make preimage")
×
1605
                require.Equal(h, payHash, preimage.Hash(), "preimage not match")
×
1606

1607
        // Otherwise we expect an all-zero preimage.
1608
        default:
×
1609
                require.Equal(h, (lntypes.Preimage{}).String(),
×
1610
                        target.PaymentPreimage, "expected zero preimage")
×
1611
        }
1612

1613
        // Perform any additional checks on the payment.
1614
        for _, check := range checks {
×
1615
                require.NoError(h, check(target))
×
1616
        }
×
1617

1618
        return target
×
1619
}
1620

1621
// AssertPaymentFailureReason asserts that the given node lists a payment with
1622
// the given preimage which has the expected failure reason.
1623
func (h *HarnessTest) AssertPaymentFailureReason(
1624
        hn *node.HarnessNode, preimage lntypes.Preimage,
1625
        reason lnrpc.PaymentFailureReason) *lnrpc.Payment {
×
1626

×
1627
        var payment *lnrpc.Payment
×
1628

×
1629
        payHash := preimage.Hash()
×
1630
        err := wait.NoError(func() error {
×
1631
                p, err := h.findPayment(hn, payHash.String())
×
1632
                if err != nil {
×
1633
                        return err
×
1634
                }
×
1635

1636
                payment = p
×
1637

×
1638
                if reason == p.FailureReason {
×
1639
                        return nil
×
1640
                }
×
1641

1642
                return fmt.Errorf("payment: %v failure reason not match, "+
×
1643
                        "want %s(%d) got %s(%d)", payHash, reason, reason,
×
1644
                        p.FailureReason, p.FailureReason)
×
1645
        }, DefaultTimeout)
1646
        require.NoError(h, err, "timeout checking payment failure reason")
×
1647

×
1648
        return payment
×
1649
}
1650

1651
// AssertActiveNodesSynced asserts all active nodes have synced to the chain.
1652
func (h *HarnessTest) AssertActiveNodesSynced() {
×
1653
        for _, node := range h.manager.activeNodes {
×
1654
                h.WaitForBlockchainSync(node)
×
1655
        }
×
1656
}
1657

1658
// AssertActiveNodesSyncedTo asserts all active nodes have synced to the
1659
// provided bestBlock.
1660
func (h *HarnessTest) AssertActiveNodesSyncedTo(bestBlock chainhash.Hash) {
×
1661
        for _, node := range h.manager.activeNodes {
×
1662
                h.WaitForBlockchainSyncTo(node, bestBlock)
×
1663
        }
×
1664
}
1665

1666
// AssertPeerNotConnected asserts that the given node b is not connected to a.
1667
func (h *HarnessTest) AssertPeerNotConnected(a, b *node.HarnessNode) {
×
1668
        err := wait.NoError(func() error {
×
1669
                // We require the RPC call to be succeeded and won't wait for
×
1670
                // it as it's an unexpected behavior.
×
1671
                resp := a.RPC.ListPeers()
×
1672

×
1673
                // If node B is seen in the ListPeers response from node A,
×
1674
                // then we return false as the connection has been fully
×
1675
                // established.
×
1676
                for _, peer := range resp.Peers {
×
1677
                        if peer.PubKey == b.PubKeyStr {
×
1678
                                return fmt.Errorf("peers %s and %s still "+
×
1679
                                        "connected", a.Name(), b.Name())
×
1680
                        }
×
1681
                }
1682

1683
                return nil
×
1684
        }, DefaultTimeout)
1685
        require.NoError(h, err, "timeout checking peers not connected")
×
1686
}
1687

1688
// AssertNotConnected asserts that two peers are not connected.
1689
func (h *HarnessTest) AssertNotConnected(a, b *node.HarnessNode) {
×
1690
        h.AssertPeerNotConnected(a, b)
×
1691
        h.AssertPeerNotConnected(b, a)
×
1692
}
×
1693

1694
// AssertConnected asserts that two peers are connected.
1695
func (h *HarnessTest) AssertConnected(a, b *node.HarnessNode) {
×
1696
        h.AssertPeerConnected(a, b)
×
1697
        h.AssertPeerConnected(b, a)
×
1698
}
×
1699

1700
// AssertAmountPaid checks that the ListChannels command of the provided
1701
// node list the total amount sent and received as expected for the
1702
// provided channel.
1703
func (h *HarnessTest) AssertAmountPaid(channelName string, hn *node.HarnessNode,
1704
        chanPoint *lnrpc.ChannelPoint, amountSent, amountReceived int64) {
×
1705

×
1706
        checkAmountPaid := func() error {
×
1707
                // Find the targeted channel.
×
1708
                channel, err := h.findChannel(hn, chanPoint)
×
1709
                if err != nil {
×
1710
                        return fmt.Errorf("assert amount failed: %w", err)
×
1711
                }
×
1712

1713
                if channel.TotalSatoshisSent != amountSent {
×
1714
                        return fmt.Errorf("%v: incorrect amount"+
×
1715
                                " sent: %v != %v", channelName,
×
1716
                                channel.TotalSatoshisSent,
×
1717
                                amountSent)
×
1718
                }
×
1719
                if channel.TotalSatoshisReceived !=
×
1720
                        amountReceived {
×
1721

×
1722
                        return fmt.Errorf("%v: incorrect amount"+
×
1723
                                " received: %v != %v",
×
1724
                                channelName,
×
1725
                                channel.TotalSatoshisReceived,
×
1726
                                amountReceived)
×
1727
                }
×
1728

1729
                return nil
×
1730
        }
1731

1732
        // As far as HTLC inclusion in commitment transaction might be
1733
        // postponed we will try to check the balance couple of times,
1734
        // and then if after some period of time we receive wrong
1735
        // balance return the error.
1736
        err := wait.NoError(checkAmountPaid, DefaultTimeout)
×
1737
        require.NoError(h, err, "timeout while checking amount paid")
×
1738
}
1739

1740
// AssertLastHTLCError checks that the last sent HTLC of the last payment sent
1741
// by the given node failed with the expected failure code.
1742
func (h *HarnessTest) AssertLastHTLCError(hn *node.HarnessNode,
1743
        code lnrpc.Failure_FailureCode) {
×
1744

×
1745
        // Use -1 to specify the last HTLC.
×
1746
        h.assertHTLCError(hn, code, -1)
×
1747
}
×
1748

1749
// AssertFirstHTLCError checks that the first HTLC of the last payment sent
1750
// by the given node failed with the expected failure code.
1751
func (h *HarnessTest) AssertFirstHTLCError(hn *node.HarnessNode,
1752
        code lnrpc.Failure_FailureCode) {
×
1753

×
1754
        // Use 0 to specify the first HTLC.
×
1755
        h.assertHTLCError(hn, code, 0)
×
1756
}
×
1757

1758
// assertLastHTLCError checks that the HTLC at the specified index of the last
1759
// payment sent by the given node failed with the expected failure code.
1760
func (h *HarnessTest) assertHTLCError(hn *node.HarnessNode,
1761
        code lnrpc.Failure_FailureCode, index int) {
×
1762

×
1763
        req := &lnrpc.ListPaymentsRequest{
×
1764
                IncludeIncomplete: true,
×
1765
        }
×
1766

×
1767
        err := wait.NoError(func() error {
×
1768
                paymentsResp := hn.RPC.ListPayments(req)
×
1769

×
1770
                payments := paymentsResp.Payments
×
1771
                if len(payments) == 0 {
×
1772
                        return fmt.Errorf("no payments found")
×
1773
                }
×
1774

1775
                payment := payments[len(payments)-1]
×
1776
                htlcs := payment.Htlcs
×
1777
                if len(htlcs) == 0 {
×
1778
                        return fmt.Errorf("no htlcs found")
×
1779
                }
×
1780

1781
                // If the index is greater than 0, check we have enough htlcs.
1782
                if index > 0 && len(htlcs) <= index {
×
1783
                        return fmt.Errorf("not enough htlcs")
×
1784
                }
×
1785

1786
                // If index is less than or equal to 0, we will read the last
1787
                // htlc.
1788
                if index <= 0 {
×
1789
                        index = len(htlcs) - 1
×
1790
                }
×
1791

1792
                htlc := htlcs[index]
×
1793

×
1794
                // The htlc must have a status of failed.
×
1795
                if htlc.Status != lnrpc.HTLCAttempt_FAILED {
×
1796
                        return fmt.Errorf("htlc should be failed")
×
1797
                }
×
1798
                // The failure field must not be empty.
1799
                if htlc.Failure == nil {
×
1800
                        return fmt.Errorf("expected htlc failure")
×
1801
                }
×
1802

1803
                // Exit if the expected code is found.
1804
                if htlc.Failure.Code == code {
×
1805
                        return nil
×
1806
                }
×
1807

1808
                return fmt.Errorf("unexpected failure code")
×
1809
        }, DefaultTimeout)
1810

1811
        require.NoError(h, err, "timeout checking HTLC error")
×
1812
}
1813

1814
// AssertZombieChannel asserts that a given channel found using the chanID is
1815
// marked as zombie.
1816
func (h *HarnessTest) AssertZombieChannel(hn *node.HarnessNode, chanID uint64) {
×
1817
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
1818
        defer cancel()
×
1819

×
1820
        err := wait.NoError(func() error {
×
1821
                _, err := hn.RPC.LN.GetChanInfo(
×
1822
                        ctxt, &lnrpc.ChanInfoRequest{ChanId: chanID},
×
1823
                )
×
1824
                if err == nil {
×
1825
                        return fmt.Errorf("expected error but got nil")
×
1826
                }
×
1827

1828
                if !strings.Contains(err.Error(), "marked as zombie") {
×
1829
                        return fmt.Errorf("expected error to contain '%s' but "+
×
1830
                                "was '%v'", "marked as zombie", err)
×
1831
                }
×
1832

1833
                return nil
×
1834
        }, DefaultTimeout)
1835
        require.NoError(h, err, "timeout while checking zombie channel")
×
1836
}
1837

1838
// AssertNotInGraph asserts that a given channel is either not found at all in
1839
// the graph or that it has been marked as a zombie.
1840
func (h *HarnessTest) AssertNotInGraph(hn *node.HarnessNode, chanID uint64) {
×
1841
        ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
×
1842
        defer cancel()
×
1843

×
1844
        err := wait.NoError(func() error {
×
1845
                _, err := hn.RPC.LN.GetChanInfo(
×
1846
                        ctxt, &lnrpc.ChanInfoRequest{ChanId: chanID},
×
1847
                )
×
1848
                if err == nil {
×
1849
                        return fmt.Errorf("expected error but got nil")
×
1850
                }
×
1851

1852
                switch {
×
1853
                case strings.Contains(err.Error(), "marked as zombie"):
×
1854
                        return nil
×
1855

1856
                case strings.Contains(err.Error(), "edge not found"):
×
1857
                        return nil
×
1858

1859
                default:
×
1860
                        return fmt.Errorf("expected error to contain either "+
×
1861
                                "'%s' or '%s' but was: '%v'", "marked as i"+
×
1862
                                "zombie", "edge not found", err)
×
1863
                }
1864
        }, DefaultTimeout)
1865
        require.NoError(h, err, "timeout while checking that channel is not "+
×
1866
                "found in graph")
×
1867
}
1868

1869
// AssertChannelInGraphDB asserts that a given channel is found in the graph db.
1870
func (h *HarnessTest) AssertChannelInGraphDB(hn *node.HarnessNode,
1871
        chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
×
1872

×
1873
        ctxt, cancel := context.WithCancel(h.runCtx)
×
1874
        defer cancel()
×
1875

×
1876
        var edge *lnrpc.ChannelEdge
×
1877

×
1878
        op := h.OutPointFromChannelPoint(chanPoint)
×
1879
        err := wait.NoError(func() error {
×
1880
                resp, err := hn.RPC.LN.GetChanInfo(
×
1881
                        ctxt, &lnrpc.ChanInfoRequest{
×
1882
                                ChanPoint: op.String(),
×
1883
                        },
×
1884
                )
×
1885
                if err != nil {
×
1886
                        return fmt.Errorf("channel %s not found in graph: %w",
×
1887
                                op, err)
×
1888
                }
×
1889

1890
                // Make sure the policies are populated, otherwise this edge
1891
                // cannot be used for routing.
1892
                if resp.Node1Policy == nil {
×
1893
                        return fmt.Errorf("channel %s has no policy1", op)
×
1894
                }
×
1895

1896
                if resp.Node2Policy == nil {
×
1897
                        return fmt.Errorf("channel %s has no policy2", op)
×
1898
                }
×
1899

1900
                edge = resp
×
1901

×
1902
                return nil
×
1903
        }, DefaultTimeout)
1904

1905
        require.NoError(h, err, "%s: timeout finding channel in graph",
×
1906
                hn.Name())
×
1907

×
1908
        return edge
×
1909
}
1910

1911
// AssertChannelInGraphCache asserts a given channel is found in the graph
1912
// cache.
1913
func (h *HarnessTest) AssertChannelInGraphCache(hn *node.HarnessNode,
1914
        chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
×
1915

×
1916
        var edge *lnrpc.ChannelEdge
×
1917

×
1918
        req := &lnrpc.ChannelGraphRequest{IncludeUnannounced: true}
×
1919
        cpStr := channelPointStr(chanPoint)
×
1920

×
1921
        err := wait.NoError(func() error {
×
1922
                chanGraph := hn.RPC.DescribeGraph(req)
×
1923

×
1924
                // Iterate all the known edges, and make sure the edge policies
×
1925
                // are populated when a matched edge is found.
×
1926
                for _, e := range chanGraph.Edges {
×
1927
                        if e.ChanPoint != cpStr {
×
1928
                                continue
×
1929
                        }
1930

1931
                        if e.Node1Policy == nil {
×
1932
                                return fmt.Errorf("no policy for node1 %v",
×
1933
                                        e.Node1Pub)
×
1934
                        }
×
1935

1936
                        if e.Node2Policy == nil {
×
1937
                                return fmt.Errorf("no policy for node2 %v",
×
1938
                                        e.Node1Pub)
×
1939
                        }
×
1940

1941
                        edge = e
×
1942

×
1943
                        return nil
×
1944
                }
1945

1946
                // If we've iterated over all the known edges and we weren't
1947
                // able to find this specific one, then we'll fail.
1948
                return fmt.Errorf("no edge found for channel point: %s", cpStr)
×
1949
        }, DefaultTimeout)
1950

1951
        require.NoError(h, err, "%s: timeout finding channel %v in graph cache",
×
1952
                cpStr, hn.Name())
×
1953

×
1954
        return edge
×
1955
}
1956

1957
// AssertChannelInGraphDB asserts that a given channel is found both in the
1958
// graph db (GetChanInfo) and the graph cache (DescribeGraph).
1959
func (h *HarnessTest) AssertChannelInGraph(hn *node.HarnessNode,
1960
        chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
×
1961

×
1962
        // Make sure the channel is found in the db first.
×
1963
        h.AssertChannelInGraphDB(hn, chanPoint)
×
1964

×
1965
        // Assert the channel is also found in the graph cache, which refreshes
×
1966
        // every `--caches.rpc-graph-cache-duration`.
×
1967
        return h.AssertChannelInGraphCache(hn, chanPoint)
×
1968
}
×
1969

1970
// AssertTxAtHeight gets all of the transactions that a node's wallet has a
1971
// record of at the target height, and finds and returns the tx with the target
1972
// txid, failing if it is not found.
1973
func (h *HarnessTest) AssertTxAtHeight(hn *node.HarnessNode, height int32,
1974
        txid *chainhash.Hash) *lnrpc.Transaction {
×
1975

×
1976
        req := &lnrpc.GetTransactionsRequest{
×
1977
                StartHeight: height,
×
1978
                EndHeight:   height,
×
1979
        }
×
1980
        txns := hn.RPC.GetTransactions(req)
×
1981

×
1982
        for _, tx := range txns.Transactions {
×
1983
                if tx.TxHash == txid.String() {
×
1984
                        return tx
×
1985
                }
×
1986
        }
1987

1988
        require.Failf(h, "fail to find tx", "tx:%v not found at height:%v",
×
1989
                txid, height)
×
1990

×
1991
        return nil
×
1992
}
1993

1994
// getChannelPolicies queries the channel graph and retrieves the current edge
1995
// policies for the provided channel point.
1996
func (h *HarnessTest) getChannelPolicies(hn *node.HarnessNode,
1997
        advertisingNode string,
1998
        cp *lnrpc.ChannelPoint) (*lnrpc.RoutingPolicy, error) {
×
1999

×
2000
        req := &lnrpc.ChannelGraphRequest{IncludeUnannounced: true}
×
2001
        chanGraph := hn.RPC.DescribeGraph(req)
×
2002

×
2003
        cpStr := channelPointStr(cp)
×
2004
        for _, e := range chanGraph.Edges {
×
2005
                if e.ChanPoint != cpStr {
×
2006
                        continue
×
2007
                }
2008

2009
                if e.Node1Pub == advertisingNode {
×
2010
                        return e.Node1Policy, nil
×
2011
                }
×
2012

2013
                return e.Node2Policy, nil
×
2014
        }
2015

2016
        // If we've iterated over all the known edges and we weren't
2017
        // able to find this specific one, then we'll fail.
2018
        return nil, fmt.Errorf("did not find edge with advertisingNode: %s"+
×
2019
                ", channel point: %s", advertisingNode, cpStr)
×
2020
}
2021

2022
// AssertChannelPolicy asserts that the passed node's known channel policy for
2023
// the passed chanPoint is consistent with the expected policy values.
2024
func (h *HarnessTest) AssertChannelPolicy(hn *node.HarnessNode,
2025
        advertisingNode string, expectedPolicy *lnrpc.RoutingPolicy,
2026
        chanPoint *lnrpc.ChannelPoint) {
×
2027

×
2028
        policy, err := h.getChannelPolicies(hn, advertisingNode, chanPoint)
×
2029
        require.NoErrorf(h, err, "%s: failed to find policy", hn.Name())
×
2030

×
2031
        err = node.CheckChannelPolicy(policy, expectedPolicy)
×
2032
        require.NoErrorf(h, err, "%s: check policy failed", hn.Name())
×
2033
}
×
2034

2035
// AssertNumPolicyUpdates asserts that a given number of channel policy updates
2036
// has been seen in the specified node.
2037
func (h *HarnessTest) AssertNumPolicyUpdates(hn *node.HarnessNode,
2038
        chanPoint *lnrpc.ChannelPoint,
2039
        advertisingNode *node.HarnessNode, num int) {
×
2040

×
2041
        op := h.OutPointFromChannelPoint(chanPoint)
×
2042

×
2043
        var policies []*node.PolicyUpdateInfo
×
2044

×
2045
        err := wait.NoError(func() error {
×
2046
                policyMap := hn.Watcher.GetPolicyUpdates(op)
×
2047
                nodePolicy, ok := policyMap[advertisingNode.PubKeyStr]
×
2048
                if ok {
×
2049
                        policies = nodePolicy
×
2050
                }
×
2051

2052
                if len(policies) == num {
×
2053
                        return nil
×
2054
                }
×
2055

2056
                p, err := json.MarshalIndent(policies, "", "\t")
×
2057
                require.NoError(h, err, "encode policy err")
×
2058

×
2059
                return fmt.Errorf("expected to find %d policy updates, "+
×
2060
                        "instead got: %d, chanPoint: %v, "+
×
2061
                        "advertisingNode: %s:%s, policy: %s", num,
×
2062
                        len(policies), op, advertisingNode.Name(),
×
2063
                        advertisingNode.PubKeyStr, p)
×
2064
        }, DefaultTimeout)
2065

2066
        require.NoError(h, err, "%s: timeout waiting for num of policy updates",
×
2067
                hn.Name())
×
2068
}
2069

2070
// AssertNumPayments asserts that the number of payments made within the test
2071
// scope is as expected, including the incomplete ones.
2072
func (h *HarnessTest) AssertNumPayments(hn *node.HarnessNode,
2073
        num int) []*lnrpc.Payment {
×
2074

×
2075
        // Get the number of payments we already have from the previous test.
×
2076
        have := hn.State.Payment.Total
×
2077

×
2078
        req := &lnrpc.ListPaymentsRequest{
×
2079
                IncludeIncomplete: true,
×
2080
                IndexOffset:       hn.State.Payment.LastIndexOffset,
×
2081
        }
×
2082

×
2083
        var payments []*lnrpc.Payment
×
2084
        err := wait.NoError(func() error {
×
2085
                resp := hn.RPC.ListPayments(req)
×
2086

×
2087
                payments = resp.Payments
×
2088
                if len(payments) == num {
×
2089
                        return nil
×
2090
                }
×
2091

2092
                return errNumNotMatched(hn.Name(), "num of payments",
×
2093
                        num, len(payments), have+len(payments), have)
×
2094
        }, DefaultTimeout)
2095
        require.NoError(h, err, "%s: timeout checking num of payments",
×
2096
                hn.Name())
×
2097

×
2098
        return payments
×
2099
}
2100

2101
// AssertNumNodeAnns asserts that a given number of node announcements has been
2102
// seen in the specified node.
2103
func (h *HarnessTest) AssertNumNodeAnns(hn *node.HarnessNode,
2104
        pubkey string, num int) []*lnrpc.NodeUpdate {
×
2105

×
2106
        // We will get the current number of channel updates first and add it
×
2107
        // to our expected number of newly created channel updates.
×
2108
        anns, err := hn.Watcher.WaitForNumNodeUpdates(pubkey, num)
×
2109
        require.NoError(h, err, "%s: failed to assert num of node anns",
×
2110
                hn.Name())
×
2111

×
2112
        return anns
×
2113
}
×
2114

2115
// AssertNumChannelUpdates asserts that a given number of channel updates has
2116
// been seen in the specified node's network topology.
2117
func (h *HarnessTest) AssertNumChannelUpdates(hn *node.HarnessNode,
2118
        chanPoint *lnrpc.ChannelPoint, num int) {
×
2119

×
2120
        op := h.OutPointFromChannelPoint(chanPoint)
×
2121
        err := hn.Watcher.WaitForNumChannelUpdates(op, num)
×
2122
        require.NoError(h, err, "%s: failed to assert num of channel updates",
×
2123
                hn.Name())
×
2124
}
×
2125

2126
// CreateBurnAddr creates a random burn address of the given type.
2127
func (h *HarnessTest) CreateBurnAddr(addrType lnrpc.AddressType) ([]byte,
2128
        btcutil.Address) {
×
2129

×
2130
        randomPrivKey, err := btcec.NewPrivateKey()
×
2131
        require.NoError(h, err)
×
2132

×
2133
        randomKeyBytes := randomPrivKey.PubKey().SerializeCompressed()
×
2134
        harnessNetParams := miner.HarnessNetParams
×
2135

×
2136
        var addr btcutil.Address
×
2137
        switch addrType {
×
2138
        case lnrpc.AddressType_WITNESS_PUBKEY_HASH:
×
2139
                addr, err = btcutil.NewAddressWitnessPubKeyHash(
×
2140
                        btcutil.Hash160(randomKeyBytes), harnessNetParams,
×
2141
                )
×
2142

2143
        case lnrpc.AddressType_TAPROOT_PUBKEY:
×
2144
                taprootKey := txscript.ComputeTaprootKeyNoScript(
×
2145
                        randomPrivKey.PubKey(),
×
2146
                )
×
2147
                addr, err = btcutil.NewAddressPubKey(
×
2148
                        schnorr.SerializePubKey(taprootKey), harnessNetParams,
×
2149
                )
×
2150

2151
        case lnrpc.AddressType_NESTED_PUBKEY_HASH:
×
2152
                var witnessAddr btcutil.Address
×
2153
                witnessAddr, err = btcutil.NewAddressWitnessPubKeyHash(
×
2154
                        btcutil.Hash160(randomKeyBytes), harnessNetParams,
×
2155
                )
×
2156
                require.NoError(h, err)
×
2157

×
2158
                addr, err = btcutil.NewAddressScriptHash(
×
2159
                        h.PayToAddrScript(witnessAddr), harnessNetParams,
×
2160
                )
×
2161

2162
        default:
×
2163
                h.Fatalf("Unsupported burn address type: %v", addrType)
×
2164
        }
2165
        require.NoError(h, err)
×
2166

×
2167
        return h.PayToAddrScript(addr), addr
×
2168
}
2169

2170
// ReceiveTrackPayment waits until a message is received on the track payment
2171
// stream or the timeout is reached.
2172
func (h *HarnessTest) ReceiveTrackPayment(
2173
        stream rpc.TrackPaymentClient) *lnrpc.Payment {
×
2174

×
2175
        chanMsg := make(chan *lnrpc.Payment)
×
2176
        errChan := make(chan error)
×
2177
        go func() {
×
2178
                // Consume one message. This will block until the message is
×
2179
                // received.
×
2180
                resp, err := stream.Recv()
×
2181
                if err != nil {
×
2182
                        errChan <- err
×
2183
                        return
×
2184
                }
×
2185
                chanMsg <- resp
×
2186
        }()
2187

2188
        select {
×
2189
        case <-time.After(DefaultTimeout):
×
2190
                require.Fail(h, "timeout", "timeout trakcing payment")
×
2191

2192
        case err := <-errChan:
×
2193
                require.Failf(h, "err from stream",
×
2194
                        "received err from stream: %v", err)
×
2195

2196
        case updateMsg := <-chanMsg:
×
2197
                return updateMsg
×
2198
        }
2199

2200
        return nil
×
2201
}
2202

2203
// ReceiveHtlcEvent waits until a message is received on the subscribe
2204
// htlc event stream or the timeout is reached.
2205
func (h *HarnessTest) ReceiveHtlcEvent(
2206
        stream rpc.HtlcEventsClient) *routerrpc.HtlcEvent {
×
2207

×
2208
        chanMsg := make(chan *routerrpc.HtlcEvent)
×
2209
        errChan := make(chan error)
×
2210
        go func() {
×
2211
                // Consume one message. This will block until the message is
×
2212
                // received.
×
2213
                resp, err := stream.Recv()
×
2214
                if err != nil {
×
2215
                        errChan <- err
×
2216
                        return
×
2217
                }
×
2218
                chanMsg <- resp
×
2219
        }()
2220

2221
        select {
×
2222
        case <-time.After(DefaultTimeout):
×
2223
                require.Fail(h, "timeout", "timeout receiving htlc "+
×
2224
                        "event update")
×
2225

2226
        case err := <-errChan:
×
2227
                require.Failf(h, "err from stream",
×
2228
                        "received err from stream: %v", err)
×
2229

2230
        case updateMsg := <-chanMsg:
×
2231
                return updateMsg
×
2232
        }
2233

2234
        return nil
×
2235
}
2236

2237
// AssertHtlcEventType consumes one event from a client and asserts the event
2238
// type is matched.
2239
func (h *HarnessTest) AssertHtlcEventType(client rpc.HtlcEventsClient,
2240
        userType routerrpc.HtlcEvent_EventType) *routerrpc.HtlcEvent {
×
2241

×
2242
        event := h.ReceiveHtlcEvent(client)
×
2243
        require.Equalf(h, userType, event.EventType, "wrong event type, "+
×
2244
                "want %v got %v", userType, event.EventType)
×
2245

×
2246
        return event
×
2247
}
×
2248

2249
// HtlcEvent maps the series of event types used in `*routerrpc.HtlcEvent_*`.
2250
type HtlcEvent int
2251

2252
const (
2253
        HtlcEventForward HtlcEvent = iota
2254
        HtlcEventForwardFail
2255
        HtlcEventSettle
2256
        HtlcEventLinkFail
2257
        HtlcEventFinal
2258
)
2259

2260
// AssertHtlcEventType consumes one event from a client and asserts both the
2261
// user event type the event.Event type is matched.
2262
func (h *HarnessTest) AssertHtlcEventTypes(client rpc.HtlcEventsClient,
2263
        userType routerrpc.HtlcEvent_EventType,
2264
        eventType HtlcEvent) *routerrpc.HtlcEvent {
×
2265

×
2266
        event := h.ReceiveHtlcEvent(client)
×
2267
        require.Equalf(h, userType, event.EventType, "wrong event type, "+
×
2268
                "want %v got %v", userType, event.EventType)
×
2269

×
2270
        var ok bool
×
2271

×
2272
        switch eventType {
×
2273
        case HtlcEventForward:
×
2274
                _, ok = event.Event.(*routerrpc.HtlcEvent_ForwardEvent)
×
2275

2276
        case HtlcEventForwardFail:
×
2277
                _, ok = event.Event.(*routerrpc.HtlcEvent_ForwardFailEvent)
×
2278

2279
        case HtlcEventSettle:
×
2280
                _, ok = event.Event.(*routerrpc.HtlcEvent_SettleEvent)
×
2281

2282
        case HtlcEventLinkFail:
×
2283
                _, ok = event.Event.(*routerrpc.HtlcEvent_LinkFailEvent)
×
2284

2285
        case HtlcEventFinal:
×
2286
                _, ok = event.Event.(*routerrpc.HtlcEvent_FinalHtlcEvent)
×
2287
        }
2288

2289
        require.Truef(h, ok, "wrong event type: %T, want %T", event.Event,
×
2290
                eventType)
×
2291

×
2292
        return event
×
2293
}
2294

2295
// AssertFeeReport checks that the fee report from the given node has the
2296
// desired day, week, and month sum values.
2297
func (h *HarnessTest) AssertFeeReport(hn *node.HarnessNode,
2298
        day, week, month int) {
×
2299

×
2300
        err := wait.NoError(func() error {
×
2301
                feeReport, err := hn.RPC.LN.FeeReport(
×
2302
                        h.runCtx, &lnrpc.FeeReportRequest{},
×
2303
                )
×
2304
                require.NoError(h, err, "unable to query for fee report")
×
2305

×
2306
                if uint64(day) != feeReport.DayFeeSum {
×
2307
                        return fmt.Errorf("day fee mismatch, want %d, got %d",
×
2308
                                day, feeReport.DayFeeSum)
×
2309
                }
×
2310

2311
                if uint64(week) != feeReport.WeekFeeSum {
×
2312
                        return fmt.Errorf("week fee mismatch, want %d, got %d",
×
2313
                                week, feeReport.WeekFeeSum)
×
2314
                }
×
2315
                if uint64(month) != feeReport.MonthFeeSum {
×
2316
                        return fmt.Errorf("month fee mismatch, want %d, got %d",
×
2317
                                month, feeReport.MonthFeeSum)
×
2318
                }
×
2319

2320
                return nil
×
2321
        }, wait.DefaultTimeout)
2322
        require.NoErrorf(h, err, "%s: time out checking fee report", hn.Name())
×
2323
}
2324

2325
// AssertHtlcEvents consumes events from a client and ensures that they are of
2326
// the expected type and contain the expected number of forwards, forward
2327
// failures and settles.
2328
//
2329
// TODO(yy): needs refactor to reduce its complexity.
2330
func (h *HarnessTest) AssertHtlcEvents(client rpc.HtlcEventsClient,
2331
        fwdCount, fwdFailCount, settleCount, linkFailCount int,
2332
        userType routerrpc.HtlcEvent_EventType) []*routerrpc.HtlcEvent {
×
2333

×
2334
        var forwards, forwardFails, settles, linkFails int
×
2335

×
2336
        numEvents := fwdCount + fwdFailCount + settleCount + linkFailCount
×
2337
        events := make([]*routerrpc.HtlcEvent, 0)
×
2338

×
2339
        // It's either the userType or the unknown type.
×
2340
        //
×
2341
        // TODO(yy): maybe the FinalHtlcEvent shouldn't be in UNKNOWN type?
×
2342
        eventTypes := []routerrpc.HtlcEvent_EventType{
×
2343
                userType, routerrpc.HtlcEvent_UNKNOWN,
×
2344
        }
×
2345

×
2346
        for i := 0; i < numEvents; i++ {
×
2347
                event := h.ReceiveHtlcEvent(client)
×
2348

×
2349
                require.Containsf(h, eventTypes, event.EventType,
×
2350
                        "wrong event type, want %v, got %v", userType,
×
2351
                        event.EventType)
×
2352

×
2353
                events = append(events, event)
×
2354

×
2355
                switch e := event.Event.(type) {
×
2356
                case *routerrpc.HtlcEvent_ForwardEvent:
×
2357
                        forwards++
×
2358

2359
                case *routerrpc.HtlcEvent_ForwardFailEvent:
×
2360
                        forwardFails++
×
2361

2362
                case *routerrpc.HtlcEvent_SettleEvent:
×
2363
                        settles++
×
2364

2365
                case *routerrpc.HtlcEvent_FinalHtlcEvent:
×
2366
                        if e.FinalHtlcEvent.Settled {
×
2367
                                settles++
×
2368
                        }
×
2369

2370
                case *routerrpc.HtlcEvent_LinkFailEvent:
×
2371
                        linkFails++
×
2372

2373
                default:
×
2374
                        require.Fail(h, "assert event fail",
×
2375
                                "unexpected event: %T", event.Event)
×
2376
                }
2377
        }
2378

2379
        require.Equal(h, fwdCount, forwards, "num of forwards mismatch")
×
2380
        require.Equal(h, fwdFailCount, forwardFails,
×
2381
                "num of forward fails mismatch")
×
2382
        require.Equal(h, settleCount, settles, "num of settles mismatch")
×
2383
        require.Equal(h, linkFailCount, linkFails, "num of link fails mismatch")
×
2384

×
2385
        return events
×
2386
}
2387

2388
// AssertTransactionInWallet asserts a given txid can be found in the node's
2389
// wallet.
2390
func (h *HarnessTest) AssertTransactionInWallet(hn *node.HarnessNode,
2391
        txid chainhash.Hash) {
×
2392

×
2393
        req := &lnrpc.GetTransactionsRequest{}
×
2394
        err := wait.NoError(func() error {
×
2395
                txResp := hn.RPC.GetTransactions(req)
×
2396
                for _, txn := range txResp.Transactions {
×
2397
                        if txn.TxHash == txid.String() {
×
2398
                                return nil
×
2399
                        }
×
2400
                }
2401

2402
                return fmt.Errorf("%s: expected txid=%v not found in wallet",
×
2403
                        hn.Name(), txid)
×
2404
        }, DefaultTimeout)
2405

2406
        require.NoError(h, err, "failed to find tx")
×
2407
}
2408

2409
// AssertTransactionNotInWallet asserts a given txid can NOT be found in the
2410
// node's wallet.
2411
func (h *HarnessTest) AssertTransactionNotInWallet(hn *node.HarnessNode,
2412
        txid chainhash.Hash) {
×
2413

×
2414
        req := &lnrpc.GetTransactionsRequest{}
×
2415
        err := wait.NoError(func() error {
×
2416
                txResp := hn.RPC.GetTransactions(req)
×
2417
                for _, txn := range txResp.Transactions {
×
2418
                        if txn.TxHash == txid.String() {
×
2419
                                return fmt.Errorf("expected txid=%v to be "+
×
2420
                                        "not found", txid)
×
2421
                        }
×
2422
                }
2423

2424
                return nil
×
2425
        }, DefaultTimeout)
2426

2427
        require.NoErrorf(h, err, "%s: failed to assert tx not found", hn.Name())
×
2428
}
2429

2430
// WaitForNodeBlockHeight queries the node for its current block height until
2431
// it reaches the passed height.
2432
func (h *HarnessTest) WaitForNodeBlockHeight(hn *node.HarnessNode,
2433
        height int32) {
×
2434

×
2435
        err := wait.NoError(func() error {
×
2436
                info := hn.RPC.GetInfo()
×
2437
                if int32(info.BlockHeight) != height {
×
2438
                        return fmt.Errorf("expected block height to "+
×
2439
                                "be %v, was %v", height, info.BlockHeight)
×
2440
                }
×
2441

2442
                return nil
×
2443
        }, DefaultTimeout)
2444

2445
        require.NoErrorf(h, err, "%s: timeout while waiting for height",
×
2446
                hn.Name())
×
2447
}
2448

2449
// AssertChannelCommitHeight asserts the given channel for the node has the
2450
// expected commit height(`NumUpdates`).
2451
func (h *HarnessTest) AssertChannelCommitHeight(hn *node.HarnessNode,
2452
        cp *lnrpc.ChannelPoint, height int) {
×
2453

×
2454
        err := wait.NoError(func() error {
×
2455
                c, err := h.findChannel(hn, cp)
×
2456
                if err != nil {
×
2457
                        return err
×
2458
                }
×
2459

2460
                if int(c.NumUpdates) == height {
×
2461
                        return nil
×
2462
                }
×
2463

2464
                return fmt.Errorf("expected commit height to be %v, was %v",
×
2465
                        height, c.NumUpdates)
×
2466
        }, DefaultTimeout)
2467

2468
        require.NoError(h, err, "timeout while waiting for commit height")
×
2469
}
2470

2471
// AssertNumInvoices asserts that the number of invoices made within the test
2472
// scope is as expected.
2473
func (h *HarnessTest) AssertNumInvoices(hn *node.HarnessNode,
2474
        num int) []*lnrpc.Invoice {
×
2475

×
2476
        have := hn.State.Invoice.Total
×
2477
        req := &lnrpc.ListInvoiceRequest{
×
2478
                NumMaxInvoices: math.MaxUint64,
×
2479
                IndexOffset:    hn.State.Invoice.LastIndexOffset,
×
2480
        }
×
2481

×
2482
        var invoices []*lnrpc.Invoice
×
2483
        err := wait.NoError(func() error {
×
2484
                resp := hn.RPC.ListInvoices(req)
×
2485

×
2486
                invoices = resp.Invoices
×
2487
                if len(invoices) == num {
×
2488
                        return nil
×
2489
                }
×
2490

2491
                return errNumNotMatched(hn.Name(), "num of invoices",
×
2492
                        num, len(invoices), have+len(invoices), have)
×
2493
        }, DefaultTimeout)
2494
        require.NoError(h, err, "timeout checking num of invoices")
×
2495

×
2496
        return invoices
×
2497
}
2498

2499
// ReceiveSendToRouteUpdate waits until a message is received on the
2500
// SendToRoute client stream or the timeout is reached.
2501
func (h *HarnessTest) ReceiveSendToRouteUpdate(
2502
        stream rpc.SendToRouteClient) (*lnrpc.SendResponse, error) {
×
2503

×
2504
        chanMsg := make(chan *lnrpc.SendResponse, 1)
×
2505
        errChan := make(chan error, 1)
×
2506
        go func() {
×
2507
                // Consume one message. This will block until the message is
×
2508
                // received.
×
2509
                resp, err := stream.Recv()
×
2510
                if err != nil {
×
2511
                        errChan <- err
×
2512

×
2513
                        return
×
2514
                }
×
2515
                chanMsg <- resp
×
2516
        }()
2517

2518
        select {
×
2519
        case <-time.After(DefaultTimeout):
×
2520
                require.Fail(h, "timeout", "timeout waiting for send resp")
×
2521
                return nil, nil
×
2522

2523
        case err := <-errChan:
×
2524
                return nil, err
×
2525

2526
        case updateMsg := <-chanMsg:
×
2527
                return updateMsg, nil
×
2528
        }
2529
}
2530

2531
// AssertInvoiceEqual asserts that two lnrpc.Invoices are equivalent. A custom
2532
// comparison function is defined for these tests, since proto message returned
2533
// from unary and streaming RPCs (as of protobuf 1.23.0 and grpc 1.29.1) aren't
2534
// consistent with the private fields set on the messages. As a result, we
2535
// avoid using require.Equal and test only the actual data members.
2536
func (h *HarnessTest) AssertInvoiceEqual(a, b *lnrpc.Invoice) {
×
2537
        // Ensure the HTLCs are sorted properly before attempting to compare.
×
2538
        sort.Slice(a.Htlcs, func(i, j int) bool {
×
2539
                return a.Htlcs[i].ChanId < a.Htlcs[j].ChanId
×
2540
        })
×
2541
        sort.Slice(b.Htlcs, func(i, j int) bool {
×
2542
                return b.Htlcs[i].ChanId < b.Htlcs[j].ChanId
×
2543
        })
×
2544

2545
        require.Equal(h, a.Memo, b.Memo)
×
2546
        require.Equal(h, a.RPreimage, b.RPreimage)
×
2547
        require.Equal(h, a.RHash, b.RHash)
×
2548
        require.Equal(h, a.Value, b.Value)
×
2549
        require.Equal(h, a.ValueMsat, b.ValueMsat)
×
2550
        require.Equal(h, a.CreationDate, b.CreationDate)
×
2551
        require.Equal(h, a.SettleDate, b.SettleDate)
×
2552
        require.Equal(h, a.PaymentRequest, b.PaymentRequest)
×
2553
        require.Equal(h, a.DescriptionHash, b.DescriptionHash)
×
2554
        require.Equal(h, a.Expiry, b.Expiry)
×
2555
        require.Equal(h, a.FallbackAddr, b.FallbackAddr)
×
2556
        require.Equal(h, a.CltvExpiry, b.CltvExpiry)
×
2557
        require.Equal(h, a.RouteHints, b.RouteHints)
×
2558
        require.Equal(h, a.Private, b.Private)
×
2559
        require.Equal(h, a.AddIndex, b.AddIndex)
×
2560
        require.Equal(h, a.SettleIndex, b.SettleIndex)
×
2561
        require.Equal(h, a.AmtPaidSat, b.AmtPaidSat)
×
2562
        require.Equal(h, a.AmtPaidMsat, b.AmtPaidMsat)
×
2563
        require.Equal(h, a.State, b.State)
×
2564
        require.Equal(h, a.Features, b.Features)
×
2565
        require.Equal(h, a.IsKeysend, b.IsKeysend)
×
2566
        require.Equal(h, a.PaymentAddr, b.PaymentAddr)
×
2567
        require.Equal(h, a.IsAmp, b.IsAmp)
×
2568

×
2569
        require.Equal(h, len(a.Htlcs), len(b.Htlcs))
×
2570
        for i := range a.Htlcs {
×
2571
                htlcA, htlcB := a.Htlcs[i], b.Htlcs[i]
×
2572
                require.Equal(h, htlcA.ChanId, htlcB.ChanId)
×
2573
                require.Equal(h, htlcA.HtlcIndex, htlcB.HtlcIndex)
×
2574
                require.Equal(h, htlcA.AmtMsat, htlcB.AmtMsat)
×
2575
                require.Equal(h, htlcA.AcceptHeight, htlcB.AcceptHeight)
×
2576
                require.Equal(h, htlcA.AcceptTime, htlcB.AcceptTime)
×
2577
                require.Equal(h, htlcA.ResolveTime, htlcB.ResolveTime)
×
2578
                require.Equal(h, htlcA.ExpiryHeight, htlcB.ExpiryHeight)
×
2579
                require.Equal(h, htlcA.State, htlcB.State)
×
2580
                require.Equal(h, htlcA.CustomRecords, htlcB.CustomRecords)
×
2581
                require.Equal(h, htlcA.MppTotalAmtMsat, htlcB.MppTotalAmtMsat)
×
2582
                require.Equal(h, htlcA.Amp, htlcB.Amp)
×
2583
        }
×
2584
}
2585

2586
// AssertUTXOInWallet asserts that a given UTXO can be found in the node's
2587
// wallet.
2588
func (h *HarnessTest) AssertUTXOInWallet(hn *node.HarnessNode,
2589
        op *lnrpc.OutPoint, account string) {
×
2590

×
2591
        err := wait.NoError(func() error {
×
2592
                utxos := h.GetUTXOs(hn, account)
×
2593

×
2594
                err := fmt.Errorf("tx with hash %x not found", op.TxidBytes)
×
2595
                for _, utxo := range utxos {
×
2596
                        if !bytes.Equal(utxo.Outpoint.TxidBytes, op.TxidBytes) {
×
2597
                                continue
×
2598
                        }
2599

2600
                        err = fmt.Errorf("tx with output index %v not found",
×
2601
                                op.OutputIndex)
×
2602
                        if utxo.Outpoint.OutputIndex != op.OutputIndex {
×
2603
                                continue
×
2604
                        }
2605

2606
                        return nil
×
2607
                }
2608

2609
                return err
×
2610
        }, DefaultTimeout)
2611

2612
        require.NoErrorf(h, err, "outpoint %v not found in %s's wallet",
×
2613
                op, hn.Name())
×
2614
}
2615

2616
// AssertWalletAccountBalance asserts that the unconfirmed and confirmed
2617
// balance for the given account is satisfied by the WalletBalance and
2618
// ListUnspent RPCs. The unconfirmed balance is not checked for neutrino nodes.
2619
func (h *HarnessTest) AssertWalletAccountBalance(hn *node.HarnessNode,
2620
        account string, confirmedBalance, unconfirmedBalance int64) {
×
2621

×
2622
        err := wait.NoError(func() error {
×
2623
                balanceResp := hn.RPC.WalletBalance()
×
2624
                require.Contains(h, balanceResp.AccountBalance, account)
×
2625
                accountBalance := balanceResp.AccountBalance[account]
×
2626

×
2627
                // Check confirmed balance.
×
2628
                if accountBalance.ConfirmedBalance != confirmedBalance {
×
2629
                        return fmt.Errorf("expected confirmed balance %v, "+
×
2630
                                "got %v", confirmedBalance,
×
2631
                                accountBalance.ConfirmedBalance)
×
2632
                }
×
2633

2634
                utxos := h.GetUTXOsConfirmed(hn, account)
×
2635
                var totalConfirmedVal int64
×
2636
                for _, utxo := range utxos {
×
2637
                        totalConfirmedVal += utxo.AmountSat
×
2638
                }
×
2639
                if totalConfirmedVal != confirmedBalance {
×
2640
                        return fmt.Errorf("expected total confirmed utxo "+
×
2641
                                "balance %v, got %v", confirmedBalance,
×
2642
                                totalConfirmedVal)
×
2643
                }
×
2644

2645
                // Skip unconfirmed balance checks for neutrino nodes.
2646
                if h.IsNeutrinoBackend() {
×
2647
                        return nil
×
2648
                }
×
2649

2650
                // Check unconfirmed balance.
2651
                if accountBalance.UnconfirmedBalance != unconfirmedBalance {
×
2652
                        return fmt.Errorf("expected unconfirmed balance %v, "+
×
2653
                                "got %v", unconfirmedBalance,
×
2654
                                accountBalance.UnconfirmedBalance)
×
2655
                }
×
2656

2657
                utxos = h.GetUTXOsUnconfirmed(hn, account)
×
2658
                var totalUnconfirmedVal int64
×
2659
                for _, utxo := range utxos {
×
2660
                        totalUnconfirmedVal += utxo.AmountSat
×
2661
                }
×
2662
                if totalUnconfirmedVal != unconfirmedBalance {
×
2663
                        return fmt.Errorf("expected total unconfirmed utxo "+
×
2664
                                "balance %v, got %v", unconfirmedBalance,
×
2665
                                totalUnconfirmedVal)
×
2666
                }
×
2667

2668
                return nil
×
2669
        }, DefaultTimeout)
2670
        require.NoError(h, err, "timeout checking wallet account balance")
×
2671
}
2672

2673
// AssertClosingTxInMempool assert that the closing transaction of the given
2674
// channel point can be found in the mempool. If the channel has anchors, it
2675
// will assert the anchor sweep tx is also in the mempool.
2676
func (h *HarnessTest) AssertClosingTxInMempool(cp *lnrpc.ChannelPoint,
2677
        c lnrpc.CommitmentType) *wire.MsgTx {
×
2678

×
2679
        // Get expected number of txes to be found in the mempool.
×
2680
        expectedTxes := 1
×
2681
        hasAnchors := CommitTypeHasAnchors(c)
×
2682
        if hasAnchors {
×
2683
                expectedTxes = 2
×
2684
        }
×
2685

2686
        // Wait for the expected txes to be found in the mempool.
2687
        h.AssertNumTxsInMempool(expectedTxes)
×
2688

×
2689
        // Get the closing tx from the mempool.
×
2690
        op := h.OutPointFromChannelPoint(cp)
×
2691
        closeTx := h.AssertOutpointInMempool(op)
×
2692

×
2693
        return closeTx
×
2694
}
2695

2696
// AssertClosingTxInMempool assert that the closing transaction of the given
2697
// channel point can be found in the mempool. If the channel has anchors, it
2698
// will assert the anchor sweep tx is also in the mempool.
2699
func (h *HarnessTest) MineClosingTx(cp *lnrpc.ChannelPoint) *wire.MsgTx {
×
2700
        // Wait for the expected txes to be found in the mempool.
×
2701
        h.AssertNumTxsInMempool(1)
×
2702

×
2703
        // Get the closing tx from the mempool.
×
2704
        op := h.OutPointFromChannelPoint(cp)
×
2705
        closeTx := h.AssertOutpointInMempool(op)
×
2706

×
2707
        // Mine a block to confirm the closing transaction and potential anchor
×
2708
        // sweep.
×
2709
        h.MineBlocksAndAssertNumTxes(1, 1)
×
2710

×
2711
        return closeTx
×
2712
}
×
2713

2714
// AssertWalletLockedBalance asserts the expected amount has been marked as
2715
// locked in the node's WalletBalance response.
2716
func (h *HarnessTest) AssertWalletLockedBalance(hn *node.HarnessNode,
2717
        balance int64) {
×
2718

×
2719
        err := wait.NoError(func() error {
×
2720
                balanceResp := hn.RPC.WalletBalance()
×
2721
                got := balanceResp.LockedBalance
×
2722

×
2723
                if got != balance {
×
2724
                        return fmt.Errorf("want %d, got %d", balance, got)
×
2725
                }
×
2726

2727
                return nil
×
2728
        }, wait.DefaultTimeout)
2729
        require.NoError(h, err, "%s: timeout checking locked balance",
×
2730
                hn.Name())
×
2731
}
2732

2733
// AssertNumPendingSweeps asserts the number of pending sweeps for the given
2734
// node.
2735
func (h *HarnessTest) AssertNumPendingSweeps(hn *node.HarnessNode,
2736
        n int) []*walletrpc.PendingSweep {
×
2737

×
2738
        results := make([]*walletrpc.PendingSweep, 0, n)
×
2739

×
2740
        err := wait.NoError(func() error {
×
2741
                resp := hn.RPC.PendingSweeps()
×
2742
                num := len(resp.PendingSweeps)
×
2743

×
2744
                numDesc := "\n"
×
2745
                for _, s := range resp.PendingSweeps {
×
2746
                        desc := fmt.Sprintf("op=%v:%v, amt=%v, type=%v, "+
×
2747
                                "deadline=%v, maturityHeight=%v\n",
×
2748
                                s.Outpoint.TxidStr, s.Outpoint.OutputIndex,
×
2749
                                s.AmountSat, s.WitnessType, s.DeadlineHeight,
×
2750
                                s.MaturityHeight)
×
2751
                        numDesc += desc
×
2752

×
2753
                        // The deadline height must be set, otherwise the
×
2754
                        // pending input response is not update-to-date.
×
2755
                        if s.DeadlineHeight == 0 {
×
2756
                                return fmt.Errorf("input not updated: %s", desc)
×
2757
                        }
×
2758
                }
2759

2760
                if num == n {
×
2761
                        results = resp.PendingSweeps
×
2762
                        return nil
×
2763
                }
×
2764

2765
                return fmt.Errorf("want %d , got %d, sweeps: %s", n, num,
×
2766
                        numDesc)
×
2767
        }, DefaultTimeout)
2768

2769
        require.NoErrorf(h, err, "%s: check pending sweeps timeout", hn.Name())
×
2770

×
2771
        return results
×
2772
}
2773

2774
// AssertAtLeastNumPendingSweeps asserts there are at least n pending sweeps for
2775
// the given node.
2776
func (h *HarnessTest) AssertAtLeastNumPendingSweeps(hn *node.HarnessNode,
2777
        n int) []*walletrpc.PendingSweep {
×
2778

×
2779
        results := make([]*walletrpc.PendingSweep, 0, n)
×
2780

×
2781
        err := wait.NoError(func() error {
×
2782
                resp := hn.RPC.PendingSweeps()
×
2783
                num := len(resp.PendingSweeps)
×
2784

×
2785
                numDesc := "\n"
×
2786
                for _, s := range resp.PendingSweeps {
×
2787
                        desc := fmt.Sprintf("op=%v:%v, amt=%v, type=%v, "+
×
2788
                                "deadline=%v, maturityHeight=%v\n",
×
2789
                                s.Outpoint.TxidStr, s.Outpoint.OutputIndex,
×
2790
                                s.AmountSat, s.WitnessType, s.DeadlineHeight,
×
2791
                                s.MaturityHeight)
×
2792
                        numDesc += desc
×
2793

×
2794
                        // The deadline height must be set, otherwise the
×
2795
                        // pending input response is not update-to-date.
×
2796
                        if s.DeadlineHeight == 0 {
×
2797
                                return fmt.Errorf("input not updated: %s", desc)
×
2798
                        }
×
2799
                }
2800

2801
                if num >= n {
×
2802
                        results = resp.PendingSweeps
×
2803
                        return nil
×
2804
                }
×
2805

2806
                return fmt.Errorf("want %d , got %d, sweeps: %s", n, num,
×
2807
                        numDesc)
×
2808
        }, DefaultTimeout)
2809

2810
        require.NoErrorf(h, err, "%s: check pending sweeps timeout", hn.Name())
×
2811

×
2812
        return results
×
2813
}
2814

2815
// FindSweepingTxns asserts the expected number of sweeping txns are found in
2816
// the txns specified and return them.
2817
func (h *HarnessTest) FindSweepingTxns(txns []*wire.MsgTx,
2818
        expectedNumSweeps int, closeTxid chainhash.Hash) []*wire.MsgTx {
×
2819

×
2820
        var sweepTxns []*wire.MsgTx
×
2821

×
2822
        for _, tx := range txns {
×
2823
                if tx.TxIn[0].PreviousOutPoint.Hash == closeTxid {
×
2824
                        sweepTxns = append(sweepTxns, tx)
×
2825
                }
×
2826
        }
2827
        require.Len(h, sweepTxns, expectedNumSweeps, "unexpected num of sweeps")
×
2828

×
2829
        return sweepTxns
×
2830
}
2831

2832
// AssertForceCloseAndAnchorTxnsInMempool asserts that the force close and
2833
// anchor sweep txns are found in the mempool and returns the force close tx
2834
// and the anchor sweep tx.
2835
func (h *HarnessTest) AssertForceCloseAndAnchorTxnsInMempool() (*wire.MsgTx,
2836
        *wire.MsgTx) {
×
2837

×
2838
        // Assert there are two txns in the mempool.
×
2839
        txns := h.GetNumTxsFromMempool(2)
×
2840

×
2841
        // isParentAndChild checks whether there is an input used in the
×
2842
        // assumed child tx by checking every input's previous outpoint against
×
2843
        // the assumed parentTxid.
×
2844
        isParentAndChild := func(parent, child *wire.MsgTx) bool {
×
2845
                parentTxid := parent.TxHash()
×
2846

×
2847
                for _, inp := range child.TxIn {
×
2848
                        if inp.PreviousOutPoint.Hash == parentTxid {
×
2849
                                // Found a match, this is indeed the anchor
×
2850
                                // sweeping tx so we return it here.
×
2851
                                return true
×
2852
                        }
×
2853
                }
2854

2855
                return false
×
2856
        }
2857

2858
        switch {
×
2859
        // Assume the first one is the closing tx and the second one is the
2860
        // anchor sweeping tx.
2861
        case isParentAndChild(txns[0], txns[1]):
×
2862
                return txns[0], txns[1]
×
2863

2864
        // Assume the first one is the anchor sweeping tx and the second one is
2865
        // the closing tx.
2866
        case isParentAndChild(txns[1], txns[0]):
×
2867
                return txns[1], txns[0]
×
2868

2869
        // Unrelated txns found, fail the test.
2870
        default:
×
2871
                h.Fatalf("the two txns not related: %v", txns)
×
2872

×
2873
                return nil, nil
×
2874
        }
2875
}
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