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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

0.0
/lnwire/test_message.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "image/color"
7
        "math"
8

9
        "github.com/btcsuite/btcd/btcec/v2"
10
        "github.com/btcsuite/btcd/btcutil"
11
        "github.com/btcsuite/btcd/chaincfg/chainhash"
12
        "github.com/lightningnetwork/lnd/fn/v2"
13
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
14
        "github.com/lightningnetwork/lnd/tlv"
15
        "pgregory.net/rapid"
16
)
17

18
// TestMessage is an interface that extends the base Message interface with a
19
// method to populate the message with random testing data.
20
type TestMessage interface {
21
        Message
22

23
        // RandTestMessage populates the message with random data suitable for
24
        // testing. It uses the rapid testing framework to generate random
25
        // values.
26
        RandTestMessage(t *rapid.T) Message
27
}
28

29
// A compile time check to ensure AcceptChannel implements the TestMessage
30
// interface.
31
var _ TestMessage = (*AcceptChannel)(nil)
32

33
// RandTestMessage populates the message with random data suitable for testing.
34
// It uses the rapid testing framework to generate random values.
35
//
36
// This is part of the TestMessage interface.
UNCOV
37
func (a *AcceptChannel) RandTestMessage(t *rapid.T) Message {
×
UNCOV
38
        var pendingChanID [32]byte
×
UNCOV
39
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
40
                t, "pendingChanID",
×
UNCOV
41
        )
×
UNCOV
42
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
43

×
UNCOV
44
        var channelType *ChannelType
×
UNCOV
45
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
UNCOV
46
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
×
UNCOV
47
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
48

×
UNCOV
49
        if includeChannelType {
×
UNCOV
50
                channelType = RandChannelType(t)
×
UNCOV
51
        }
×
52

UNCOV
53
        var leaseExpiry *LeaseExpiry
×
UNCOV
54
        if includeLeaseExpiry {
×
UNCOV
55
                leaseExpiry = RandLeaseExpiry(t)
×
UNCOV
56
        }
×
57

UNCOV
58
        var localNonce OptMusig2NonceTLV
×
UNCOV
59
        if includeLocalNonce {
×
UNCOV
60
                nonce := RandMusig2Nonce(t)
×
UNCOV
61
                localNonce = tlv.SomeRecordT(
×
UNCOV
62
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
UNCOV
63
                )
×
UNCOV
64
        }
×
65

UNCOV
66
        return &AcceptChannel{
×
UNCOV
67
                PendingChannelID: pendingChanID,
×
UNCOV
68
                DustLimit: btcutil.Amount(
×
UNCOV
69
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
×
UNCOV
70
                ),
×
UNCOV
71
                MaxValueInFlight: MilliSatoshi(
×
UNCOV
72
                        rapid.IntRange(10000, 1000000).Draw(
×
UNCOV
73
                                t, "maxValueInFlight",
×
UNCOV
74
                        ),
×
UNCOV
75
                ),
×
UNCOV
76
                ChannelReserve: btcutil.Amount(
×
UNCOV
77
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
×
UNCOV
78
                ),
×
UNCOV
79
                HtlcMinimum: MilliSatoshi(
×
UNCOV
80
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
×
UNCOV
81
                ),
×
UNCOV
82
                MinAcceptDepth: uint32(
×
UNCOV
83
                        rapid.IntRange(1, 10).Draw(t, "minAcceptDepth"),
×
UNCOV
84
                ),
×
UNCOV
85
                CsvDelay: uint16(
×
UNCOV
86
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
×
UNCOV
87
                ),
×
UNCOV
88
                MaxAcceptedHTLCs: uint16(
×
UNCOV
89
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
×
UNCOV
90
                ),
×
UNCOV
91
                FundingKey:            RandPubKey(t),
×
UNCOV
92
                RevocationPoint:       RandPubKey(t),
×
UNCOV
93
                PaymentPoint:          RandPubKey(t),
×
UNCOV
94
                DelayedPaymentPoint:   RandPubKey(t),
×
UNCOV
95
                HtlcPoint:             RandPubKey(t),
×
UNCOV
96
                FirstCommitmentPoint:  RandPubKey(t),
×
UNCOV
97
                UpfrontShutdownScript: RandDeliveryAddress(t),
×
UNCOV
98
                ChannelType:           channelType,
×
UNCOV
99
                LeaseExpiry:           leaseExpiry,
×
UNCOV
100
                LocalNonce:            localNonce,
×
UNCOV
101
                ExtraData:             RandExtraOpaqueData(t, nil),
×
UNCOV
102
        }
×
103
}
104

105
// A compile time check to ensure AnnounceSignatures1 implements the
106
// lnwire.TestMessage interface.
107
var _ TestMessage = (*AnnounceSignatures1)(nil)
108

109
// RandTestMessage populates the message with random data suitable for testing.
110
// It uses the rapid testing framework to generate random values.
111
//
112
// This is part of the TestMessage interface.
UNCOV
113
func (a *AnnounceSignatures1) RandTestMessage(t *rapid.T) Message {
×
UNCOV
114
        return &AnnounceSignatures1{
×
UNCOV
115
                ChannelID:        RandChannelID(t),
×
UNCOV
116
                ShortChannelID:   RandShortChannelID(t),
×
UNCOV
117
                NodeSignature:    RandSignature(t),
×
UNCOV
118
                BitcoinSignature: RandSignature(t),
×
UNCOV
119
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
×
UNCOV
120
        }
×
UNCOV
121
}
×
122

123
// A compile time check to ensure AnnounceSignatures2 implements the
124
// lnwire.TestMessage interface.
125
var _ TestMessage = (*AnnounceSignatures2)(nil)
126

127
// RandTestMessage populates the message with random data suitable for testing.
128
// It uses the rapid testing framework to generate random values.
129
//
130
// This is part of the TestMessage interface.
UNCOV
131
func (a *AnnounceSignatures2) RandTestMessage(t *rapid.T) Message {
×
UNCOV
132
        return &AnnounceSignatures2{
×
UNCOV
133
                ChannelID:        RandChannelID(t),
×
UNCOV
134
                ShortChannelID:   RandShortChannelID(t),
×
UNCOV
135
                PartialSignature: *RandPartialSig(t),
×
UNCOV
136
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
×
UNCOV
137
        }
×
UNCOV
138
}
×
139

140
// A compile time check to ensure ChannelAnnouncement1 implements the
141
// TestMessage interface.
142
var _ TestMessage = (*ChannelAnnouncement1)(nil)
143

144
// RandTestMessage populates the message with random data suitable for testing.
145
// It uses the rapid testing framework to generate random values.
146
//
147
// This is part of the TestMessage interface.
UNCOV
148
func (a *ChannelAnnouncement1) RandTestMessage(t *rapid.T) Message {
×
UNCOV
149
        // Generate Node IDs and Bitcoin keys (compressed public keys)
×
UNCOV
150
        node1PubKey := RandPubKey(t)
×
UNCOV
151
        node2PubKey := RandPubKey(t)
×
UNCOV
152
        bitcoin1PubKey := RandPubKey(t)
×
UNCOV
153
        bitcoin2PubKey := RandPubKey(t)
×
UNCOV
154

×
UNCOV
155
        // Convert to byte arrays
×
UNCOV
156
        var nodeID1, nodeID2, bitcoinKey1, bitcoinKey2 [33]byte
×
UNCOV
157
        copy(nodeID1[:], node1PubKey.SerializeCompressed())
×
UNCOV
158
        copy(nodeID2[:], node2PubKey.SerializeCompressed())
×
UNCOV
159
        copy(bitcoinKey1[:], bitcoin1PubKey.SerializeCompressed())
×
UNCOV
160
        copy(bitcoinKey2[:], bitcoin2PubKey.SerializeCompressed())
×
UNCOV
161

×
UNCOV
162
        // Ensure nodeID1 is numerically less than nodeID2
×
UNCOV
163
        // This is a requirement stated in the field description
×
UNCOV
164
        if bytes.Compare(nodeID1[:], nodeID2[:]) > 0 {
×
UNCOV
165
                nodeID1, nodeID2 = nodeID2, nodeID1
×
UNCOV
166
        }
×
167

168
        // Generate chain hash
UNCOV
169
        chainHash := RandChainHash(t)
×
UNCOV
170
        var hash chainhash.Hash
×
UNCOV
171
        copy(hash[:], chainHash[:])
×
UNCOV
172

×
UNCOV
173
        return &ChannelAnnouncement1{
×
UNCOV
174
                NodeSig1:        RandSignature(t),
×
UNCOV
175
                NodeSig2:        RandSignature(t),
×
UNCOV
176
                BitcoinSig1:     RandSignature(t),
×
UNCOV
177
                BitcoinSig2:     RandSignature(t),
×
UNCOV
178
                Features:        RandFeatureVector(t),
×
UNCOV
179
                ChainHash:       hash,
×
UNCOV
180
                ShortChannelID:  RandShortChannelID(t),
×
UNCOV
181
                NodeID1:         nodeID1,
×
UNCOV
182
                NodeID2:         nodeID2,
×
UNCOV
183
                BitcoinKey1:     bitcoinKey1,
×
UNCOV
184
                BitcoinKey2:     bitcoinKey2,
×
UNCOV
185
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
186
        }
×
187
}
188

189
// A compile time check to ensure ChannelAnnouncement2 implements the
190
// lnwire.TestMessage interface.
191
var _ TestMessage = (*ChannelAnnouncement2)(nil)
192

193
// RandTestMessage populates the message with random data suitable for testing.
194
// It uses the rapid testing framework to generate random values.
195
//
196
// This is part of the TestMessage interface.
UNCOV
197
func (c *ChannelAnnouncement2) RandTestMessage(t *rapid.T) Message {
×
UNCOV
198
        features := RandFeatureVector(t)
×
UNCOV
199
        shortChanID := RandShortChannelID(t)
×
UNCOV
200
        capacity := uint64(rapid.IntRange(1, 16777215).Draw(t, "capacity"))
×
UNCOV
201

×
UNCOV
202
        var nodeID1, nodeID2 [33]byte
×
UNCOV
203
        copy(nodeID1[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
204
        copy(nodeID2[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
205

×
UNCOV
206
        // Make sure nodeID1 is numerically less than nodeID2 (as per spec).
×
UNCOV
207
        if bytes.Compare(nodeID1[:], nodeID2[:]) > 0 {
×
UNCOV
208
                nodeID1, nodeID2 = nodeID2, nodeID1
×
UNCOV
209
        }
×
210

UNCOV
211
        chainHash := RandChainHash(t)
×
UNCOV
212
        var chainHashObj chainhash.Hash
×
UNCOV
213
        copy(chainHashObj[:], chainHash[:])
×
UNCOV
214

×
UNCOV
215
        msg := &ChannelAnnouncement2{
×
UNCOV
216
                Signature: RandSignature(t),
×
UNCOV
217
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
×
UNCOV
218
                        chainHashObj,
×
UNCOV
219
                ),
×
UNCOV
220
                Features: tlv.NewRecordT[tlv.TlvType2, RawFeatureVector](
×
UNCOV
221
                        *features,
×
UNCOV
222
                ),
×
UNCOV
223
                ShortChannelID: tlv.NewRecordT[tlv.TlvType4, ShortChannelID](
×
UNCOV
224
                        shortChanID,
×
UNCOV
225
                ),
×
UNCOV
226
                Capacity: tlv.NewPrimitiveRecord[tlv.TlvType6, uint64](
×
UNCOV
227
                        capacity,
×
UNCOV
228
                ),
×
UNCOV
229
                NodeID1: tlv.NewPrimitiveRecord[tlv.TlvType8, [33]byte](
×
UNCOV
230
                        nodeID1,
×
UNCOV
231
                ),
×
UNCOV
232
                NodeID2: tlv.NewPrimitiveRecord[tlv.TlvType10, [33]byte](
×
UNCOV
233
                        nodeID2,
×
UNCOV
234
                ),
×
UNCOV
235
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
236
        }
×
UNCOV
237

×
UNCOV
238
        msg.Signature.ForceSchnorr()
×
UNCOV
239

×
UNCOV
240
        // Randomly include optional fields
×
UNCOV
241
        if rapid.Bool().Draw(t, "includeBitcoinKey1") {
×
UNCOV
242
                var bitcoinKey1 [33]byte
×
UNCOV
243
                copy(bitcoinKey1[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
244
                msg.BitcoinKey1 = tlv.SomeRecordT(
×
UNCOV
245
                        tlv.NewPrimitiveRecord[tlv.TlvType12, [33]byte](
×
UNCOV
246
                                bitcoinKey1,
×
UNCOV
247
                        ),
×
UNCOV
248
                )
×
UNCOV
249
        }
×
250

UNCOV
251
        if rapid.Bool().Draw(t, "includeBitcoinKey2") {
×
UNCOV
252
                var bitcoinKey2 [33]byte
×
UNCOV
253
                copy(bitcoinKey2[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
254
                msg.BitcoinKey2 = tlv.SomeRecordT(
×
UNCOV
255
                        tlv.NewPrimitiveRecord[tlv.TlvType14, [33]byte](
×
UNCOV
256
                                bitcoinKey2,
×
UNCOV
257
                        ),
×
UNCOV
258
                )
×
UNCOV
259
        }
×
260

UNCOV
261
        if rapid.Bool().Draw(t, "includeMerkleRootHash") {
×
UNCOV
262
                hash := RandSHA256Hash(t)
×
UNCOV
263
                var merkleRootHash [32]byte
×
UNCOV
264
                copy(merkleRootHash[:], hash[:])
×
UNCOV
265
                msg.MerkleRootHash = tlv.SomeRecordT(
×
UNCOV
266
                        tlv.NewPrimitiveRecord[tlv.TlvType16, [32]byte](
×
UNCOV
267
                                merkleRootHash,
×
UNCOV
268
                        ),
×
UNCOV
269
                )
×
UNCOV
270
        }
×
271

UNCOV
272
        return msg
×
273
}
274

275
// A compile time check to ensure ChannelReady implements the lnwire.TestMessage
276
// interface.
277
var _ TestMessage = (*ChannelReady)(nil)
278

279
// RandTestMessage populates the message with random data suitable for testing.
280
// It uses the rapid testing framework to generate random values.
281
//
282
// This is part of the TestMessage interface.
UNCOV
283
func (c *ChannelReady) RandTestMessage(t *rapid.T) Message {
×
UNCOV
284
        msg := &ChannelReady{
×
UNCOV
285
                ChanID:                 RandChannelID(t),
×
UNCOV
286
                NextPerCommitmentPoint: RandPubKey(t),
×
UNCOV
287
                ExtraData:              RandExtraOpaqueData(t, nil),
×
UNCOV
288
        }
×
UNCOV
289

×
UNCOV
290
        includeAliasScid := rapid.Bool().Draw(t, "includeAliasScid")
×
UNCOV
291
        includeNextLocalNonce := rapid.Bool().Draw(t, "includeNextLocalNonce")
×
UNCOV
292
        includeAnnouncementNodeNonce := rapid.Bool().Draw(
×
UNCOV
293
                t, "includeAnnouncementNodeNonce",
×
UNCOV
294
        )
×
UNCOV
295
        includeAnnouncementBitcoinNonce := rapid.Bool().Draw(
×
UNCOV
296
                t, "includeAnnouncementBitcoinNonce",
×
UNCOV
297
        )
×
UNCOV
298

×
UNCOV
299
        if includeAliasScid {
×
UNCOV
300
                scid := RandShortChannelID(t)
×
UNCOV
301
                msg.AliasScid = &scid
×
UNCOV
302
        }
×
303

UNCOV
304
        if includeNextLocalNonce {
×
UNCOV
305
                nonce := RandMusig2Nonce(t)
×
UNCOV
306
                msg.NextLocalNonce = SomeMusig2Nonce(nonce)
×
UNCOV
307
        }
×
308

UNCOV
309
        if includeAnnouncementNodeNonce {
×
UNCOV
310
                nonce := RandMusig2Nonce(t)
×
UNCOV
311
                msg.AnnouncementNodeNonce = tlv.SomeRecordT(
×
UNCOV
312
                        tlv.NewRecordT[tlv.TlvType0, Musig2Nonce](nonce),
×
UNCOV
313
                )
×
UNCOV
314
        }
×
315

UNCOV
316
        if includeAnnouncementBitcoinNonce {
×
UNCOV
317
                nonce := RandMusig2Nonce(t)
×
UNCOV
318
                msg.AnnouncementBitcoinNonce = tlv.SomeRecordT(
×
UNCOV
319
                        tlv.NewRecordT[tlv.TlvType2, Musig2Nonce](nonce),
×
UNCOV
320
                )
×
UNCOV
321
        }
×
322

UNCOV
323
        return msg
×
324
}
325

326
// A compile time check to ensure ChannelReestablish implements the
327
// lnwire.TestMessage interface.
328
var _ TestMessage = (*ChannelReestablish)(nil)
329

330
// RandTestMessage populates the message with random data suitable for testing.
331
// It uses the rapid testing framework to generate random values.
332
//
333
// This is part of the TestMessage interface.
UNCOV
334
func (a *ChannelReestablish) RandTestMessage(t *rapid.T) Message {
×
UNCOV
335
        msg := &ChannelReestablish{
×
UNCOV
336
                ChanID: RandChannelID(t),
×
UNCOV
337
                NextLocalCommitHeight: rapid.Uint64().Draw(
×
UNCOV
338
                        t, "nextLocalCommitHeight",
×
UNCOV
339
                ),
×
UNCOV
340
                RemoteCommitTailHeight: rapid.Uint64().Draw(
×
UNCOV
341
                        t, "remoteCommitTailHeight",
×
UNCOV
342
                ),
×
UNCOV
343
                LastRemoteCommitSecret:    RandPaymentPreimage(t),
×
UNCOV
344
                LocalUnrevokedCommitPoint: RandPubKey(t),
×
UNCOV
345
                ExtraData:                 RandExtraOpaqueData(t, nil),
×
UNCOV
346
        }
×
UNCOV
347

×
UNCOV
348
        // Randomly decide whether to include optional fields
×
UNCOV
349
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
350
        includeDynHeight := rapid.Bool().Draw(t, "includeDynHeight")
×
UNCOV
351

×
UNCOV
352
        if includeLocalNonce {
×
UNCOV
353
                nonce := RandMusig2Nonce(t)
×
UNCOV
354
                msg.LocalNonce = SomeMusig2Nonce(nonce)
×
UNCOV
355
        }
×
356

UNCOV
357
        if includeDynHeight {
×
UNCOV
358
                height := DynHeight(rapid.Uint64().Draw(t, "dynHeight"))
×
UNCOV
359
                msg.DynHeight = fn.Some(height)
×
UNCOV
360
        }
×
361

UNCOV
362
        return msg
×
363
}
364

365
// A compile time check to ensure ChannelUpdate1 implements the TestMessage
366
// interface.
367
var _ TestMessage = (*ChannelUpdate1)(nil)
368

369
// RandTestMessage populates the message with random data suitable for testing.
370
// It uses the rapid testing framework to generate random values.
371
//
372
// This is part of the TestMessage interface.
UNCOV
373
func (a *ChannelUpdate1) RandTestMessage(t *rapid.T) Message {
×
UNCOV
374
        // Generate random message flags
×
UNCOV
375
        // Randomly decide whether to include max HTLC field
×
UNCOV
376
        includeMaxHtlc := rapid.Bool().Draw(t, "includeMaxHtlc")
×
UNCOV
377
        var msgFlags ChanUpdateMsgFlags
×
UNCOV
378
        if includeMaxHtlc {
×
UNCOV
379
                msgFlags |= ChanUpdateRequiredMaxHtlc
×
UNCOV
380
        }
×
381

382
        // Generate random channel flags
383
        // Randomly decide direction (node1 or node2)
UNCOV
384
        isNode2 := rapid.Bool().Draw(t, "isNode2")
×
UNCOV
385
        var chanFlags ChanUpdateChanFlags
×
UNCOV
386
        if isNode2 {
×
UNCOV
387
                chanFlags |= ChanUpdateDirection
×
UNCOV
388
        }
×
389

390
        // Randomly decide if channel is disabled
UNCOV
391
        isDisabled := rapid.Bool().Draw(t, "isDisabled")
×
UNCOV
392
        if isDisabled {
×
UNCOV
393
                chanFlags |= ChanUpdateDisabled
×
UNCOV
394
        }
×
395

396
        // Generate chain hash
UNCOV
397
        chainHash := RandChainHash(t)
×
UNCOV
398
        var hash chainhash.Hash
×
UNCOV
399
        copy(hash[:], chainHash[:])
×
UNCOV
400

×
UNCOV
401
        // Generate other random fields
×
UNCOV
402
        maxHtlc := MilliSatoshi(rapid.Uint64().Draw(t, "maxHtlc"))
×
UNCOV
403

×
UNCOV
404
        // If max HTLC flag is not set, we need to zero the value
×
UNCOV
405
        if !includeMaxHtlc {
×
UNCOV
406
                maxHtlc = 0
×
UNCOV
407
        }
×
408

UNCOV
409
        return &ChannelUpdate1{
×
UNCOV
410
                Signature:      RandSignature(t),
×
UNCOV
411
                ChainHash:      hash,
×
UNCOV
412
                ShortChannelID: RandShortChannelID(t),
×
UNCOV
413
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
414
                        t, "timestamp"),
×
UNCOV
415
                ),
×
UNCOV
416
                MessageFlags: msgFlags,
×
UNCOV
417
                ChannelFlags: chanFlags,
×
UNCOV
418
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
×
UNCOV
419
                        t, "timelockDelta"),
×
UNCOV
420
                ),
×
UNCOV
421
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
×
UNCOV
422
                        t, "htlcMinimum"),
×
UNCOV
423
                ),
×
UNCOV
424
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
425
                        t, "baseFee"),
×
UNCOV
426
                ),
×
UNCOV
427
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
428
                        t, "feeRate"),
×
UNCOV
429
                ),
×
UNCOV
430
                HtlcMaximumMsat: maxHtlc,
×
UNCOV
431
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
432
        }
×
433
}
434

435
// A compile time check to ensure ChannelUpdate2 implements the
436
// lnwire.TestMessage interface.
437
var _ TestMessage = (*ChannelUpdate2)(nil)
438

439
// RandTestMessage populates the message with random data suitable for testing.
440
// It uses the rapid testing framework to generate random values.
441
//
442
// This is part of the TestMessage interface.
UNCOV
443
func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
×
UNCOV
444
        shortChanID := RandShortChannelID(t)
×
UNCOV
445
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
×
UNCOV
446

×
UNCOV
447
        var disabledFlags ChanUpdateDisableFlags
×
UNCOV
448
        if rapid.Bool().Draw(t, "disableIncoming") {
×
UNCOV
449
                disabledFlags |= ChanUpdateDisableIncoming
×
UNCOV
450
        }
×
UNCOV
451
        if rapid.Bool().Draw(t, "disableOutgoing") {
×
UNCOV
452
                disabledFlags |= ChanUpdateDisableOutgoing
×
UNCOV
453
        }
×
454

UNCOV
455
        cltvExpiryDelta := uint16(rapid.IntRange(10, 200).Draw(
×
UNCOV
456
                t, "cltvExpiryDelta"),
×
UNCOV
457
        )
×
UNCOV
458

×
UNCOV
459
        htlcMinMsat := MilliSatoshi(rapid.IntRange(1, 10000).Draw(
×
UNCOV
460
                t, "htlcMinMsat"),
×
UNCOV
461
        )
×
UNCOV
462
        htlcMaxMsat := MilliSatoshi(rapid.IntRange(10000, 100000000).Draw(
×
UNCOV
463
                t, "htlcMaxMsat"),
×
UNCOV
464
        )
×
UNCOV
465
        feeBaseMsat := uint32(rapid.IntRange(0, 10000).Draw(t, "feeBaseMsat"))
×
UNCOV
466
        feeProportionalMillionths := uint32(rapid.IntRange(0, 10000).Draw(
×
UNCOV
467
                t, "feeProportionalMillionths"),
×
UNCOV
468
        )
×
UNCOV
469

×
UNCOV
470
        chainHash := RandChainHash(t)
×
UNCOV
471
        var chainHashObj chainhash.Hash
×
UNCOV
472
        copy(chainHashObj[:], chainHash[:])
×
UNCOV
473

×
UNCOV
474
        //nolint:ll
×
UNCOV
475
        msg := &ChannelUpdate2{
×
UNCOV
476
                Signature: RandSignature(t),
×
UNCOV
477
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
×
UNCOV
478
                        chainHashObj,
×
UNCOV
479
                ),
×
UNCOV
480
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2, ShortChannelID](
×
UNCOV
481
                        shortChanID,
×
UNCOV
482
                ),
×
UNCOV
483
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType4, uint32](
×
UNCOV
484
                        blockHeight,
×
UNCOV
485
                ),
×
UNCOV
486
                DisabledFlags: tlv.NewPrimitiveRecord[tlv.TlvType6, ChanUpdateDisableFlags]( //nolint:ll
×
UNCOV
487
                        disabledFlags,
×
UNCOV
488
                ),
×
UNCOV
489
                CLTVExpiryDelta: tlv.NewPrimitiveRecord[tlv.TlvType10, uint16](
×
UNCOV
490
                        cltvExpiryDelta,
×
UNCOV
491
                ),
×
UNCOV
492
                HTLCMinimumMsat: tlv.NewPrimitiveRecord[tlv.TlvType12, MilliSatoshi](
×
UNCOV
493
                        htlcMinMsat,
×
UNCOV
494
                ),
×
UNCOV
495
                HTLCMaximumMsat: tlv.NewPrimitiveRecord[tlv.TlvType14, MilliSatoshi](
×
UNCOV
496
                        htlcMaxMsat,
×
UNCOV
497
                ),
×
UNCOV
498
                FeeBaseMsat: tlv.NewPrimitiveRecord[tlv.TlvType16, uint32](
×
UNCOV
499
                        feeBaseMsat,
×
UNCOV
500
                ),
×
UNCOV
501
                FeeProportionalMillionths: tlv.NewPrimitiveRecord[tlv.TlvType18, uint32](
×
UNCOV
502
                        feeProportionalMillionths,
×
UNCOV
503
                ),
×
UNCOV
504
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
505
        }
×
UNCOV
506

×
UNCOV
507
        msg.Signature.ForceSchnorr()
×
UNCOV
508

×
UNCOV
509
        if rapid.Bool().Draw(t, "isSecondPeer") {
×
UNCOV
510
                msg.SecondPeer = tlv.SomeRecordT(
×
UNCOV
511
                        tlv.RecordT[tlv.TlvType8, TrueBoolean]{},
×
UNCOV
512
                )
×
UNCOV
513
        }
×
514

UNCOV
515
        return msg
×
516
}
517

518
// A compile time check to ensure ClosingComplete implements the
519
// lnwire.TestMessage interface.
520
var _ TestMessage = (*ClosingComplete)(nil)
521

522
// RandTestMessage populates the message with random data suitable for testing.
523
// It uses the rapid testing framework to generate random values.
524
//
525
// This is part of the TestMessage interface.
UNCOV
526
func (c *ClosingComplete) RandTestMessage(t *rapid.T) Message {
×
UNCOV
527
        msg := &ClosingComplete{
×
UNCOV
528
                ChannelID: RandChannelID(t),
×
UNCOV
529
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
×
UNCOV
530
                        t, "feeSatoshis"),
×
UNCOV
531
                ),
×
UNCOV
532
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
×
UNCOV
533
                        t, "lockTime",
×
UNCOV
534
                ),
×
UNCOV
535
                CloseeScript: RandDeliveryAddress(t),
×
UNCOV
536
                CloserScript: RandDeliveryAddress(t),
×
UNCOV
537
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
538
        }
×
UNCOV
539

×
UNCOV
540
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
×
UNCOV
541
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
×
UNCOV
542
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
×
UNCOV
543

×
UNCOV
544
        // Ensure at least one signature is present.
×
UNCOV
545
        if !includeCloserNoClosee && !includeNoCloserClosee &&
×
UNCOV
546
                !includeCloserAndClosee {
×
UNCOV
547

×
UNCOV
548
                // If all are false, enable at least one randomly.
×
UNCOV
549
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
×
UNCOV
550
                switch choice {
×
UNCOV
551
                case 0:
×
UNCOV
552
                        includeCloserNoClosee = true
×
UNCOV
553
                case 1:
×
UNCOV
554
                        includeNoCloserClosee = true
×
UNCOV
555
                case 2:
×
UNCOV
556
                        includeCloserAndClosee = true
×
557
                }
558
        }
559

UNCOV
560
        if includeCloserNoClosee {
×
UNCOV
561
                sig := RandSignature(t)
×
UNCOV
562
                msg.CloserNoClosee = tlv.SomeRecordT(
×
UNCOV
563
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
×
UNCOV
564
                )
×
UNCOV
565
        }
×
566

UNCOV
567
        if includeNoCloserClosee {
×
UNCOV
568
                sig := RandSignature(t)
×
UNCOV
569
                msg.NoCloserClosee = tlv.SomeRecordT(
×
UNCOV
570
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
×
UNCOV
571
                )
×
UNCOV
572
        }
×
573

UNCOV
574
        if includeCloserAndClosee {
×
UNCOV
575
                sig := RandSignature(t)
×
UNCOV
576
                msg.CloserAndClosee = tlv.SomeRecordT(
×
UNCOV
577
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
×
UNCOV
578
                )
×
UNCOV
579
        }
×
580

UNCOV
581
        return msg
×
582
}
583

584
// A compile time check to ensure ClosingSig implements the lnwire.TestMessage
585
// interface.
586
var _ TestMessage = (*ClosingSig)(nil)
587

588
// RandTestMessage populates the message with random data suitable for testing.
589
// It uses the rapid testing framework to generate random values.
590
//
591
// This is part of the TestMessage interface.
UNCOV
592
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
593
        msg := &ClosingSig{
×
UNCOV
594
                ChannelID:    RandChannelID(t),
×
UNCOV
595
                CloseeScript: RandDeliveryAddress(t),
×
UNCOV
596
                CloserScript: RandDeliveryAddress(t),
×
UNCOV
597
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
598
        }
×
UNCOV
599

×
UNCOV
600
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
×
UNCOV
601
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
×
UNCOV
602
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
×
UNCOV
603

×
UNCOV
604
        // Ensure at least one signature is present.
×
UNCOV
605
        if !includeCloserNoClosee && !includeNoCloserClosee &&
×
UNCOV
606
                !includeCloserAndClosee {
×
UNCOV
607

×
UNCOV
608
                // If all are false, enable at least one randomly.
×
UNCOV
609
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
×
UNCOV
610
                switch choice {
×
UNCOV
611
                case 0:
×
UNCOV
612
                        includeCloserNoClosee = true
×
UNCOV
613
                case 1:
×
UNCOV
614
                        includeNoCloserClosee = true
×
UNCOV
615
                case 2:
×
UNCOV
616
                        includeCloserAndClosee = true
×
617
                }
618
        }
619

UNCOV
620
        if includeCloserNoClosee {
×
UNCOV
621
                sig := RandSignature(t)
×
UNCOV
622
                msg.CloserNoClosee = tlv.SomeRecordT(
×
UNCOV
623
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
×
UNCOV
624
                )
×
UNCOV
625
        }
×
626

UNCOV
627
        if includeNoCloserClosee {
×
UNCOV
628
                sig := RandSignature(t)
×
UNCOV
629
                msg.NoCloserClosee = tlv.SomeRecordT(
×
UNCOV
630
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
×
UNCOV
631
                )
×
UNCOV
632
        }
×
633

UNCOV
634
        if includeCloserAndClosee {
×
UNCOV
635
                sig := RandSignature(t)
×
UNCOV
636
                msg.CloserAndClosee = tlv.SomeRecordT(
×
UNCOV
637
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
×
UNCOV
638
                )
×
UNCOV
639
        }
×
640

UNCOV
641
        return msg
×
642
}
643

644
// A compile time check to ensure ClosingSigned implements the
645
// lnwire.TestMessage interface.
646
var _ TestMessage = (*ClosingSigned)(nil)
647

648
// RandTestMessage populates the message with random data suitable for testing.
649
// It uses the rapid testing framework to generate random values.
650
//
651
// This is part of the TestMessage interface.
UNCOV
652
func (c *ClosingSigned) RandTestMessage(t *rapid.T) Message {
×
UNCOV
653
        // Generate a random boolean to decide whether to include CommitSig or
×
UNCOV
654
        // PartialSig Since they're mutually exclusive, when one is populated,
×
UNCOV
655
        // the other must be blank.
×
UNCOV
656
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
UNCOV
657

×
UNCOV
658
        msg := &ClosingSigned{
×
UNCOV
659
                ChannelID: RandChannelID(t),
×
UNCOV
660
                FeeSatoshis: btcutil.Amount(
×
UNCOV
661
                        rapid.Int64Range(0, 1000000).Draw(t, "feeSatoshis"),
×
UNCOV
662
                ),
×
UNCOV
663
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
664
        }
×
UNCOV
665

×
UNCOV
666
        if usePartialSig {
×
UNCOV
667
                sigBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
668
                        t, "sigScalar",
×
UNCOV
669
                )
×
UNCOV
670
                var s btcec.ModNScalar
×
UNCOV
671
                _ = s.SetByteSlice(sigBytes)
×
UNCOV
672

×
UNCOV
673
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
×
UNCOV
674
                msg.Signature = Sig{}
×
UNCOV
675
        } else {
×
UNCOV
676
                msg.Signature = RandSignature(t)
×
UNCOV
677
        }
×
678

UNCOV
679
        return msg
×
680
}
681

682
// A compile time check to ensure CommitSig implements the lnwire.TestMessage
683
// interface.
684
var _ TestMessage = (*CommitSig)(nil)
685

686
// RandTestMessage populates the message with random data suitable for testing.
687
// It uses the rapid testing framework to generate random values.
688
//
689
// This is part of the TestMessage interface.
UNCOV
690
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
691
        cr, _ := RandCustomRecords(t, nil, true)
×
UNCOV
692
        sig := &CommitSig{
×
UNCOV
693
                ChanID:        RandChannelID(t),
×
UNCOV
694
                CommitSig:     RandSignature(t),
×
UNCOV
695
                CustomRecords: cr,
×
UNCOV
696
        }
×
UNCOV
697

×
UNCOV
698
        numHtlcSigs := rapid.IntRange(0, 20).Draw(t, "numHtlcSigs")
×
UNCOV
699
        htlcSigs := make([]Sig, numHtlcSigs)
×
UNCOV
700
        for i := 0; i < numHtlcSigs; i++ {
×
UNCOV
701
                htlcSigs[i] = RandSignature(t)
×
UNCOV
702
        }
×
703

UNCOV
704
        if len(htlcSigs) > 0 {
×
UNCOV
705
                sig.HtlcSigs = htlcSigs
×
UNCOV
706
        }
×
707

UNCOV
708
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
UNCOV
709
        if includePartialSig {
×
UNCOV
710
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
711
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
712
        }
×
713

UNCOV
714
        return sig
×
715
}
716

717
// A compile time check to ensure Custom implements the lnwire.TestMessage
718
// interface.
719
var _ TestMessage = (*Custom)(nil)
720

721
// RandTestMessage populates the message with random data suitable for testing.
722
// It uses the rapid testing framework to generate random values.
723
//
724
// This is part of the TestMessage interface.
UNCOV
725
func (c *Custom) RandTestMessage(t *rapid.T) Message {
×
UNCOV
726
        msgType := MessageType(
×
UNCOV
727
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
×
UNCOV
728
                        t, "customMsgType",
×
UNCOV
729
                ),
×
UNCOV
730
        )
×
UNCOV
731

×
UNCOV
732
        dataLen := rapid.IntRange(0, 1000).Draw(t, "customDataLength")
×
UNCOV
733
        data := rapid.SliceOfN(rapid.Byte(), dataLen, dataLen).Draw(
×
UNCOV
734
                t, "customData",
×
UNCOV
735
        )
×
UNCOV
736

×
UNCOV
737
        msg, err := NewCustom(msgType, data)
×
UNCOV
738
        if err != nil {
×
739
                panic(fmt.Sprintf("Error creating custom message: %v", err))
×
740
        }
741

UNCOV
742
        return msg
×
743
}
744

745
// A compile time check to ensure DynAck implements the lnwire.TestMessage
746
// interface.
747
var _ TestMessage = (*DynAck)(nil)
748

749
// RandTestMessage populates the message with random data suitable for testing.
750
// It uses the rapid testing framework to generate random values.
751
//
752
// This is part of the TestMessage interface.
UNCOV
753
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
×
UNCOV
754
        msg := &DynAck{
×
UNCOV
755
                ChanID:    RandChannelID(t),
×
UNCOV
756
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
757
        }
×
UNCOV
758

×
UNCOV
759
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
760

×
UNCOV
761
        if includeLocalNonce {
×
UNCOV
762
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
×
UNCOV
763
        }
×
764

UNCOV
765
        return msg
×
766
}
767

768
// A compile time check to ensure DynPropose implements the lnwire.TestMessage
769
// interface.
770
var _ TestMessage = (*DynPropose)(nil)
771

772
// RandTestMessage populates the message with random data suitable for testing.
773
// It uses the rapid testing framework to generate random values.
774
//
775
// This is part of the TestMessage interface.
UNCOV
776
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
×
UNCOV
777
        msg := &DynPropose{
×
UNCOV
778
                ChanID:    RandChannelID(t),
×
UNCOV
779
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
UNCOV
780
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
781
        }
×
UNCOV
782

×
UNCOV
783
        // Randomly decide which optional fields to include
×
UNCOV
784
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
UNCOV
785
        includeMaxValueInFlight := rapid.Bool().Draw(
×
UNCOV
786
                t, "includeMaxValueInFlight",
×
UNCOV
787
        )
×
UNCOV
788
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
UNCOV
789
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
UNCOV
790
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
UNCOV
791
                t, "includeMaxAcceptedHTLCs",
×
UNCOV
792
        )
×
UNCOV
793
        includeFundingKey := rapid.Bool().Draw(t, "includeFundingKey")
×
UNCOV
794
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
UNCOV
795
        includeKickoffFeerate := rapid.Bool().Draw(t, "includeKickoffFeerate")
×
UNCOV
796

×
UNCOV
797
        // Generate random values for each included field
×
UNCOV
798
        if includeDustLimit {
×
UNCOV
799
                dl := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
UNCOV
800
                msg.DustLimit = fn.Some(dl)
×
UNCOV
801
        }
×
802

UNCOV
803
        if includeMaxValueInFlight {
×
UNCOV
804
                mvif := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
UNCOV
805
                msg.MaxValueInFlight = fn.Some(mvif)
×
UNCOV
806
        }
×
807

UNCOV
808
        if includeChannelReserve {
×
UNCOV
809
                cr := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
UNCOV
810
                msg.ChannelReserve = fn.Some(cr)
×
UNCOV
811
        }
×
812

UNCOV
813
        if includeCsvDelay {
×
UNCOV
814
                cd := rapid.Uint16().Draw(t, "csvDelay")
×
UNCOV
815
                msg.CsvDelay = fn.Some(cd)
×
UNCOV
816
        }
×
817

UNCOV
818
        if includeMaxAcceptedHTLCs {
×
UNCOV
819
                mah := rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
UNCOV
820
                msg.MaxAcceptedHTLCs = fn.Some(mah)
×
UNCOV
821
        }
×
822

UNCOV
823
        if includeFundingKey {
×
UNCOV
824
                msg.FundingKey = fn.Some(*RandPubKey(t))
×
UNCOV
825
        }
×
826

UNCOV
827
        if includeChannelType {
×
UNCOV
828
                msg.ChannelType = fn.Some(*RandChannelType(t))
×
UNCOV
829
        }
×
830

UNCOV
831
        if includeKickoffFeerate {
×
UNCOV
832
                kf := chainfee.SatPerKWeight(rapid.Uint32().Draw(
×
UNCOV
833
                        t, "kickoffFeerate"),
×
UNCOV
834
                )
×
UNCOV
835
                msg.KickoffFeerate = fn.Some(kf)
×
UNCOV
836
        }
×
837

UNCOV
838
        return msg
×
839
}
840

841
// A compile time check to ensure DynReject implements the lnwire.TestMessage
842
// interface.
843
var _ TestMessage = (*DynReject)(nil)
844

845
// RandTestMessage populates the message with random data suitable for testing.
846
// It uses the rapid testing framework to generate random values.
847
//
848
// This is part of the TestMessage interface.
UNCOV
849
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
×
UNCOV
850
        featureVec := NewRawFeatureVector()
×
UNCOV
851

×
UNCOV
852
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
×
UNCOV
853
        for i := 0; i < numFeatures; i++ {
×
UNCOV
854
                bit := FeatureBit(
×
UNCOV
855
                        rapid.IntRange(0, 31).Draw(
×
UNCOV
856
                                t, fmt.Sprintf("rejectionBit-%d", i),
×
UNCOV
857
                        ),
×
UNCOV
858
                )
×
UNCOV
859
                featureVec.Set(bit)
×
UNCOV
860
        }
×
861

UNCOV
862
        var extraData ExtraOpaqueData
×
UNCOV
863
        randData := RandExtraOpaqueData(t, nil)
×
UNCOV
864
        if len(randData) > 0 {
×
UNCOV
865
                extraData = randData
×
UNCOV
866
        }
×
867

UNCOV
868
        return &DynReject{
×
UNCOV
869
                ChanID:           RandChannelID(t),
×
UNCOV
870
                UpdateRejections: *featureVec,
×
UNCOV
871
                ExtraData:        extraData,
×
UNCOV
872
        }
×
873
}
874

875
// A compile time check to ensure FundingCreated implements the TestMessage
876
// interface.
877
var _ TestMessage = (*FundingCreated)(nil)
878

879
// RandTestMessage populates the message with random data suitable for testing.
880
// It uses the rapid testing framework to generate random values.
881
//
882
// This is part of the TestMessage interface.
UNCOV
883
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
×
UNCOV
884
        var pendingChanID [32]byte
×
UNCOV
885
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
886
                t, "pendingChanID",
×
UNCOV
887
        )
×
UNCOV
888
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
889

×
UNCOV
890
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
UNCOV
891
        var partialSig OptPartialSigWithNonceTLV
×
UNCOV
892
        var commitSig Sig
×
UNCOV
893

×
UNCOV
894
        if includePartialSig {
×
UNCOV
895
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
896
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
897

×
UNCOV
898
                // When using partial sig, CommitSig should be empty/blank.
×
UNCOV
899
                commitSig = Sig{}
×
UNCOV
900
        } else {
×
UNCOV
901
                commitSig = RandSignature(t)
×
UNCOV
902
        }
×
903

UNCOV
904
        return &FundingCreated{
×
UNCOV
905
                PendingChannelID: pendingChanID,
×
UNCOV
906
                FundingPoint:     RandOutPoint(t),
×
UNCOV
907
                CommitSig:        commitSig,
×
UNCOV
908
                PartialSig:       partialSig,
×
UNCOV
909
                ExtraData:        RandExtraOpaqueData(t, nil),
×
UNCOV
910
        }
×
911
}
912

913
// A compile time check to ensure FundingSigned implements the
914
// lnwire.TestMessage interface.
915
var _ TestMessage = (*FundingSigned)(nil)
916

917
// RandTestMessage populates the message with random data suitable for testing.
918
// It uses the rapid testing framework to generate random values.
919
//
920
// This is part of the TestMessage interface.
UNCOV
921
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
×
UNCOV
922
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
UNCOV
923

×
UNCOV
924
        msg := &FundingSigned{
×
UNCOV
925
                ChanID:    RandChannelID(t),
×
UNCOV
926
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
927
        }
×
UNCOV
928

×
UNCOV
929
        if usePartialSig {
×
UNCOV
930
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
931
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
932

×
UNCOV
933
                msg.CommitSig = Sig{}
×
UNCOV
934
        } else {
×
UNCOV
935
                msg.CommitSig = RandSignature(t)
×
UNCOV
936
        }
×
937

UNCOV
938
        return msg
×
939
}
940

941
// A compile time check to ensure GossipTimestampRange implements the
942
// lnwire.TestMessage interface.
943
var _ TestMessage = (*GossipTimestampRange)(nil)
944

945
// RandTestMessage populates the message with random data suitable for testing.
946
// It uses the rapid testing framework to generate random values.
947
//
948
// This is part of the TestMessage interface.
UNCOV
949
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
950
        var chainHash chainhash.Hash
×
UNCOV
951
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
952
        copy(chainHash[:], hashBytes)
×
UNCOV
953

×
UNCOV
954
        msg := &GossipTimestampRange{
×
UNCOV
955
                ChainHash:      chainHash,
×
UNCOV
956
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
×
UNCOV
957
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
×
UNCOV
958
                ExtraData:      RandExtraOpaqueData(t, nil),
×
UNCOV
959
        }
×
UNCOV
960

×
UNCOV
961
        includeFirstBlockHeight := rapid.Bool().Draw(
×
UNCOV
962
                t, "includeFirstBlockHeight",
×
UNCOV
963
        )
×
UNCOV
964
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
×
UNCOV
965

×
UNCOV
966
        if includeFirstBlockHeight {
×
UNCOV
967
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
×
UNCOV
968
                msg.FirstBlockHeight = tlv.SomeRecordT(
×
UNCOV
969
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
×
UNCOV
970
                )
×
UNCOV
971
        }
×
972

UNCOV
973
        if includeBlockRange {
×
UNCOV
974
                blockRange := rapid.Uint32().Draw(t, "blockRange")
×
UNCOV
975
                msg.BlockRange = tlv.SomeRecordT(
×
UNCOV
976
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
×
UNCOV
977
                )
×
UNCOV
978
        }
×
979

UNCOV
980
        return msg
×
981
}
982

983
// RandTestMessage populates the message with random data suitable for testing.
984
// It uses the rapid testing framework to generate random values.
985
//
986
// This is part of the TestMessage interface.
UNCOV
987
func (msg *Init) RandTestMessage(t *rapid.T) Message {
×
UNCOV
988
        global := NewRawFeatureVector()
×
UNCOV
989
        local := NewRawFeatureVector()
×
UNCOV
990

×
UNCOV
991
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
×
UNCOV
992
        for i := 0; i < numGlobalFeatures; i++ {
×
UNCOV
993
                bit := FeatureBit(
×
UNCOV
994
                        rapid.IntRange(0, 100).Draw(
×
UNCOV
995
                                t, fmt.Sprintf("globalFeatureBit%d", i),
×
UNCOV
996
                        ),
×
UNCOV
997
                )
×
UNCOV
998
                global.Set(bit)
×
UNCOV
999
        }
×
1000

UNCOV
1001
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
×
UNCOV
1002
        for i := 0; i < numLocalFeatures; i++ {
×
UNCOV
1003
                bit := FeatureBit(
×
UNCOV
1004
                        rapid.IntRange(0, 100).Draw(
×
UNCOV
1005
                                t, fmt.Sprintf("localFeatureBit%d", i),
×
UNCOV
1006
                        ),
×
UNCOV
1007
                )
×
UNCOV
1008
                local.Set(bit)
×
UNCOV
1009
        }
×
1010

UNCOV
1011
        return NewInitMessage(global, local)
×
1012
}
1013

1014
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1015
// interface.
1016
var _ TestMessage = (*KickoffSig)(nil)
1017

1018
// RandTestMessage populates the message with random data suitable for testing.
1019
// It uses the rapid testing framework to generate random values.
1020
//
1021
// This is part of the TestMessage interface.
UNCOV
1022
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1023
        return &KickoffSig{
×
UNCOV
1024
                ChanID:    RandChannelID(t),
×
UNCOV
1025
                Signature: RandSignature(t),
×
UNCOV
1026
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1027
        }
×
UNCOV
1028
}
×
1029

1030
// A compile time check to ensure NodeAnnouncement implements the
1031
// lnwire.TestMessage interface.
1032
var _ TestMessage = (*NodeAnnouncement)(nil)
1033

1034
// RandTestMessage populates the message with random data suitable for testing.
1035
// It uses the rapid testing framework to generate random values.
1036
//
1037
// This is part of the TestMessage interface.
UNCOV
1038
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1039
        // Generate random compressed public key for node ID
×
UNCOV
1040
        pubKey := RandPubKey(t)
×
UNCOV
1041
        var nodeID [33]byte
×
UNCOV
1042
        copy(nodeID[:], pubKey.SerializeCompressed())
×
UNCOV
1043

×
UNCOV
1044
        // Generate random RGB color
×
UNCOV
1045
        rgbColor := color.RGBA{
×
UNCOV
1046
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
×
UNCOV
1047
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
×
UNCOV
1048
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
×
UNCOV
1049
        }
×
UNCOV
1050

×
UNCOV
1051
        return &NodeAnnouncement{
×
UNCOV
1052
                Signature: RandSignature(t),
×
UNCOV
1053
                Features:  RandFeatureVector(t),
×
UNCOV
1054
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
1055
                        t, "timestamp"),
×
UNCOV
1056
                ),
×
UNCOV
1057
                NodeID:          nodeID,
×
UNCOV
1058
                RGBColor:        rgbColor,
×
UNCOV
1059
                Alias:           RandNodeAlias(t),
×
UNCOV
1060
                Addresses:       RandNetAddrs(t),
×
UNCOV
1061
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
1062
        }
×
UNCOV
1063
}
×
1064

1065
// A compile time check to ensure OpenChannel implements the TestMessage
1066
// interface.
1067
var _ TestMessage = (*OpenChannel)(nil)
1068

1069
// RandTestMessage populates the message with random data suitable for testing.
1070
// It uses the rapid testing framework to generate random values.
1071
//
1072
// This is part of the TestMessage interface.
UNCOV
1073
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1074
        chainHash := RandChainHash(t)
×
UNCOV
1075
        var hash chainhash.Hash
×
UNCOV
1076
        copy(hash[:], chainHash[:])
×
UNCOV
1077

×
UNCOV
1078
        var pendingChanID [32]byte
×
UNCOV
1079
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
1080
                t, "pendingChanID",
×
UNCOV
1081
        )
×
UNCOV
1082
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
1083

×
UNCOV
1084
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
UNCOV
1085
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
×
UNCOV
1086
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
1087

×
UNCOV
1088
        var channelFlags FundingFlag
×
UNCOV
1089
        if rapid.Bool().Draw(t, "announceChannel") {
×
UNCOV
1090
                channelFlags |= FFAnnounceChannel
×
UNCOV
1091
        }
×
1092

UNCOV
1093
        var localNonce OptMusig2NonceTLV
×
UNCOV
1094
        if includeLocalNonce {
×
UNCOV
1095
                nonce := RandMusig2Nonce(t)
×
UNCOV
1096
                localNonce = tlv.SomeRecordT(
×
UNCOV
1097
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
UNCOV
1098
                )
×
UNCOV
1099
        }
×
1100

UNCOV
1101
        var channelType *ChannelType
×
UNCOV
1102
        if includeChannelType {
×
UNCOV
1103
                channelType = RandChannelType(t)
×
UNCOV
1104
        }
×
1105

UNCOV
1106
        var leaseExpiry *LeaseExpiry
×
UNCOV
1107
        if includeLeaseExpiry {
×
UNCOV
1108
                leaseExpiry = RandLeaseExpiry(t)
×
UNCOV
1109
        }
×
1110

UNCOV
1111
        return &OpenChannel{
×
UNCOV
1112
                ChainHash:        hash,
×
UNCOV
1113
                PendingChannelID: pendingChanID,
×
UNCOV
1114
                FundingAmount: btcutil.Amount(
×
UNCOV
1115
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
×
UNCOV
1116
                ),
×
UNCOV
1117
                PushAmount: MilliSatoshi(
×
UNCOV
1118
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
×
UNCOV
1119
                ),
×
UNCOV
1120
                DustLimit: btcutil.Amount(
×
UNCOV
1121
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
×
UNCOV
1122
                ),
×
UNCOV
1123
                MaxValueInFlight: MilliSatoshi(
×
UNCOV
1124
                        rapid.IntRange(10000, 1000000).Draw(
×
UNCOV
1125
                                t, "maxValueInFlight",
×
UNCOV
1126
                        ),
×
UNCOV
1127
                ),
×
UNCOV
1128
                ChannelReserve: btcutil.Amount(
×
UNCOV
1129
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
×
UNCOV
1130
                ),
×
UNCOV
1131
                HtlcMinimum: MilliSatoshi(
×
UNCOV
1132
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
×
UNCOV
1133
                ),
×
UNCOV
1134
                FeePerKiloWeight: uint32(
×
UNCOV
1135
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
×
UNCOV
1136
                ),
×
UNCOV
1137
                CsvDelay: uint16(
×
UNCOV
1138
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
×
UNCOV
1139
                ),
×
UNCOV
1140
                MaxAcceptedHTLCs: uint16(
×
UNCOV
1141
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
×
UNCOV
1142
                ),
×
UNCOV
1143
                FundingKey:            RandPubKey(t),
×
UNCOV
1144
                RevocationPoint:       RandPubKey(t),
×
UNCOV
1145
                PaymentPoint:          RandPubKey(t),
×
UNCOV
1146
                DelayedPaymentPoint:   RandPubKey(t),
×
UNCOV
1147
                HtlcPoint:             RandPubKey(t),
×
UNCOV
1148
                FirstCommitmentPoint:  RandPubKey(t),
×
UNCOV
1149
                ChannelFlags:          channelFlags,
×
UNCOV
1150
                UpfrontShutdownScript: RandDeliveryAddress(t),
×
UNCOV
1151
                ChannelType:           channelType,
×
UNCOV
1152
                LeaseExpiry:           leaseExpiry,
×
UNCOV
1153
                LocalNonce:            localNonce,
×
UNCOV
1154
                ExtraData:             RandExtraOpaqueData(t, nil),
×
UNCOV
1155
        }
×
1156
}
1157

1158
// A compile time check to ensure Ping implements the lnwire.TestMessage
1159
// interface.
1160
var _ TestMessage = (*Ping)(nil)
1161

1162
// RandTestMessage populates the message with random data suitable for testing.
1163
// It uses the rapid testing framework to generate random values.
1164
//
1165
// This is part of the TestMessage interface.
UNCOV
1166
func (p *Ping) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1167
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
×
UNCOV
1168
                t, "numPongBytes"),
×
UNCOV
1169
        )
×
UNCOV
1170

×
UNCOV
1171
        // Generate padding bytes (but keeping within allowed message size)
×
UNCOV
1172
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
×
UNCOV
1173
        maxPaddingLen := MaxMsgBody - 4
×
UNCOV
1174
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
×
UNCOV
1175
                t, "paddingLen",
×
UNCOV
1176
        )
×
UNCOV
1177
        padding := make(PingPayload, paddingLen)
×
UNCOV
1178

×
UNCOV
1179
        // Fill padding with random bytes
×
UNCOV
1180
        for i := 0; i < paddingLen; i++ {
×
UNCOV
1181
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
×
UNCOV
1182
                        t, fmt.Sprintf("paddingByte%d", i)),
×
UNCOV
1183
                )
×
UNCOV
1184
        }
×
1185

UNCOV
1186
        return &Ping{
×
UNCOV
1187
                NumPongBytes: numPongBytes,
×
UNCOV
1188
                PaddingBytes: padding,
×
UNCOV
1189
        }
×
1190
}
1191

1192
// A compile time check to ensure Pong implements the lnwire.TestMessage
1193
// interface.
1194
var _ TestMessage = (*Pong)(nil)
1195

1196
// RandTestMessage populates the message with random data suitable for testing.
1197
// It uses the rapid testing framework to generate random values.
1198
//
1199
// This is part of the TestMessage interface.
UNCOV
1200
func (p *Pong) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1201
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
×
UNCOV
1202
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
×
UNCOV
1203
                t, "pongPayload",
×
UNCOV
1204
        )
×
UNCOV
1205

×
UNCOV
1206
        return &Pong{
×
UNCOV
1207
                PongBytes: payload,
×
UNCOV
1208
        }
×
UNCOV
1209
}
×
1210

1211
// A compile time check to ensure QueryChannelRange implements the
1212
// lnwire.TestMessage interface.
1213
var _ TestMessage = (*QueryChannelRange)(nil)
1214

1215
// RandTestMessage populates the message with random data suitable for testing.
1216
// It uses the rapid testing framework to generate random values.
1217
//
1218
// This is part of the TestMessage interface.
UNCOV
1219
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1220
        msg := &QueryChannelRange{
×
UNCOV
1221
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
UNCOV
1222
                        t, "firstBlockHeight"),
×
UNCOV
1223
                ),
×
UNCOV
1224
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
UNCOV
1225
                        t, "numBlocks"),
×
UNCOV
1226
                ),
×
UNCOV
1227
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1228
        }
×
UNCOV
1229

×
UNCOV
1230
        // Generate chain hash
×
UNCOV
1231
        chainHash := RandChainHash(t)
×
UNCOV
1232
        var chainHashObj chainhash.Hash
×
UNCOV
1233
        copy(chainHashObj[:], chainHash[:])
×
UNCOV
1234
        msg.ChainHash = chainHashObj
×
UNCOV
1235

×
UNCOV
1236
        // Randomly include QueryOptions
×
UNCOV
1237
        if rapid.Bool().Draw(t, "includeQueryOptions") {
×
UNCOV
1238
                queryOptions := &QueryOptions{}
×
UNCOV
1239
                *queryOptions = QueryOptions(*RandFeatureVector(t))
×
UNCOV
1240
                msg.QueryOptions = queryOptions
×
UNCOV
1241
        }
×
1242

UNCOV
1243
        return msg
×
1244
}
1245

1246
// A compile time check to ensure QueryShortChanIDs implements the
1247
// lnwire.TestMessage interface.
1248
var _ TestMessage = (*QueryShortChanIDs)(nil)
1249

1250
// RandTestMessage populates the message with random data suitable for testing.
1251
// It uses the rapid testing framework to generate random values.
1252
//
1253
// This is part of the TestMessage interface.
UNCOV
1254
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1255
        var chainHash chainhash.Hash
×
UNCOV
1256
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
1257
        copy(chainHash[:], hashBytes)
×
UNCOV
1258

×
UNCOV
1259
        encodingType := EncodingSortedPlain
×
UNCOV
1260
        if rapid.Bool().Draw(t, "useZlibEncoding") {
×
UNCOV
1261
                encodingType = EncodingSortedZlib
×
UNCOV
1262
        }
×
1263

UNCOV
1264
        msg := &QueryShortChanIDs{
×
UNCOV
1265
                ChainHash:    chainHash,
×
UNCOV
1266
                EncodingType: encodingType,
×
UNCOV
1267
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
1268
                noSort:       false,
×
UNCOV
1269
        }
×
UNCOV
1270

×
UNCOV
1271
        numIDs := rapid.IntRange(2, 20).Draw(t, "numShortChanIDs")
×
UNCOV
1272

×
UNCOV
1273
        // Generate sorted short channel IDs.
×
UNCOV
1274
        shortChanIDs := make([]ShortChannelID, numIDs)
×
UNCOV
1275
        for i := 0; i < numIDs; i++ {
×
UNCOV
1276
                shortChanIDs[i] = RandShortChannelID(t)
×
UNCOV
1277

×
UNCOV
1278
                // Ensure they're properly sorted.
×
UNCOV
1279
                if i > 0 && shortChanIDs[i].ToUint64() <=
×
UNCOV
1280
                        shortChanIDs[i-1].ToUint64() {
×
UNCOV
1281

×
UNCOV
1282
                        // Ensure this ID is larger than the previous one.
×
UNCOV
1283
                        shortChanIDs[i] = NewShortChanIDFromInt(
×
UNCOV
1284
                                shortChanIDs[i-1].ToUint64() + 1,
×
UNCOV
1285
                        )
×
UNCOV
1286
                }
×
1287
        }
1288

UNCOV
1289
        msg.ShortChanIDs = shortChanIDs
×
UNCOV
1290

×
UNCOV
1291
        return msg
×
1292
}
1293

1294
// A compile time check to ensure ReplyChannelRange implements the
1295
// lnwire.TestMessage interface.
1296
var _ TestMessage = (*ReplyChannelRange)(nil)
1297

1298
// RandTestMessage populates the message with random data suitable for testing.
1299
// It uses the rapid testing framework to generate random values.
1300
//
1301
// This is part of the TestMessage interface.
UNCOV
1302
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1303
        msg := &ReplyChannelRange{
×
UNCOV
1304
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
UNCOV
1305
                        t, "firstBlockHeight"),
×
UNCOV
1306
                ),
×
UNCOV
1307
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
UNCOV
1308
                        t, "numBlocks"),
×
UNCOV
1309
                ),
×
UNCOV
1310
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
×
UNCOV
1311
                EncodingType: QueryEncoding(
×
UNCOV
1312
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
×
UNCOV
1313
                ),
×
UNCOV
1314
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1315
        }
×
UNCOV
1316

×
UNCOV
1317
        msg.ChainHash = RandChainHash(t)
×
UNCOV
1318

×
UNCOV
1319
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
×
UNCOV
1320
        if numShortChanIDs == 0 {
×
UNCOV
1321
                return msg
×
UNCOV
1322
        }
×
1323

UNCOV
1324
        scidSet := fn.NewSet[ShortChannelID]()
×
UNCOV
1325
        scids := make([]ShortChannelID, numShortChanIDs)
×
UNCOV
1326
        for i := 0; i < numShortChanIDs; i++ {
×
UNCOV
1327
                scid := RandShortChannelID(t)
×
UNCOV
1328
                for scidSet.Contains(scid) {
×
UNCOV
1329
                        scid = RandShortChannelID(t)
×
UNCOV
1330
                }
×
1331

UNCOV
1332
                scids[i] = scid
×
UNCOV
1333

×
UNCOV
1334
                scidSet.Add(scid)
×
1335
        }
1336

1337
        // Make sure there're no duplicates.
UNCOV
1338
        msg.ShortChanIDs = scids
×
UNCOV
1339

×
UNCOV
1340
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
×
UNCOV
1341
                msg.Timestamps = make(Timestamps, numShortChanIDs)
×
UNCOV
1342
                for i := 0; i < numShortChanIDs; i++ {
×
UNCOV
1343
                        msg.Timestamps[i] = ChanUpdateTimestamps{
×
UNCOV
1344
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
×
UNCOV
1345
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
×
UNCOV
1346
                        }
×
UNCOV
1347
                }
×
1348
        }
1349

UNCOV
1350
        return msg
×
1351
}
1352

1353
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1354
// lnwire.TestMessage interface.
1355
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1356

1357
// RandTestMessage populates the message with random data suitable for testing.
1358
// It uses the rapid testing framework to generate random values.
1359
//
1360
// This is part of the TestMessage interface.
UNCOV
1361
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1362
        var chainHash chainhash.Hash
×
UNCOV
1363
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
1364
        copy(chainHash[:], hashBytes)
×
UNCOV
1365

×
UNCOV
1366
        complete := uint8(rapid.IntRange(0, 1).Draw(t, "complete"))
×
UNCOV
1367

×
UNCOV
1368
        return &ReplyShortChanIDsEnd{
×
UNCOV
1369
                ChainHash: chainHash,
×
UNCOV
1370
                Complete:  complete,
×
UNCOV
1371
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1372
        }
×
UNCOV
1373
}
×
1374

1375
// RandTestMessage returns a RevokeAndAck message populated with random data.
1376
//
1377
// This is part of the TestMessage interface.
UNCOV
1378
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1379
        msg := NewRevokeAndAck()
×
UNCOV
1380

×
UNCOV
1381
        var chanID ChannelID
×
UNCOV
1382
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
×
UNCOV
1383
        copy(chanID[:], bytes)
×
UNCOV
1384
        msg.ChanID = chanID
×
UNCOV
1385

×
UNCOV
1386
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
×
UNCOV
1387
        copy(msg.Revocation[:], revBytes)
×
UNCOV
1388

×
UNCOV
1389
        msg.NextRevocationKey = RandPubKey(t)
×
UNCOV
1390

×
UNCOV
1391
        if rapid.Bool().Draw(t, "includeLocalNonce") {
×
UNCOV
1392
                var nonce Musig2Nonce
×
UNCOV
1393
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
1394
                        t, "nonce",
×
UNCOV
1395
                )
×
UNCOV
1396
                copy(nonce[:], nonceBytes)
×
UNCOV
1397

×
UNCOV
1398
                msg.LocalNonce = tlv.SomeRecordT(
×
UNCOV
1399
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
UNCOV
1400
                )
×
UNCOV
1401
        }
×
1402

UNCOV
1403
        return msg
×
1404
}
1405

1406
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1407
// interface.
1408
var _ TestMessage = (*Shutdown)(nil)
1409

1410
// RandTestMessage populates the message with random data suitable for testing.
1411
// It uses the rapid testing framework to generate random values.
1412
//
1413
// This is part of the TestMessage interface.
UNCOV
1414
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1415
        // Generate random delivery address
×
UNCOV
1416
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
×
UNCOV
1417
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
×
UNCOV
1418

×
UNCOV
1419
        // Generate random address length based on type
×
UNCOV
1420
        var addrLen int
×
UNCOV
1421
        switch addrType {
×
1422
        // P2PKH
UNCOV
1423
        case 0:
×
UNCOV
1424
                addrLen = 25
×
1425
        // P2SH
UNCOV
1426
        case 1:
×
UNCOV
1427
                addrLen = 23
×
1428
        // P2WPKH
UNCOV
1429
        case 2:
×
UNCOV
1430
                addrLen = 22
×
1431
        // P2WSH
UNCOV
1432
        case 3:
×
UNCOV
1433
                addrLen = 34
×
1434
        // P2TR
UNCOV
1435
        case 4:
×
UNCOV
1436
                addrLen = 34
×
1437
        }
1438

UNCOV
1439
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
×
UNCOV
1440
                t, "address",
×
UNCOV
1441
        )
×
UNCOV
1442

×
UNCOV
1443
        // Randomly decide whether to include a shutdown nonce
×
UNCOV
1444
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
×
UNCOV
1445
        var shutdownNonce ShutdownNonceTLV
×
UNCOV
1446

×
UNCOV
1447
        if includeNonce {
×
UNCOV
1448
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
×
UNCOV
1449
        }
×
1450

UNCOV
1451
        cr, _ := RandCustomRecords(t, nil, true)
×
UNCOV
1452

×
UNCOV
1453
        return &Shutdown{
×
UNCOV
1454
                ChannelID:     RandChannelID(t),
×
UNCOV
1455
                Address:       addr,
×
UNCOV
1456
                ShutdownNonce: shutdownNonce,
×
UNCOV
1457
                CustomRecords: cr,
×
UNCOV
1458
        }
×
1459
}
1460

1461
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1462
// interface.
1463
var _ TestMessage = (*Stfu)(nil)
1464

1465
// RandTestMessage populates the message with random data suitable for testing.
1466
// It uses the rapid testing framework to generate random values.
1467
//
1468
// This is part of the TestMessage interface.
UNCOV
1469
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1470
        m := &Stfu{
×
UNCOV
1471
                ChanID:    RandChannelID(t),
×
UNCOV
1472
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
UNCOV
1473
        }
×
UNCOV
1474

×
UNCOV
1475
        extraData := RandExtraOpaqueData(t, nil)
×
UNCOV
1476
        if len(extraData) > 0 {
×
UNCOV
1477
                m.ExtraData = extraData
×
UNCOV
1478
        }
×
1479

UNCOV
1480
        return m
×
1481
}
1482

1483
// A compile time check to ensure UpdateAddHTLC implements the
1484
// lnwire.TestMessage interface.
1485
var _ TestMessage = (*UpdateAddHTLC)(nil)
1486

1487
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1488
//
1489
// This is part of the TestMessage interface.
UNCOV
1490
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1491
        msg := &UpdateAddHTLC{
×
UNCOV
1492
                ChanID: RandChannelID(t),
×
UNCOV
1493
                ID:     rapid.Uint64().Draw(t, "id"),
×
UNCOV
1494
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
×
UNCOV
1495
                Expiry: rapid.Uint32().Draw(t, "expiry"),
×
UNCOV
1496
        }
×
UNCOV
1497

×
UNCOV
1498
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
×
UNCOV
1499
        copy(msg.PaymentHash[:], hashBytes)
×
UNCOV
1500

×
UNCOV
1501
        onionBytes := rapid.SliceOfN(
×
UNCOV
1502
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
×
UNCOV
1503
        ).Draw(t, "onionBlob")
×
UNCOV
1504
        copy(msg.OnionBlob[:], onionBytes)
×
UNCOV
1505

×
UNCOV
1506
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
×
UNCOV
1507
        if numRecords > 0 {
×
UNCOV
1508
                msg.CustomRecords, _ = RandCustomRecords(t, nil, true)
×
UNCOV
1509
        }
×
1510

1511
        // 50/50 chance to add a blinding point
UNCOV
1512
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
×
UNCOV
1513
                pubKey := RandPubKey(t)
×
UNCOV
1514

×
UNCOV
1515
                msg.BlindingPoint = tlv.SomeRecordT(
×
UNCOV
1516
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
×
UNCOV
1517
                )
×
UNCOV
1518
        }
×
1519

UNCOV
1520
        return msg
×
1521
}
1522

1523
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1524
// interface.
1525
var _ TestMessage = (*UpdateFailHTLC)(nil)
1526

1527
// RandTestMessage populates the message with random data suitable for testing.
1528
// It uses the rapid testing framework to generate random values.
1529
//
1530
// This is part of the TestMessage interface.
UNCOV
1531
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1532
        return &UpdateFailHTLC{
×
UNCOV
1533
                ChanID:    RandChannelID(t),
×
UNCOV
1534
                ID:        rapid.Uint64().Draw(t, "id"),
×
UNCOV
1535
                Reason:    RandOpaqueReason(t),
×
UNCOV
1536
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1537
        }
×
UNCOV
1538
}
×
1539

1540
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1541
// TestMessage interface.
1542
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1543

1544
// RandTestMessage populates the message with random data suitable for testing.
1545
// It uses the rapid testing framework to generate random values.
1546
//
1547
// This is part of the TestMessage interface.
UNCOV
1548
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1549
        return &UpdateFailMalformedHTLC{
×
UNCOV
1550
                ChanID:       RandChannelID(t),
×
UNCOV
1551
                ID:           rapid.Uint64().Draw(t, "id"),
×
UNCOV
1552
                ShaOnionBlob: RandSHA256Hash(t),
×
UNCOV
1553
                FailureCode:  RandFailCode(t),
×
UNCOV
1554
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
1555
        }
×
UNCOV
1556
}
×
1557

1558
// A compile time check to ensure UpdateFee implements the TestMessage
1559
// interface.
1560
var _ TestMessage = (*UpdateFee)(nil)
1561

1562
// RandTestMessage populates the message with random data suitable for testing.
1563
// It uses the rapid testing framework to generate random values.
1564
//
1565
// This is part of the TestMessage interface.
UNCOV
1566
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1567
        return &UpdateFee{
×
UNCOV
1568
                ChanID:    RandChannelID(t),
×
UNCOV
1569
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
×
UNCOV
1570
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1571
        }
×
UNCOV
1572
}
×
1573

1574
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1575
// interface.
1576
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1577

1578
// RandTestMessage populates the message with random data suitable for testing.
1579
// It uses the rapid testing framework to generate random values.
1580
//
1581
// This is part of the TestMessage interface.
UNCOV
1582
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1583
        msg := &UpdateFulfillHTLC{
×
UNCOV
1584
                ChanID:          RandChannelID(t),
×
UNCOV
1585
                ID:              rapid.Uint64().Draw(t, "id"),
×
UNCOV
1586
                PaymentPreimage: RandPaymentPreimage(t),
×
UNCOV
1587
        }
×
UNCOV
1588

×
UNCOV
1589
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
×
UNCOV
1590
        msg.CustomRecords = cr
×
UNCOV
1591

×
UNCOV
1592
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
UNCOV
1593
        if len(randData) > 0 {
×
UNCOV
1594
                msg.ExtraData = randData
×
UNCOV
1595
        }
×
1596

UNCOV
1597
        return msg
×
1598
}
1599

1600
// A compile time check to ensure Warning implements the lnwire.TestMessage
1601
// interface.
1602
var _ TestMessage = (*Warning)(nil)
1603

1604
// RandTestMessage populates the message with random data suitable for testing.
1605
// It uses the rapid testing framework to generate random values.
1606
//
1607
// This is part of the TestMessage interface.
UNCOV
1608
func (c *Warning) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1609
        msg := &Warning{
×
UNCOV
1610
                ChanID: RandChannelID(t),
×
UNCOV
1611
        }
×
UNCOV
1612

×
UNCOV
1613
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
UNCOV
1614
        if useASCII {
×
UNCOV
1615
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
UNCOV
1616
                data := make([]byte, length)
×
UNCOV
1617
                for i := 0; i < length; i++ {
×
UNCOV
1618
                        data[i] = byte(
×
UNCOV
1619
                                rapid.IntRange(32, 126).Draw(
×
UNCOV
1620
                                        t, fmt.Sprintf("warningDataByte-%d", i),
×
UNCOV
1621
                                ),
×
UNCOV
1622
                        )
×
UNCOV
1623
                }
×
UNCOV
1624
                msg.Data = data
×
UNCOV
1625
        } else {
×
UNCOV
1626
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
UNCOV
1627
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
×
UNCOV
1628
                        t, "warningData",
×
UNCOV
1629
                )
×
UNCOV
1630
        }
×
1631

UNCOV
1632
        return msg
×
1633
}
1634

1635
// A compile time check to ensure Error implements the lnwire.TestMessage
1636
// interface.
1637
var _ TestMessage = (*Error)(nil)
1638

1639
// RandTestMessage populates the message with random data suitable for testing.
1640
// It uses the rapid testing framework to generate random values.
1641
//
1642
// This is part of the TestMessage interface.
UNCOV
1643
func (c *Error) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1644
        msg := &Error{
×
UNCOV
1645
                ChanID: RandChannelID(t),
×
UNCOV
1646
        }
×
UNCOV
1647

×
UNCOV
1648
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
UNCOV
1649
        if useASCII {
×
UNCOV
1650
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
UNCOV
1651
                data := make([]byte, length)
×
UNCOV
1652
                for i := 0; i < length; i++ {
×
UNCOV
1653
                        data[i] = byte(
×
UNCOV
1654
                                rapid.IntRange(32, 126).Draw(
×
UNCOV
1655
                                        t, fmt.Sprintf("errorDataByte-%d", i),
×
UNCOV
1656
                                ),
×
UNCOV
1657
                        )
×
UNCOV
1658
                }
×
UNCOV
1659
                msg.Data = data
×
UNCOV
1660
        } else {
×
UNCOV
1661
                // Generate random binary data
×
UNCOV
1662
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
UNCOV
1663
                msg.Data = rapid.SliceOfN(
×
UNCOV
1664
                        rapid.Byte(), length, length,
×
UNCOV
1665
                ).Draw(t, "errorData")
×
UNCOV
1666
        }
×
1667

UNCOV
1668
        return msg
×
1669
}
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