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

lightningnetwork / lnd / 19338576814

13 Nov 2025 04:31PM UTC coverage: 65.209% (-0.01%) from 65.219%
19338576814

Pull #10367

github

web-flow
Merge ade491779 into f6005ed35
Pull Request #10367: multi: rename experimental endorsement signal to accountable

65 of 85 new or added lines in 11 files covered. (76.47%)

1775 existing lines in 24 files now uncovered.

137557 of 210947 relevant lines covered (65.21%)

20763.21 hits per line

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

99.8
/lnwire/test_message.go
1
package lnwire
2

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

10
        "github.com/btcsuite/btcd/btcec/v2"
11
        "github.com/btcsuite/btcd/btcutil"
12
        "github.com/btcsuite/btcd/chaincfg/chainhash"
13
        "github.com/lightningnetwork/lnd/fn/v2"
14
        "github.com/lightningnetwork/lnd/tlv"
15
        "github.com/lightningnetwork/lnd/tor"
16
        "github.com/stretchr/testify/require"
17
        "pgregory.net/rapid"
18
)
19

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

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

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

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

101✔
46
        var channelType *ChannelType
101✔
47
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
101✔
48
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
101✔
49
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
101✔
50

101✔
51
        if includeChannelType {
156✔
52
                channelType = RandChannelType(t)
55✔
53
        }
55✔
54

55
        var leaseExpiry *LeaseExpiry
101✔
56
        if includeLeaseExpiry {
151✔
57
                leaseExpiry = RandLeaseExpiry(t)
50✔
58
        }
50✔
59

60
        var localNonce OptMusig2NonceTLV
101✔
61
        if includeLocalNonce {
159✔
62
                nonce := RandMusig2Nonce(t)
58✔
63
                localNonce = tlv.SomeRecordT(
58✔
64
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
58✔
65
                )
58✔
66
        }
58✔
67

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

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

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

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

129
// RandTestMessage populates the message with random data suitable for testing.
130
// It uses the rapid testing framework to generate random values.
131
//
132
// This is part of the TestMessage interface.
133
func (a *AnnounceSignatures2) RandTestMessage(t *rapid.T) Message {
100✔
134
        var (
100✔
135
                chanID = RandChannelID(t)
100✔
136
                scid   = RandShortChannelID(t)
100✔
137
                pSig   = RandPartialSig(t)
100✔
138
        )
100✔
139

100✔
140
        msg := &AnnounceSignatures2{
100✔
141
                ChannelID: tlv.NewRecordT[tlv.TlvType0, ChannelID](
100✔
142
                        chanID,
100✔
143
                ),
100✔
144
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2](scid),
100✔
145
                PartialSignature: tlv.NewRecordT[tlv.TlvType4, PartialSig](
100✔
146
                        *pSig,
100✔
147
                ),
100✔
148
                ExtraSignedFields: make(map[uint64][]byte),
100✔
149
        }
100✔
150

100✔
151
        randRecs, _ := RandSignedRangeRecords(t)
100✔
152
        if len(randRecs) > 0 {
172✔
153
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
72✔
154
        }
72✔
155

156
        return msg
100✔
157
}
158

159
// A compile time check to ensure ChannelAnnouncement1 implements the
160
// TestMessage interface.
161
var _ TestMessage = (*ChannelAnnouncement1)(nil)
162

163
// RandTestMessage populates the message with random data suitable for testing.
164
// It uses the rapid testing framework to generate random values.
165
//
166
// This is part of the TestMessage interface.
167
func (a *ChannelAnnouncement1) RandTestMessage(t *rapid.T) Message {
100✔
168
        // Generate Node IDs and Bitcoin keys (compressed public keys)
100✔
169
        node1PubKey := RandPubKey(t)
100✔
170
        node2PubKey := RandPubKey(t)
100✔
171
        bitcoin1PubKey := RandPubKey(t)
100✔
172
        bitcoin2PubKey := RandPubKey(t)
100✔
173

100✔
174
        // Convert to byte arrays
100✔
175
        var nodeID1, nodeID2, bitcoinKey1, bitcoinKey2 [33]byte
100✔
176
        copy(nodeID1[:], node1PubKey.SerializeCompressed())
100✔
177
        copy(nodeID2[:], node2PubKey.SerializeCompressed())
100✔
178
        copy(bitcoinKey1[:], bitcoin1PubKey.SerializeCompressed())
100✔
179
        copy(bitcoinKey2[:], bitcoin2PubKey.SerializeCompressed())
100✔
180

100✔
181
        // Ensure nodeID1 is numerically less than nodeID2
100✔
182
        // This is a requirement stated in the field description
100✔
183
        if bytes.Compare(nodeID1[:], nodeID2[:]) > 0 {
143✔
184
                nodeID1, nodeID2 = nodeID2, nodeID1
43✔
185
        }
43✔
186

187
        // Generate chain hash
188
        chainHash := RandChainHash(t)
100✔
189
        var hash chainhash.Hash
100✔
190
        copy(hash[:], chainHash[:])
100✔
191

100✔
192
        return &ChannelAnnouncement1{
100✔
193
                NodeSig1:        RandSignature(t),
100✔
194
                NodeSig2:        RandSignature(t),
100✔
195
                BitcoinSig1:     RandSignature(t),
100✔
196
                BitcoinSig2:     RandSignature(t),
100✔
197
                Features:        RandFeatureVector(t),
100✔
198
                ChainHash:       hash,
100✔
199
                ShortChannelID:  RandShortChannelID(t),
100✔
200
                NodeID1:         nodeID1,
100✔
201
                NodeID2:         nodeID2,
100✔
202
                BitcoinKey1:     bitcoinKey1,
100✔
203
                BitcoinKey2:     bitcoinKey2,
100✔
204
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
205
        }
100✔
206
}
207

208
// A compile time check to ensure ChannelAnnouncement2 implements the
209
// lnwire.TestMessage interface.
210
var _ TestMessage = (*ChannelAnnouncement2)(nil)
211

212
// RandTestMessage populates the message with random data suitable for testing.
213
// It uses the rapid testing framework to generate random values.
214
//
215
// This is part of the TestMessage interface.
216
func (c *ChannelAnnouncement2) RandTestMessage(t *rapid.T) Message {
100✔
217
        features := RandFeatureVector(t)
100✔
218
        shortChanID := RandShortChannelID(t)
100✔
219
        capacity := uint64(rapid.IntRange(1, 16777215).Draw(t, "capacity"))
100✔
220

100✔
221
        var nodeID1, nodeID2 [33]byte
100✔
222
        copy(nodeID1[:], RandPubKey(t).SerializeCompressed())
100✔
223
        copy(nodeID2[:], RandPubKey(t).SerializeCompressed())
100✔
224

100✔
225
        // Make sure nodeID1 is numerically less than nodeID2 (as per spec).
100✔
226
        if bytes.Compare(nodeID1[:], nodeID2[:]) > 0 {
146✔
227
                nodeID1, nodeID2 = nodeID2, nodeID1
46✔
228
        }
46✔
229

230
        chainHash := RandChainHash(t)
100✔
231
        var chainHashObj chainhash.Hash
100✔
232
        copy(chainHashObj[:], chainHash[:])
100✔
233

100✔
234
        msg := &ChannelAnnouncement2{
100✔
235
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
100✔
236
                        chainHashObj,
100✔
237
                ),
100✔
238
                Features: tlv.NewRecordT[tlv.TlvType2, RawFeatureVector](
100✔
239
                        *features,
100✔
240
                ),
100✔
241
                ShortChannelID: tlv.NewRecordT[tlv.TlvType4, ShortChannelID](
100✔
242
                        shortChanID,
100✔
243
                ),
100✔
244
                Capacity: tlv.NewPrimitiveRecord[tlv.TlvType6, uint64](
100✔
245
                        capacity,
100✔
246
                ),
100✔
247
                NodeID1: tlv.NewPrimitiveRecord[tlv.TlvType8, [33]byte](
100✔
248
                        nodeID1,
100✔
249
                ),
100✔
250
                NodeID2: tlv.NewPrimitiveRecord[tlv.TlvType10, [33]byte](
100✔
251
                        nodeID2,
100✔
252
                ),
100✔
253
                ExtraSignedFields: make(map[uint64][]byte),
100✔
254
        }
100✔
255

100✔
256
        msg.Signature.Val = RandSignature(t)
100✔
257
        msg.Signature.Val.ForceSchnorr()
100✔
258

100✔
259
        randRecs, _ := RandSignedRangeRecords(t)
100✔
260
        if len(randRecs) > 0 {
179✔
261
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
79✔
262
        }
79✔
263

264
        // Randomly include optional fields
265
        if rapid.Bool().Draw(t, "includeBitcoinKey1") {
159✔
266
                var bitcoinKey1 [33]byte
59✔
267
                copy(bitcoinKey1[:], RandPubKey(t).SerializeCompressed())
59✔
268
                msg.BitcoinKey1 = tlv.SomeRecordT(
59✔
269
                        tlv.NewPrimitiveRecord[tlv.TlvType12, [33]byte](
59✔
270
                                bitcoinKey1,
59✔
271
                        ),
59✔
272
                )
59✔
273
        }
59✔
274

275
        if rapid.Bool().Draw(t, "includeBitcoinKey2") {
154✔
276
                var bitcoinKey2 [33]byte
54✔
277
                copy(bitcoinKey2[:], RandPubKey(t).SerializeCompressed())
54✔
278
                msg.BitcoinKey2 = tlv.SomeRecordT(
54✔
279
                        tlv.NewPrimitiveRecord[tlv.TlvType14, [33]byte](
54✔
280
                                bitcoinKey2,
54✔
281
                        ),
54✔
282
                )
54✔
283
        }
54✔
284

285
        if rapid.Bool().Draw(t, "includeMerkleRootHash") {
151✔
286
                hash := RandSHA256Hash(t)
51✔
287
                var merkleRootHash [32]byte
51✔
288
                copy(merkleRootHash[:], hash[:])
51✔
289
                msg.MerkleRootHash = tlv.SomeRecordT(
51✔
290
                        tlv.NewPrimitiveRecord[tlv.TlvType16, [32]byte](
51✔
291
                                merkleRootHash,
51✔
292
                        ),
51✔
293
                )
51✔
294
        }
51✔
295

296
        msg.Outpoint = tlv.NewRecordT[tlv.TlvType18, OutPoint](
100✔
297
                OutPoint(RandOutPoint(t)),
100✔
298
        )
100✔
299

100✔
300
        return msg
100✔
301
}
302

303
// A compile time check to ensure ChannelReady implements the lnwire.TestMessage
304
// interface.
305
var _ TestMessage = (*ChannelReady)(nil)
306

307
// RandTestMessage populates the message with random data suitable for testing.
308
// It uses the rapid testing framework to generate random values.
309
//
310
// This is part of the TestMessage interface.
311
func (c *ChannelReady) RandTestMessage(t *rapid.T) Message {
100✔
312
        msg := &ChannelReady{
100✔
313
                ChanID:                 RandChannelID(t),
100✔
314
                NextPerCommitmentPoint: RandPubKey(t),
100✔
315
                ExtraData:              RandExtraOpaqueData(t, nil),
100✔
316
        }
100✔
317

100✔
318
        includeAliasScid := rapid.Bool().Draw(t, "includeAliasScid")
100✔
319
        includeNextLocalNonce := rapid.Bool().Draw(t, "includeNextLocalNonce")
100✔
320
        includeAnnouncementNodeNonce := rapid.Bool().Draw(
100✔
321
                t, "includeAnnouncementNodeNonce",
100✔
322
        )
100✔
323
        includeAnnouncementBitcoinNonce := rapid.Bool().Draw(
100✔
324
                t, "includeAnnouncementBitcoinNonce",
100✔
325
        )
100✔
326

100✔
327
        if includeAliasScid {
149✔
328
                scid := RandShortChannelID(t)
49✔
329
                msg.AliasScid = &scid
49✔
330
        }
49✔
331

332
        if includeNextLocalNonce {
145✔
333
                nonce := RandMusig2Nonce(t)
45✔
334
                msg.NextLocalNonce = SomeMusig2Nonce(nonce)
45✔
335
        }
45✔
336

337
        if includeAnnouncementNodeNonce {
152✔
338
                nonce := RandMusig2Nonce(t)
52✔
339
                msg.AnnouncementNodeNonce = tlv.SomeRecordT(
52✔
340
                        tlv.NewRecordT[tlv.TlvType0, Musig2Nonce](nonce),
52✔
341
                )
52✔
342
        }
52✔
343

344
        if includeAnnouncementBitcoinNonce {
150✔
345
                nonce := RandMusig2Nonce(t)
50✔
346
                msg.AnnouncementBitcoinNonce = tlv.SomeRecordT(
50✔
347
                        tlv.NewRecordT[tlv.TlvType2, Musig2Nonce](nonce),
50✔
348
                )
50✔
349
        }
50✔
350

351
        return msg
100✔
352
}
353

354
// A compile time check to ensure ChannelReestablish implements the
355
// lnwire.TestMessage interface.
356
var _ TestMessage = (*ChannelReestablish)(nil)
357

358
// RandTestMessage populates the message with random data suitable for testing.
359
// It uses the rapid testing framework to generate random values.
360
//
361
// This is part of the TestMessage interface.
362
func (a *ChannelReestablish) RandTestMessage(t *rapid.T) Message {
100✔
363
        msg := &ChannelReestablish{
100✔
364
                ChanID: RandChannelID(t),
100✔
365
                NextLocalCommitHeight: rapid.Uint64().Draw(
100✔
366
                        t, "nextLocalCommitHeight",
100✔
367
                ),
100✔
368
                RemoteCommitTailHeight: rapid.Uint64().Draw(
100✔
369
                        t, "remoteCommitTailHeight",
100✔
370
                ),
100✔
371
                LastRemoteCommitSecret:    RandPaymentPreimage(t),
100✔
372
                LocalUnrevokedCommitPoint: RandPubKey(t),
100✔
373
                ExtraData:                 RandExtraOpaqueData(t, nil),
100✔
374
        }
100✔
375

100✔
376
        // Randomly decide whether to include optional fields
100✔
377
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
378
        includeDynHeight := rapid.Bool().Draw(t, "includeDynHeight")
100✔
379

100✔
380
        if includeLocalNonce {
151✔
381
                nonce := RandMusig2Nonce(t)
51✔
382
                msg.LocalNonce = SomeMusig2Nonce(nonce)
51✔
383
        }
51✔
384

385
        if includeDynHeight {
145✔
386
                height := DynHeight(rapid.Uint64().Draw(t, "dynHeight"))
45✔
387
                msg.DynHeight = fn.Some(height)
45✔
388
        }
45✔
389

390
        return msg
100✔
391
}
392

393
// A compile time check to ensure ChannelUpdate1 implements the TestMessage
394
// interface.
395
var _ TestMessage = (*ChannelUpdate1)(nil)
396

397
// RandTestMessage populates the message with random data suitable for testing.
398
// It uses the rapid testing framework to generate random values.
399
//
400
// This is part of the TestMessage interface.
401
func (a *ChannelUpdate1) RandTestMessage(t *rapid.T) Message {
100✔
402
        // Generate random message flags
100✔
403
        // Randomly decide whether to include max HTLC field
100✔
404
        includeMaxHtlc := rapid.Bool().Draw(t, "includeMaxHtlc")
100✔
405
        var msgFlags ChanUpdateMsgFlags
100✔
406
        if includeMaxHtlc {
151✔
407
                msgFlags |= ChanUpdateRequiredMaxHtlc
51✔
408
        }
51✔
409

410
        // Generate random channel flags
411
        // Randomly decide direction (node1 or node2)
412
        isNode2 := rapid.Bool().Draw(t, "isNode2")
100✔
413
        var chanFlags ChanUpdateChanFlags
100✔
414
        if isNode2 {
149✔
415
                chanFlags |= ChanUpdateDirection
49✔
416
        }
49✔
417

418
        // Randomly decide if channel is disabled
419
        isDisabled := rapid.Bool().Draw(t, "isDisabled")
100✔
420
        if isDisabled {
157✔
421
                chanFlags |= ChanUpdateDisabled
57✔
422
        }
57✔
423

424
        // Generate chain hash
425
        chainHash := RandChainHash(t)
100✔
426
        var hash chainhash.Hash
100✔
427
        copy(hash[:], chainHash[:])
100✔
428

100✔
429
        // Generate other random fields
100✔
430
        maxHtlc := MilliSatoshi(rapid.Uint64().Draw(t, "maxHtlc"))
100✔
431

100✔
432
        // If max HTLC flag is not set, we need to zero the value
100✔
433
        if !includeMaxHtlc {
149✔
434
                maxHtlc = 0
49✔
435
        }
49✔
436

437
        // Randomly decide if an inbound fee should be included.
438
        // By default, our extra opaque data will just be random TLV but if we
439
        // include an inbound fee, then we will also set the record in the
440
        // extra opaque data.
441
        var (
100✔
442
                customRecords, _ = RandCustomRecords(t, nil)
100✔
443
                inboundFee       tlv.OptionalRecordT[tlv.TlvType55555, Fee]
100✔
444
        )
100✔
445
        includeInboundFee := rapid.Bool().Draw(t, "includeInboundFee")
100✔
446
        if includeInboundFee {
144✔
447
                if customRecords == nil {
56✔
448
                        customRecords = make(CustomRecords)
12✔
449
                }
12✔
450

451
                inFeeBase := int32(
44✔
452
                        rapid.IntRange(-1000, 1000).Draw(t, "inFeeBase"),
44✔
453
                )
44✔
454
                inFeeProp := int32(
44✔
455
                        rapid.IntRange(-1000, 1000).Draw(t, "inFeeProp"),
44✔
456
                )
44✔
457
                fee := Fee{
44✔
458
                        BaseFee: inFeeBase,
44✔
459
                        FeeRate: inFeeProp,
44✔
460
                }
44✔
461
                inboundFee = tlv.SomeRecordT(
44✔
462
                        tlv.NewRecordT[tlv.TlvType55555, Fee](fee),
44✔
463
                )
44✔
464

44✔
465
                var b bytes.Buffer
44✔
466
                feeRecord := fee.Record()
44✔
467
                err := feeRecord.Encode(&b)
44✔
468
                require.NoError(t, err)
44✔
469

44✔
470
                customRecords[uint64(FeeRecordType)] = b.Bytes()
44✔
471
        }
472

473
        extraBytes, err := customRecords.Serialize()
100✔
474
        require.NoError(t, err)
100✔
475

100✔
476
        return &ChannelUpdate1{
100✔
477
                Signature:      RandSignature(t),
100✔
478
                ChainHash:      hash,
100✔
479
                ShortChannelID: RandShortChannelID(t),
100✔
480
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
481
                        t, "timestamp"),
100✔
482
                ),
100✔
483
                MessageFlags: msgFlags,
100✔
484
                ChannelFlags: chanFlags,
100✔
485
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
100✔
486
                        t, "timelockDelta"),
100✔
487
                ),
100✔
488
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
100✔
489
                        t, "htlcMinimum"),
100✔
490
                ),
100✔
491
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
492
                        t, "baseFee"),
100✔
493
                ),
100✔
494
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
495
                        t, "feeRate"),
100✔
496
                ),
100✔
497
                HtlcMaximumMsat: maxHtlc,
100✔
498
                InboundFee:      inboundFee,
100✔
499
                ExtraOpaqueData: extraBytes,
100✔
500
        }
100✔
501
}
502

503
// A compile time check to ensure ChannelUpdate2 implements the
504
// lnwire.TestMessage interface.
505
var _ TestMessage = (*ChannelUpdate2)(nil)
506

507
// RandTestMessage populates the message with random data suitable for testing.
508
// It uses the rapid testing framework to generate random values.
509
//
510
// This is part of the TestMessage interface.
511
func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
100✔
512
        shortChanID := RandShortChannelID(t)
100✔
513
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
100✔
514

100✔
515
        var disabledFlags ChanUpdateDisableFlags
100✔
516
        if rapid.Bool().Draw(t, "disableIncoming") {
147✔
517
                disabledFlags |= ChanUpdateDisableIncoming
47✔
518
        }
47✔
519
        if rapid.Bool().Draw(t, "disableOutgoing") {
153✔
520
                disabledFlags |= ChanUpdateDisableOutgoing
53✔
521
        }
53✔
522

523
        cltvExpiryDelta := uint16(rapid.IntRange(10, 200).Draw(
100✔
524
                t, "cltvExpiryDelta"),
100✔
525
        )
100✔
526

100✔
527
        htlcMinMsat := MilliSatoshi(rapid.IntRange(1, 10000).Draw(
100✔
528
                t, "htlcMinMsat"),
100✔
529
        )
100✔
530
        htlcMaxMsat := MilliSatoshi(rapid.IntRange(10000, 100000000).Draw(
100✔
531
                t, "htlcMaxMsat"),
100✔
532
        )
100✔
533
        feeBaseMsat := uint32(rapid.IntRange(0, 10000).Draw(t, "feeBaseMsat"))
100✔
534
        feeProportionalMillionths := uint32(rapid.IntRange(0, 10000).Draw(
100✔
535
                t, "feeProportionalMillionths"),
100✔
536
        )
100✔
537

100✔
538
        chainHash := RandChainHash(t)
100✔
539
        var chainHashObj chainhash.Hash
100✔
540
        copy(chainHashObj[:], chainHash[:])
100✔
541

100✔
542
        //nolint:ll
100✔
543
        msg := &ChannelUpdate2{
100✔
544
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
100✔
545
                        chainHashObj,
100✔
546
                ),
100✔
547
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2, ShortChannelID](
100✔
548
                        shortChanID,
100✔
549
                ),
100✔
550
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType4, uint32](
100✔
551
                        blockHeight,
100✔
552
                ),
100✔
553
                DisabledFlags: tlv.NewPrimitiveRecord[tlv.TlvType6, ChanUpdateDisableFlags]( //nolint:ll
100✔
554
                        disabledFlags,
100✔
555
                ),
100✔
556
                CLTVExpiryDelta: tlv.NewPrimitiveRecord[tlv.TlvType10, uint16](
100✔
557
                        cltvExpiryDelta,
100✔
558
                ),
100✔
559
                HTLCMinimumMsat: tlv.NewPrimitiveRecord[tlv.TlvType12, MilliSatoshi](
100✔
560
                        htlcMinMsat,
100✔
561
                ),
100✔
562
                HTLCMaximumMsat: tlv.NewPrimitiveRecord[tlv.TlvType14, MilliSatoshi](
100✔
563
                        htlcMaxMsat,
100✔
564
                ),
100✔
565
                FeeBaseMsat: tlv.NewPrimitiveRecord[tlv.TlvType16, uint32](
100✔
566
                        feeBaseMsat,
100✔
567
                ),
100✔
568
                FeeProportionalMillionths: tlv.NewPrimitiveRecord[tlv.TlvType18, uint32](
100✔
569
                        feeProportionalMillionths,
100✔
570
                ),
100✔
571
                ExtraSignedFields: make(map[uint64][]byte),
100✔
572
        }
100✔
573

100✔
574
        if rapid.Bool().Draw(t, "includeInboundFee") {
151✔
575
                base := rapid.IntRange(-1000, 1000).Draw(t, "inFeeBase")
51✔
576
                rate := rapid.IntRange(-1000, 1000).Draw(t, "inFeeProp")
51✔
577
                fee := Fee{
51✔
578
                        BaseFee: int32(base),
51✔
579
                        FeeRate: int32(rate),
51✔
580
                }
51✔
581
                msg.InboundFee = tlv.SomeRecordT(
51✔
582
                        tlv.NewRecordT[tlv.TlvType55555](fee),
51✔
583
                )
51✔
584
        }
51✔
585

586
        msg.Signature.Val = RandSignature(t)
100✔
587
        msg.Signature.Val.ForceSchnorr()
100✔
588

100✔
589
        if rapid.Bool().Draw(t, "isSecondPeer") {
152✔
590
                msg.SecondPeer = tlv.SomeRecordT(
52✔
591
                        tlv.RecordT[tlv.TlvType8, TrueBoolean]{},
52✔
592
                )
52✔
593
        }
52✔
594

595
        return msg
100✔
596
}
597

598
// A compile time check to ensure ClosingComplete implements the
599
// lnwire.TestMessage interface.
600
var _ TestMessage = (*ClosingComplete)(nil)
601

602
// RandTestMessage populates the message with random data suitable for testing.
603
// It uses the rapid testing framework to generate random values.
604
//
605
// This is part of the TestMessage interface.
606
func (c *ClosingComplete) RandTestMessage(t *rapid.T) Message {
101✔
607
        msg := &ClosingComplete{
101✔
608
                ChannelID: RandChannelID(t),
101✔
609
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
101✔
610
                        t, "feeSatoshis"),
101✔
611
                ),
101✔
612
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
101✔
613
                        t, "lockTime",
101✔
614
                ),
101✔
615
                CloseeScript: RandDeliveryAddress(t),
101✔
616
                CloserScript: RandDeliveryAddress(t),
101✔
617
                ExtraData:    RandExtraOpaqueData(t, nil),
101✔
618
        }
101✔
619

101✔
620
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
101✔
621
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
101✔
622
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
101✔
623

101✔
624
        // Ensure at least one signature is present.
101✔
625
        if !includeCloserNoClosee && !includeNoCloserClosee &&
101✔
626
                !includeCloserAndClosee {
114✔
627

13✔
628
                // If all are false, enable at least one randomly.
13✔
629
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
13✔
630
                switch choice {
13✔
631
                case 0:
1✔
632
                        includeCloserNoClosee = true
1✔
633
                case 1:
8✔
634
                        includeNoCloserClosee = true
8✔
635
                case 2:
4✔
636
                        includeCloserAndClosee = true
4✔
637
                }
638
        }
639

640
        if includeCloserNoClosee {
151✔
641
                sig := RandSignature(t)
50✔
642
                msg.CloserNoClosee = tlv.SomeRecordT(
50✔
643
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
50✔
644
                )
50✔
645
        }
50✔
646

647
        if includeNoCloserClosee {
159✔
648
                sig := RandSignature(t)
58✔
649
                msg.NoCloserClosee = tlv.SomeRecordT(
58✔
650
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
58✔
651
                )
58✔
652
        }
58✔
653

654
        if includeCloserAndClosee {
157✔
655
                sig := RandSignature(t)
56✔
656
                msg.CloserAndClosee = tlv.SomeRecordT(
56✔
657
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
56✔
658
                )
56✔
659
        }
56✔
660

661
        return msg
101✔
662
}
663

664
// A compile time check to ensure ClosingSig implements the lnwire.TestMessage
665
// interface.
666
var _ TestMessage = (*ClosingSig)(nil)
667

668
// RandTestMessage populates the message with random data suitable for testing.
669
// It uses the rapid testing framework to generate random values.
670
//
671
// This is part of the TestMessage interface.
672
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
102✔
673
        msg := &ClosingSig{
102✔
674
                ChannelID:    RandChannelID(t),
102✔
675
                CloseeScript: RandDeliveryAddress(t),
102✔
676
                CloserScript: RandDeliveryAddress(t),
102✔
677
                ExtraData:    RandExtraOpaqueData(t, nil),
102✔
678
        }
102✔
679

102✔
680
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
102✔
681
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
102✔
682
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
102✔
683

102✔
684
        // Ensure at least one signature is present.
102✔
685
        if !includeCloserNoClosee && !includeNoCloserClosee &&
102✔
686
                !includeCloserAndClosee {
107✔
687

5✔
688
                // If all are false, enable at least one randomly.
5✔
689
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
5✔
690
                switch choice {
5✔
691
                case 0:
3✔
692
                        includeCloserNoClosee = true
3✔
693
                case 1:
2✔
694
                        includeNoCloserClosee = true
2✔
UNCOV
695
                case 2:
×
UNCOV
696
                        includeCloserAndClosee = true
×
697
                }
698
        }
699

700
        if includeCloserNoClosee {
162✔
701
                sig := RandSignature(t)
60✔
702
                msg.CloserNoClosee = tlv.SomeRecordT(
60✔
703
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
60✔
704
                )
60✔
705
        }
60✔
706

707
        if includeNoCloserClosee {
156✔
708
                sig := RandSignature(t)
54✔
709
                msg.NoCloserClosee = tlv.SomeRecordT(
54✔
710
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
54✔
711
                )
54✔
712
        }
54✔
713

714
        if includeCloserAndClosee {
157✔
715
                sig := RandSignature(t)
55✔
716
                msg.CloserAndClosee = tlv.SomeRecordT(
55✔
717
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
55✔
718
                )
55✔
719
        }
55✔
720

721
        return msg
102✔
722
}
723

724
// A compile time check to ensure ClosingSigned implements the
725
// lnwire.TestMessage interface.
726
var _ TestMessage = (*ClosingSigned)(nil)
727

728
// RandTestMessage populates the message with random data suitable for testing.
729
// It uses the rapid testing framework to generate random values.
730
//
731
// This is part of the TestMessage interface.
732
func (c *ClosingSigned) RandTestMessage(t *rapid.T) Message {
100✔
733
        // Generate a random boolean to decide whether to include CommitSig or
100✔
734
        // PartialSig Since they're mutually exclusive, when one is populated,
100✔
735
        // the other must be blank.
100✔
736
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
737

100✔
738
        msg := &ClosingSigned{
100✔
739
                ChannelID: RandChannelID(t),
100✔
740
                FeeSatoshis: btcutil.Amount(
100✔
741
                        rapid.Int64Range(0, 1000000).Draw(t, "feeSatoshis"),
100✔
742
                ),
100✔
743
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
744
        }
100✔
745

100✔
746
        if usePartialSig {
144✔
747
                sigBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
44✔
748
                        t, "sigScalar",
44✔
749
                )
44✔
750
                var s btcec.ModNScalar
44✔
751
                _ = s.SetByteSlice(sigBytes)
44✔
752

44✔
753
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
44✔
754
                msg.Signature = Sig{}
44✔
755
        } else {
100✔
756
                msg.Signature = RandSignature(t)
56✔
757
        }
56✔
758

759
        return msg
100✔
760
}
761

762
// A compile time check to ensure CommitSig implements the lnwire.TestMessage
763
// interface.
764
var _ TestMessage = (*CommitSig)(nil)
765

766
// RandTestMessage populates the message with random data suitable for testing.
767
// It uses the rapid testing framework to generate random values.
768
//
769
// This is part of the TestMessage interface.
770
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
100✔
771
        cr, _ := RandCustomRecords(t, nil)
100✔
772
        sig := &CommitSig{
100✔
773
                ChanID:        RandChannelID(t),
100✔
774
                CommitSig:     RandSignature(t),
100✔
775
                CustomRecords: cr,
100✔
776
        }
100✔
777

100✔
778
        numHtlcSigs := rapid.IntRange(0, 20).Draw(t, "numHtlcSigs")
100✔
779
        htlcSigs := make([]Sig, numHtlcSigs)
100✔
780
        for i := 0; i < numHtlcSigs; i++ {
814✔
781
                htlcSigs[i] = RandSignature(t)
714✔
782
        }
714✔
783

784
        if len(htlcSigs) > 0 {
186✔
785
                sig.HtlcSigs = htlcSigs
86✔
786
        }
86✔
787

788
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
789
        if includePartialSig {
152✔
790
                sigWithNonce := RandPartialSigWithNonce(t)
52✔
791
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
52✔
792
        }
52✔
793

794
        return sig
100✔
795
}
796

797
// A compile time check to ensure Custom implements the lnwire.TestMessage
798
// interface.
799
var _ TestMessage = (*Custom)(nil)
800

801
// RandTestMessage populates the message with random data suitable for testing.
802
// It uses the rapid testing framework to generate random values.
803
//
804
// This is part of the TestMessage interface.
805
func (c *Custom) RandTestMessage(t *rapid.T) Message {
14✔
806
        msgType := MessageType(
14✔
807
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
14✔
808
                        t, "customMsgType",
14✔
809
                ),
14✔
810
        )
14✔
811

14✔
812
        dataLen := rapid.IntRange(0, 1000).Draw(t, "customDataLength")
14✔
813
        data := rapid.SliceOfN(rapid.Byte(), dataLen, dataLen).Draw(
14✔
814
                t, "customData",
14✔
815
        )
14✔
816

14✔
817
        msg, err := NewCustom(msgType, data)
14✔
818
        if err != nil {
14✔
819
                panic(fmt.Sprintf("Error creating custom message: %v", err))
×
820
        }
821

822
        return msg
14✔
823
}
824

825
// A compile time check to ensure OnionMessage implements the lnwire.TestMessage
826
// interface.
827
var _ TestMessage = (*OnionMessage)(nil)
828

829
// RandTestMessage populates the message with random data suitable for testing.
830
// It uses the rapid testing framework to generate random values.
831
//
832
// This is part of the TestMessage interface.
833
func (o *OnionMessage) RandTestMessage(t *rapid.T) Message {
100✔
834
        // Generate random compressed public key for node ID
100✔
835
        pathKey := RandPubKey(t)
100✔
836

100✔
837
        dataLen := rapid.IntRange(0, 1000).Draw(t, "onionMessageDataLength")
100✔
838
        data := rapid.SliceOfN(rapid.Byte(), dataLen, dataLen).Draw(
100✔
839
                t, "onionMessageData",
100✔
840
        )
100✔
841

100✔
842
        msg := NewOnionMessage(pathKey, data)
100✔
843

100✔
844
        return msg
100✔
845
}
100✔
846

847
// A compile time check to ensure DynAck implements the lnwire.TestMessage
848
// interface.
849
var _ TestMessage = (*DynAck)(nil)
850

851
// RandTestMessage populates the message with random data suitable for testing.
852
// It uses the rapid testing framework to generate random values.
853
//
854
// This is part of the TestMessage interface.
855
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
100✔
856
        msg := &DynAck{
100✔
857
                ChanID: RandChannelID(t),
100✔
858
        }
100✔
859

100✔
860
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
861
        if includeLocalNonce {
151✔
862
                nonce := RandMusig2Nonce(t)
51✔
863
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
51✔
864
                msg.LocalNonce = tlv.SomeRecordT(rec)
51✔
865
        }
51✔
866

867
        // Create a tlv type lists to hold all known records which will be
868
        // ignored when creating ExtraData records.
869
        ignoreRecords := fn.NewSet[uint64]()
100✔
870
        for i := range uint64(15) {
1,600✔
871
                // Ignore known records.
1,500✔
872
                if i%2 == 0 {
2,300✔
873
                        ignoreRecords.Add(i)
800✔
874
                }
800✔
875
        }
876

877
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
100✔
878

100✔
879
        return msg
100✔
880
}
881

882
// A compile time check to ensure DynPropose implements the lnwire.TestMessage
883
// interface.
884
var _ TestMessage = (*DynPropose)(nil)
885

886
// RandTestMessage populates the message with random data suitable for testing.
887
// It uses the rapid testing framework to generate random values.
888
//
889
// This is part of the TestMessage interface.
890
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
100✔
891
        msg := &DynPropose{
100✔
892
                ChanID: RandChannelID(t),
100✔
893
        }
100✔
894

100✔
895
        // Randomly decide which optional fields to include
100✔
896
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
100✔
897
        includeMaxValueInFlight := rapid.Bool().Draw(
100✔
898
                t, "includeMaxValueInFlight",
100✔
899
        )
100✔
900
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
100✔
901
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
100✔
902
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
100✔
903
                t, "includeMaxAcceptedHTLCs",
100✔
904
        )
100✔
905
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
906

100✔
907
        // Generate random values for each included field
100✔
908
        if includeDustLimit {
144✔
909
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
44✔
910
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
44✔
911
                rec.Val = tlv.NewBigSizeT(val)
44✔
912
                msg.DustLimit = tlv.SomeRecordT(rec)
44✔
913
        }
44✔
914

915
        if includeMaxValueInFlight {
151✔
916
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
51✔
917
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
51✔
918
                rec.Val = val
51✔
919
                msg.MaxValueInFlight = tlv.SomeRecordT(rec)
51✔
920
        }
51✔
921

922
        if includeChannelReserve {
152✔
923
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
52✔
924
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
52✔
925
                rec.Val = tlv.NewBigSizeT(val)
52✔
926
                msg.ChannelReserve = tlv.SomeRecordT(rec)
52✔
927
        }
52✔
928

929
        if includeCsvDelay {
151✔
930
                csvDelay := msg.CsvDelay.Zero()
51✔
931
                val := rapid.Uint16().Draw(t, "csvDelay")
51✔
932
                csvDelay.Val = val
51✔
933
                msg.CsvDelay = tlv.SomeRecordT(csvDelay)
51✔
934
        }
51✔
935

936
        if includeMaxAcceptedHTLCs {
149✔
937
                maxHtlcs := msg.MaxAcceptedHTLCs.Zero()
49✔
938
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
49✔
939
                msg.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
49✔
940
        }
49✔
941

942
        if includeChannelType {
149✔
943
                chanType := msg.ChannelType.Zero()
49✔
944
                chanType.Val = *RandChannelType(t)
49✔
945
                msg.ChannelType = tlv.SomeRecordT(chanType)
49✔
946
        }
49✔
947

948
        // Create a tlv type lists to hold all known records which will be
949
        // ignored when creating ExtraData records.
950
        ignoreRecords := fn.NewSet[uint64]()
100✔
951
        for i := range uint64(13) {
1,400✔
952
                // Ignore known records.
1,300✔
953
                if i%2 == 0 {
2,000✔
954
                        ignoreRecords.Add(i)
700✔
955
                }
700✔
956
        }
957

958
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
100✔
959

100✔
960
        return msg
100✔
961
}
962

963
// A compile time check to ensure DynReject implements the lnwire.TestMessage
964
// interface.
965
var _ TestMessage = (*DynReject)(nil)
966

967
// RandTestMessage populates the message with random data suitable for testing.
968
// It uses the rapid testing framework to generate random values.
969
//
970
// This is part of the TestMessage interface.
971
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
100✔
972
        featureVec := NewRawFeatureVector()
100✔
973

100✔
974
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
100✔
975
        for i := 0; i < numFeatures; i++ {
447✔
976
                bit := FeatureBit(
347✔
977
                        rapid.IntRange(0, 31).Draw(
347✔
978
                                t, fmt.Sprintf("rejectionBit-%d", i),
347✔
979
                        ),
347✔
980
                )
347✔
981
                featureVec.Set(bit)
347✔
982
        }
347✔
983

984
        var extraData ExtraOpaqueData
100✔
985
        randData := RandExtraOpaqueData(t, nil)
100✔
986
        if len(randData) > 0 {
177✔
987
                extraData = randData
77✔
988
        }
77✔
989

990
        return &DynReject{
100✔
991
                ChanID:           RandChannelID(t),
100✔
992
                UpdateRejections: *featureVec,
100✔
993
                ExtraData:        extraData,
100✔
994
        }
100✔
995
}
996

997
// A compile time check to ensure DynCommit implements the lnwire.TestMessage
998
// interface.
999
var _ TestMessage = (*DynCommit)(nil)
1000

1001
// RandTestMessage populates the message with random data suitable for testing.
1002
// It uses the rapid testing framework to generate random values.
1003
//
1004
// This is part of the TestMessage interface.
1005
func (dc *DynCommit) RandTestMessage(t *rapid.T) Message {
100✔
1006
        chanID := RandChannelID(t)
100✔
1007

100✔
1008
        da := &DynAck{
100✔
1009
                ChanID: chanID,
100✔
1010
        }
100✔
1011

100✔
1012
        dp := &DynPropose{
100✔
1013
                ChanID: chanID,
100✔
1014
        }
100✔
1015

100✔
1016
        // Randomly decide which optional fields to include
100✔
1017
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
100✔
1018
        includeMaxValueInFlight := rapid.Bool().Draw(
100✔
1019
                t, "includeMaxValueInFlight",
100✔
1020
        )
100✔
1021
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
100✔
1022
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
100✔
1023
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
100✔
1024
                t, "includeMaxAcceptedHTLCs",
100✔
1025
        )
100✔
1026
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
1027

100✔
1028
        // Generate random values for each included field
100✔
1029
        if includeDustLimit {
148✔
1030
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
48✔
1031
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
48✔
1032
                rec.Val = tlv.NewBigSizeT(val)
48✔
1033
                dp.DustLimit = tlv.SomeRecordT(rec)
48✔
1034
        }
48✔
1035

1036
        if includeMaxValueInFlight {
146✔
1037
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
46✔
1038
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
46✔
1039
                rec.Val = val
46✔
1040
                dp.MaxValueInFlight = tlv.SomeRecordT(rec)
46✔
1041
        }
46✔
1042

1043
        if includeChannelReserve {
150✔
1044
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
50✔
1045
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
50✔
1046
                rec.Val = tlv.NewBigSizeT(val)
50✔
1047
                dp.ChannelReserve = tlv.SomeRecordT(rec)
50✔
1048
        }
50✔
1049

1050
        if includeCsvDelay {
152✔
1051
                csvDelay := dp.CsvDelay.Zero()
52✔
1052
                val := rapid.Uint16().Draw(t, "csvDelay")
52✔
1053
                csvDelay.Val = val
52✔
1054
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
52✔
1055
        }
52✔
1056

1057
        if includeMaxAcceptedHTLCs {
152✔
1058
                maxHtlcs := dp.MaxAcceptedHTLCs.Zero()
52✔
1059
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
52✔
1060
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
52✔
1061
        }
52✔
1062

1063
        if includeChannelType {
144✔
1064
                chanType := dp.ChannelType.Zero()
44✔
1065
                chanType.Val = *RandChannelType(t)
44✔
1066
                dp.ChannelType = tlv.SomeRecordT(chanType)
44✔
1067
        }
44✔
1068

1069
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
1070
        if includeLocalNonce {
148✔
1071
                nonce := RandMusig2Nonce(t)
48✔
1072
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
48✔
1073
                da.LocalNonce = tlv.SomeRecordT(rec)
48✔
1074
        }
48✔
1075

1076
        // Create a tlv type lists to hold all known records which will be
1077
        // ignored when creating ExtraData records.
1078
        ignoreRecords := fn.NewSet[uint64]()
100✔
1079
        for i := range uint64(15) {
1,600✔
1080
                // Ignore known records.
1,500✔
1081
                if i%2 == 0 {
2,300✔
1082
                        ignoreRecords.Add(i)
800✔
1083
                }
800✔
1084
        }
1085
        msg := &DynCommit{
100✔
1086
                DynPropose: *dp,
100✔
1087
                DynAck:     *da,
100✔
1088
        }
100✔
1089

100✔
1090
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
100✔
1091

100✔
1092
        return msg
100✔
1093
}
1094

1095
// A compile time check to ensure FundingCreated implements the TestMessage
1096
// interface.
1097
var _ TestMessage = (*FundingCreated)(nil)
1098

1099
// RandTestMessage populates the message with random data suitable for testing.
1100
// It uses the rapid testing framework to generate random values.
1101
//
1102
// This is part of the TestMessage interface.
1103
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
101✔
1104
        var pendingChanID [32]byte
101✔
1105
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
101✔
1106
                t, "pendingChanID",
101✔
1107
        )
101✔
1108
        copy(pendingChanID[:], pendingChanIDBytes)
101✔
1109

101✔
1110
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
101✔
1111
        var partialSig OptPartialSigWithNonceTLV
101✔
1112
        var commitSig Sig
101✔
1113

101✔
1114
        if includePartialSig {
162✔
1115
                sigWithNonce := RandPartialSigWithNonce(t)
61✔
1116
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
61✔
1117

61✔
1118
                // When using partial sig, CommitSig should be empty/blank.
61✔
1119
                commitSig = Sig{}
61✔
1120
        } else {
101✔
1121
                commitSig = RandSignature(t)
40✔
1122
        }
40✔
1123

1124
        return &FundingCreated{
101✔
1125
                PendingChannelID: pendingChanID,
101✔
1126
                FundingPoint:     RandOutPoint(t),
101✔
1127
                CommitSig:        commitSig,
101✔
1128
                PartialSig:       partialSig,
101✔
1129
                ExtraData:        RandExtraOpaqueData(t, nil),
101✔
1130
        }
101✔
1131
}
1132

1133
// A compile time check to ensure FundingSigned implements the
1134
// lnwire.TestMessage interface.
1135
var _ TestMessage = (*FundingSigned)(nil)
1136

1137
// RandTestMessage populates the message with random data suitable for testing.
1138
// It uses the rapid testing framework to generate random values.
1139
//
1140
// This is part of the TestMessage interface.
1141
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
100✔
1142
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
1143

100✔
1144
        msg := &FundingSigned{
100✔
1145
                ChanID:    RandChannelID(t),
100✔
1146
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1147
        }
100✔
1148

100✔
1149
        if usePartialSig {
154✔
1150
                sigWithNonce := RandPartialSigWithNonce(t)
54✔
1151
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
54✔
1152

54✔
1153
                msg.CommitSig = Sig{}
54✔
1154
        } else {
100✔
1155
                msg.CommitSig = RandSignature(t)
46✔
1156
        }
46✔
1157

1158
        return msg
100✔
1159
}
1160

1161
// A compile time check to ensure GossipTimestampRange implements the
1162
// lnwire.TestMessage interface.
1163
var _ TestMessage = (*GossipTimestampRange)(nil)
1164

1165
// RandTestMessage populates the message with random data suitable for testing.
1166
// It uses the rapid testing framework to generate random values.
1167
//
1168
// This is part of the TestMessage interface.
1169
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
100✔
1170
        var chainHash chainhash.Hash
100✔
1171
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1172
        copy(chainHash[:], hashBytes)
100✔
1173

100✔
1174
        msg := &GossipTimestampRange{
100✔
1175
                ChainHash:      chainHash,
100✔
1176
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
100✔
1177
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
100✔
1178
                ExtraData:      RandExtraOpaqueData(t, nil),
100✔
1179
        }
100✔
1180

100✔
1181
        includeFirstBlockHeight := rapid.Bool().Draw(
100✔
1182
                t, "includeFirstBlockHeight",
100✔
1183
        )
100✔
1184
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
100✔
1185

100✔
1186
        if includeFirstBlockHeight {
153✔
1187
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
53✔
1188
                msg.FirstBlockHeight = tlv.SomeRecordT(
53✔
1189
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
53✔
1190
                )
53✔
1191
        }
53✔
1192

1193
        if includeBlockRange {
156✔
1194
                blockRange := rapid.Uint32().Draw(t, "blockRange")
56✔
1195
                msg.BlockRange = tlv.SomeRecordT(
56✔
1196
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
56✔
1197
                )
56✔
1198
        }
56✔
1199

1200
        return msg
100✔
1201
}
1202

1203
// RandTestMessage populates the message with random data suitable for testing.
1204
// It uses the rapid testing framework to generate random values.
1205
//
1206
// This is part of the TestMessage interface.
1207
func (msg *Init) RandTestMessage(t *rapid.T) Message {
100✔
1208
        global := NewRawFeatureVector()
100✔
1209
        local := NewRawFeatureVector()
100✔
1210

100✔
1211
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
100✔
1212
        for i := 0; i < numGlobalFeatures; i++ {
838✔
1213
                bit := FeatureBit(
738✔
1214
                        rapid.IntRange(0, 100).Draw(
738✔
1215
                                t, fmt.Sprintf("globalFeatureBit%d", i),
738✔
1216
                        ),
738✔
1217
                )
738✔
1218
                global.Set(bit)
738✔
1219
        }
738✔
1220

1221
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
100✔
1222
        for i := 0; i < numLocalFeatures; i++ {
744✔
1223
                bit := FeatureBit(
644✔
1224
                        rapid.IntRange(0, 100).Draw(
644✔
1225
                                t, fmt.Sprintf("localFeatureBit%d", i),
644✔
1226
                        ),
644✔
1227
                )
644✔
1228
                local.Set(bit)
644✔
1229
        }
644✔
1230

1231
        ignoreRecords := fn.NewSet[uint64]()
100✔
1232

100✔
1233
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
100✔
1234

100✔
1235
        return NewInitMessage(global, local)
100✔
1236
}
1237

1238
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1239
// interface.
1240
var _ TestMessage = (*KickoffSig)(nil)
1241

1242
// RandTestMessage populates the message with random data suitable for testing.
1243
// It uses the rapid testing framework to generate random values.
1244
//
1245
// This is part of the TestMessage interface.
1246
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
100✔
1247
        return &KickoffSig{
100✔
1248
                ChanID:    RandChannelID(t),
100✔
1249
                Signature: RandSignature(t),
100✔
1250
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1251
        }
100✔
1252
}
100✔
1253

1254
// A compile time check to ensure NodeAnnouncement1 implements the
1255
// lnwire.TestMessage interface.
1256
var _ TestMessage = (*NodeAnnouncement1)(nil)
1257

1258
// A compile time check to ensure NodeAnnouncement2 implements the
1259
// lnwire.TestMessage interface.
1260
var _ TestMessage = (*NodeAnnouncement2)(nil)
1261

1262
// RandTestMessage populates the message with random data suitable for testing.
1263
// It uses the rapid testing framework to generate random values.
1264
//
1265
// This is part of the TestMessage interface.
1266
func (a *NodeAnnouncement1) RandTestMessage(t *rapid.T) Message {
100✔
1267
        // Generate random compressed public key for node ID
100✔
1268
        pubKey := RandPubKey(t)
100✔
1269
        var nodeID [33]byte
100✔
1270
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1271

100✔
1272
        // Generate random RGB color
100✔
1273
        rgbColor := color.RGBA{
100✔
1274
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
100✔
1275
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
100✔
1276
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
100✔
1277
        }
100✔
1278

100✔
1279
        return &NodeAnnouncement1{
100✔
1280
                Signature: RandSignature(t),
100✔
1281
                Features:  RandFeatureVector(t),
100✔
1282
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
1283
                        t, "timestamp"),
100✔
1284
                ),
100✔
1285
                NodeID:          nodeID,
100✔
1286
                RGBColor:        rgbColor,
100✔
1287
                Alias:           RandNodeAlias(t),
100✔
1288
                Addresses:       RandNetAddrs(t),
100✔
1289
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
1290
        }
100✔
1291
}
100✔
1292

1293
// RandTestMessage populates the message with random data suitable for testing.
1294
// It uses the rapid testing framework to generate random values.
1295
//
1296
// This is part of the TestMessage interface.
1297
func (n *NodeAnnouncement2) RandTestMessage(t *rapid.T) Message {
100✔
1298
        features := RandFeatureVector(t)
100✔
1299
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
100✔
1300

100✔
1301
        // Generate random compressed public key for node ID
100✔
1302
        pubKey := RandPubKey(t)
100✔
1303
        var nodeID [33]byte
100✔
1304
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1305

100✔
1306
        msg := &NodeAnnouncement2{
100✔
1307
                Features: tlv.NewRecordT[tlv.TlvType0](*features),
100✔
1308
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType2](
100✔
1309
                        blockHeight,
100✔
1310
                ),
100✔
1311
                NodeID:            tlv.NewPrimitiveRecord[tlv.TlvType4](nodeID),
100✔
1312
                ExtraSignedFields: make(map[uint64][]byte),
100✔
1313
        }
100✔
1314

100✔
1315
        msg.Signature.Val = RandSignature(t)
100✔
1316
        msg.Signature.Val.ForceSchnorr()
100✔
1317

100✔
1318
        // Test optional fields one by one
100✔
1319
        if rapid.Bool().Draw(t, "includeColor") {
145✔
1320
                rgbColor := Color{
45✔
1321
                        R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
45✔
1322
                        G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
45✔
1323
                        B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
45✔
1324
                }
45✔
1325
                colorRecord := tlv.ZeroRecordT[tlv.TlvType1, Color]()
45✔
1326
                colorRecord.Val = rgbColor
45✔
1327
                msg.Color = tlv.SomeRecordT(colorRecord)
45✔
1328
        }
45✔
1329

1330
        if rapid.Bool().Draw(t, "includeAlias") {
150✔
1331
                aliasBytes := RandNodeAlias2(t)
50✔
1332
                aliasRecord := tlv.ZeroRecordT[tlv.TlvType3, NodeAlias2]()
50✔
1333
                aliasRecord.Val = aliasBytes
50✔
1334
                msg.Alias = tlv.SomeRecordT(aliasRecord)
50✔
1335
        }
50✔
1336

1337
        if rapid.Bool().Draw(t, "includeIPV4Addrs") {
148✔
1338
                ipv4Addrs := make(IPV4Addrs, 1)
48✔
1339
                ip := make(net.IP, 4)
48✔
1340
                ip[0] = uint8(rapid.IntRange(1, 223).Draw(t, "ip4_0"))
48✔
1341
                ip[1] = uint8(rapid.IntRange(0, 255).Draw(t, "ip4_1"))
48✔
1342
                ip[2] = uint8(rapid.IntRange(0, 255).Draw(t, "ip4_2"))
48✔
1343
                ip[3] = uint8(rapid.IntRange(1, 254).Draw(t, "ip4_3"))
48✔
1344

48✔
1345
                ipv4Addrs[0] = &net.TCPAddr{
48✔
1346
                        IP:   ip,
48✔
1347
                        Port: rapid.IntRange(1, 65535).Draw(t, "port4"),
48✔
1348
                }
48✔
1349

48✔
1350
                ipv4Record := tlv.ZeroRecordT[tlv.TlvType5, IPV4Addrs]()
48✔
1351
                ipv4Record.Val = ipv4Addrs
48✔
1352
                msg.IPV4Addrs = tlv.SomeRecordT(ipv4Record)
48✔
1353
        }
48✔
1354

1355
        if rapid.Bool().Draw(t, "includeIPV6Addrs") {
148✔
1356
                ipv6Addrs := make(IPV6Addrs, 1)
48✔
1357
                ip := make(net.IP, 16)
48✔
1358
                // Generate random IPv6 address.
48✔
1359
                for j := 0; j < 16; j++ {
816✔
1360
                        ip[j] = uint8(rapid.IntRange(0, 255).Draw(
768✔
1361
                                t, fmt.Sprintf("ip6_%d", j)),
768✔
1362
                        )
768✔
1363
                }
768✔
1364

1365
                ipv6Addrs[0] = &net.TCPAddr{
48✔
1366
                        IP:   ip,
48✔
1367
                        Port: rapid.IntRange(1, 65535).Draw(t, "port6"),
48✔
1368
                }
48✔
1369

48✔
1370
                ipv6Record := tlv.ZeroRecordT[tlv.TlvType7, IPV6Addrs]()
48✔
1371
                ipv6Record.Val = ipv6Addrs
48✔
1372
                msg.IPV6Addrs = tlv.SomeRecordT(ipv6Record)
48✔
1373
        }
1374

1375
        if rapid.Bool().Draw(t, "includeTorV3Addrs") {
159✔
1376
                torV3Addrs := make(TorV3Addrs, 1)
59✔
1377
                onionBytes := rapid.SliceOfN(rapid.Byte(), 35, 35).Draw(
59✔
1378
                        t, "onion",
59✔
1379
                )
59✔
1380
                onionService := tor.Base32Encoding.EncodeToString(onionBytes) +
59✔
1381
                        tor.OnionSuffix
59✔
1382

59✔
1383
                torV3Addrs[0] = &tor.OnionAddr{
59✔
1384
                        OnionService: onionService,
59✔
1385
                        Port: rapid.IntRange(1, 65535).Draw(
59✔
1386
                                t, "torPort",
59✔
1387
                        ),
59✔
1388
                }
59✔
1389

59✔
1390
                torV3Record := tlv.ZeroRecordT[tlv.TlvType9, TorV3Addrs]()
59✔
1391
                torV3Record.Val = torV3Addrs
59✔
1392
                msg.TorV3Addrs = tlv.SomeRecordT(torV3Record)
59✔
1393
        }
59✔
1394

1395
        if rapid.Bool().Draw(t, "includeDNSHostName") {
147✔
1396
                // Generate a valid DNS hostname.
47✔
1397
                hostname := genValidHostname(t)
47✔
1398
                port := rapid.Uint16Range(1, 65535).Draw(t, "dnsPort")
47✔
1399

47✔
1400
                dnsAddr := DNSAddress{
47✔
1401
                        Hostname: hostname,
47✔
1402
                        Port:     port,
47✔
1403
                }
47✔
1404

47✔
1405
                dnsRecord := tlv.ZeroRecordT[tlv.TlvType11, DNSAddress]()
47✔
1406
                dnsRecord.Val = dnsAddr
47✔
1407
                msg.DNSHostName = tlv.SomeRecordT(dnsRecord)
47✔
1408
        }
47✔
1409

1410
        randRecs, _ := RandSignedRangeRecords(t)
100✔
1411
        if len(randRecs) > 0 {
178✔
1412
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
78✔
1413
        }
78✔
1414

1415
        return msg
100✔
1416
}
1417

1418
// A compile time check to ensure OpenChannel implements the TestMessage
1419
// interface.
1420
var _ TestMessage = (*OpenChannel)(nil)
1421

1422
// RandTestMessage populates the message with random data suitable for testing.
1423
// It uses the rapid testing framework to generate random values.
1424
//
1425
// This is part of the TestMessage interface.
1426
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
100✔
1427
        chainHash := RandChainHash(t)
100✔
1428
        var hash chainhash.Hash
100✔
1429
        copy(hash[:], chainHash[:])
100✔
1430

100✔
1431
        var pendingChanID [32]byte
100✔
1432
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1433
                t, "pendingChanID",
100✔
1434
        )
100✔
1435
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1436

100✔
1437
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
1438
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
100✔
1439
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
1440

100✔
1441
        var channelFlags FundingFlag
100✔
1442
        if rapid.Bool().Draw(t, "announceChannel") {
146✔
1443
                channelFlags |= FFAnnounceChannel
46✔
1444
        }
46✔
1445

1446
        var localNonce OptMusig2NonceTLV
100✔
1447
        if includeLocalNonce {
154✔
1448
                nonce := RandMusig2Nonce(t)
54✔
1449
                localNonce = tlv.SomeRecordT(
54✔
1450
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
54✔
1451
                )
54✔
1452
        }
54✔
1453

1454
        var channelType *ChannelType
100✔
1455
        if includeChannelType {
150✔
1456
                channelType = RandChannelType(t)
50✔
1457
        }
50✔
1458

1459
        var leaseExpiry *LeaseExpiry
100✔
1460
        if includeLeaseExpiry {
150✔
1461
                leaseExpiry = RandLeaseExpiry(t)
50✔
1462
        }
50✔
1463

1464
        return &OpenChannel{
100✔
1465
                ChainHash:        hash,
100✔
1466
                PendingChannelID: pendingChanID,
100✔
1467
                FundingAmount: btcutil.Amount(
100✔
1468
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
100✔
1469
                ),
100✔
1470
                PushAmount: MilliSatoshi(
100✔
1471
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
100✔
1472
                ),
100✔
1473
                DustLimit: btcutil.Amount(
100✔
1474
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
100✔
1475
                ),
100✔
1476
                MaxValueInFlight: MilliSatoshi(
100✔
1477
                        rapid.IntRange(10000, 1000000).Draw(
100✔
1478
                                t, "maxValueInFlight",
100✔
1479
                        ),
100✔
1480
                ),
100✔
1481
                ChannelReserve: btcutil.Amount(
100✔
1482
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
100✔
1483
                ),
100✔
1484
                HtlcMinimum: MilliSatoshi(
100✔
1485
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
100✔
1486
                ),
100✔
1487
                FeePerKiloWeight: uint32(
100✔
1488
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
100✔
1489
                ),
100✔
1490
                CsvDelay: uint16(
100✔
1491
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
100✔
1492
                ),
100✔
1493
                MaxAcceptedHTLCs: uint16(
100✔
1494
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
100✔
1495
                ),
100✔
1496
                FundingKey:            RandPubKey(t),
100✔
1497
                RevocationPoint:       RandPubKey(t),
100✔
1498
                PaymentPoint:          RandPubKey(t),
100✔
1499
                DelayedPaymentPoint:   RandPubKey(t),
100✔
1500
                HtlcPoint:             RandPubKey(t),
100✔
1501
                FirstCommitmentPoint:  RandPubKey(t),
100✔
1502
                ChannelFlags:          channelFlags,
100✔
1503
                UpfrontShutdownScript: RandDeliveryAddress(t),
100✔
1504
                ChannelType:           channelType,
100✔
1505
                LeaseExpiry:           leaseExpiry,
100✔
1506
                LocalNonce:            localNonce,
100✔
1507
                ExtraData:             RandExtraOpaqueData(t, nil),
100✔
1508
        }
100✔
1509
}
1510

1511
// A compile time check to ensure Ping implements the lnwire.TestMessage
1512
// interface.
1513
var _ TestMessage = (*Ping)(nil)
1514

1515
// RandTestMessage populates the message with random data suitable for testing.
1516
// It uses the rapid testing framework to generate random values.
1517
//
1518
// This is part of the TestMessage interface.
1519
func (p *Ping) RandTestMessage(t *rapid.T) Message {
100✔
1520
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
100✔
1521
                t, "numPongBytes"),
100✔
1522
        )
100✔
1523

100✔
1524
        // Generate padding bytes (but keeping within allowed message size)
100✔
1525
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
100✔
1526
        maxPaddingLen := MaxMsgBody - 4
100✔
1527
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
100✔
1528
                t, "paddingLen",
100✔
1529
        )
100✔
1530
        padding := make(PingPayload, paddingLen)
100✔
1531

100✔
1532
        // Fill padding with random bytes
100✔
1533
        for i := 0; i < paddingLen; i++ {
916,395✔
1534
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
916,295✔
1535
                        t, fmt.Sprintf("paddingByte%d", i)),
916,295✔
1536
                )
916,295✔
1537
        }
916,295✔
1538

1539
        return &Ping{
100✔
1540
                NumPongBytes: numPongBytes,
100✔
1541
                PaddingBytes: padding,
100✔
1542
        }
100✔
1543
}
1544

1545
// A compile time check to ensure Pong implements the lnwire.TestMessage
1546
// interface.
1547
var _ TestMessage = (*Pong)(nil)
1548

1549
// RandTestMessage populates the message with random data suitable for testing.
1550
// It uses the rapid testing framework to generate random values.
1551
//
1552
// This is part of the TestMessage interface.
1553
func (p *Pong) RandTestMessage(t *rapid.T) Message {
100✔
1554
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
100✔
1555
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
100✔
1556
                t, "pongPayload",
100✔
1557
        )
100✔
1558

100✔
1559
        return &Pong{
100✔
1560
                PongBytes: payload,
100✔
1561
        }
100✔
1562
}
100✔
1563

1564
// A compile time check to ensure QueryChannelRange implements the
1565
// lnwire.TestMessage interface.
1566
var _ TestMessage = (*QueryChannelRange)(nil)
1567

1568
// RandTestMessage populates the message with random data suitable for testing.
1569
// It uses the rapid testing framework to generate random values.
1570
//
1571
// This is part of the TestMessage interface.
1572
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
100✔
1573
        msg := &QueryChannelRange{
100✔
1574
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1575
                        t, "firstBlockHeight"),
100✔
1576
                ),
100✔
1577
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1578
                        t, "numBlocks"),
100✔
1579
                ),
100✔
1580
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1581
        }
100✔
1582

100✔
1583
        // Generate chain hash
100✔
1584
        chainHash := RandChainHash(t)
100✔
1585
        var chainHashObj chainhash.Hash
100✔
1586
        copy(chainHashObj[:], chainHash[:])
100✔
1587
        msg.ChainHash = chainHashObj
100✔
1588

100✔
1589
        // Randomly include QueryOptions
100✔
1590
        if rapid.Bool().Draw(t, "includeQueryOptions") {
150✔
1591
                queryOptions := &QueryOptions{}
50✔
1592
                *queryOptions = QueryOptions(*RandFeatureVector(t))
50✔
1593
                msg.QueryOptions = queryOptions
50✔
1594
        }
50✔
1595

1596
        return msg
100✔
1597
}
1598

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

1603
// RandTestMessage populates the message with random data suitable for testing.
1604
// It uses the rapid testing framework to generate random values.
1605
//
1606
// This is part of the TestMessage interface.
1607
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
100✔
1608
        var chainHash chainhash.Hash
100✔
1609
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1610
        copy(chainHash[:], hashBytes)
100✔
1611

100✔
1612
        encodingType := EncodingSortedPlain
100✔
1613
        if rapid.Bool().Draw(t, "useZlibEncoding") {
155✔
1614
                encodingType = EncodingSortedZlib
55✔
1615
        }
55✔
1616

1617
        msg := &QueryShortChanIDs{
100✔
1618
                ChainHash:    chainHash,
100✔
1619
                EncodingType: encodingType,
100✔
1620
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1621
                noSort:       false,
100✔
1622
        }
100✔
1623

100✔
1624
        numIDs := rapid.IntRange(2, 20).Draw(t, "numShortChanIDs")
100✔
1625

100✔
1626
        // Generate sorted short channel IDs.
100✔
1627
        shortChanIDs := make([]ShortChannelID, numIDs)
100✔
1628
        for i := 0; i < numIDs; i++ {
1,031✔
1629
                shortChanIDs[i] = RandShortChannelID(t)
931✔
1630

931✔
1631
                // Ensure they're properly sorted.
931✔
1632
                if i > 0 && shortChanIDs[i].ToUint64() <=
931✔
1633
                        shortChanIDs[i-1].ToUint64() {
1,592✔
1634

661✔
1635
                        // Ensure this ID is larger than the previous one.
661✔
1636
                        shortChanIDs[i] = NewShortChanIDFromInt(
661✔
1637
                                shortChanIDs[i-1].ToUint64() + 1,
661✔
1638
                        )
661✔
1639
                }
661✔
1640
        }
1641

1642
        msg.ShortChanIDs = shortChanIDs
100✔
1643

100✔
1644
        return msg
100✔
1645
}
1646

1647
// A compile time check to ensure ReplyChannelRange implements the
1648
// lnwire.TestMessage interface.
1649
var _ TestMessage = (*ReplyChannelRange)(nil)
1650

1651
// RandTestMessage populates the message with random data suitable for testing.
1652
// It uses the rapid testing framework to generate random values.
1653
//
1654
// This is part of the TestMessage interface.
1655
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
100✔
1656
        msg := &ReplyChannelRange{
100✔
1657
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1658
                        t, "firstBlockHeight"),
100✔
1659
                ),
100✔
1660
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1661
                        t, "numBlocks"),
100✔
1662
                ),
100✔
1663
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
100✔
1664
                EncodingType: QueryEncoding(
100✔
1665
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
100✔
1666
                ),
100✔
1667
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1668
        }
100✔
1669

100✔
1670
        msg.ChainHash = RandChainHash(t)
100✔
1671

100✔
1672
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
100✔
1673
        if numShortChanIDs == 0 {
119✔
1674
                return msg
19✔
1675
        }
19✔
1676

1677
        scidSet := fn.NewSet[ShortChannelID]()
81✔
1678
        scids := make([]ShortChannelID, numShortChanIDs)
81✔
1679
        for i := 0; i < numShortChanIDs; i++ {
702✔
1680
                scid := RandShortChannelID(t)
621✔
1681
                for scidSet.Contains(scid) {
691✔
1682
                        scid = RandShortChannelID(t)
70✔
1683
                }
70✔
1684

1685
                scids[i] = scid
621✔
1686

621✔
1687
                scidSet.Add(scid)
621✔
1688
        }
1689

1690
        // Make sure there're no duplicates.
1691
        msg.ShortChanIDs = scids
81✔
1692

81✔
1693
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
122✔
1694
                msg.Timestamps = make(Timestamps, numShortChanIDs)
41✔
1695
                for i := 0; i < numShortChanIDs; i++ {
317✔
1696
                        msg.Timestamps[i] = ChanUpdateTimestamps{
276✔
1697
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
276✔
1698
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
276✔
1699
                        }
276✔
1700
                }
276✔
1701
        }
1702

1703
        return msg
81✔
1704
}
1705

1706
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1707
// lnwire.TestMessage interface.
1708
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1709

1710
// RandTestMessage populates the message with random data suitable for testing.
1711
// It uses the rapid testing framework to generate random values.
1712
//
1713
// This is part of the TestMessage interface.
1714
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
100✔
1715
        var chainHash chainhash.Hash
100✔
1716
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1717
        copy(chainHash[:], hashBytes)
100✔
1718

100✔
1719
        complete := uint8(rapid.IntRange(0, 1).Draw(t, "complete"))
100✔
1720

100✔
1721
        return &ReplyShortChanIDsEnd{
100✔
1722
                ChainHash: chainHash,
100✔
1723
                Complete:  complete,
100✔
1724
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1725
        }
100✔
1726
}
100✔
1727

1728
// RandTestMessage returns a RevokeAndAck message populated with random data.
1729
//
1730
// This is part of the TestMessage interface.
1731
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
100✔
1732
        msg := NewRevokeAndAck()
100✔
1733

100✔
1734
        var chanID ChannelID
100✔
1735
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
100✔
1736
        copy(chanID[:], bytes)
100✔
1737
        msg.ChanID = chanID
100✔
1738

100✔
1739
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
100✔
1740
        copy(msg.Revocation[:], revBytes)
100✔
1741

100✔
1742
        msg.NextRevocationKey = RandPubKey(t)
100✔
1743

100✔
1744
        if rapid.Bool().Draw(t, "includeLocalNonce") {
159✔
1745
                var nonce Musig2Nonce
59✔
1746
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
59✔
1747
                        t, "nonce",
59✔
1748
                )
59✔
1749
                copy(nonce[:], nonceBytes)
59✔
1750

59✔
1751
                msg.LocalNonce = tlv.SomeRecordT(
59✔
1752
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
59✔
1753
                )
59✔
1754
        }
59✔
1755

1756
        return msg
100✔
1757
}
1758

1759
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1760
// interface.
1761
var _ TestMessage = (*Shutdown)(nil)
1762

1763
// RandTestMessage populates the message with random data suitable for testing.
1764
// It uses the rapid testing framework to generate random values.
1765
//
1766
// This is part of the TestMessage interface.
1767
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
100✔
1768
        // Generate random delivery address
100✔
1769
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
100✔
1770
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
100✔
1771

100✔
1772
        // Generate random address length based on type
100✔
1773
        var addrLen int
100✔
1774
        switch addrType {
100✔
1775
        // P2PKH
1776
        case 0:
22✔
1777
                addrLen = 25
22✔
1778
        // P2SH
1779
        case 1:
17✔
1780
                addrLen = 23
17✔
1781
        // P2WPKH
1782
        case 2:
20✔
1783
                addrLen = 22
20✔
1784
        // P2WSH
1785
        case 3:
21✔
1786
                addrLen = 34
21✔
1787
        // P2TR
1788
        case 4:
20✔
1789
                addrLen = 34
20✔
1790
        }
1791

1792
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
100✔
1793
                t, "address",
100✔
1794
        )
100✔
1795

100✔
1796
        // Randomly decide whether to include a shutdown nonce
100✔
1797
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
100✔
1798
        var shutdownNonce ShutdownNonceTLV
100✔
1799

100✔
1800
        if includeNonce {
152✔
1801
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
52✔
1802
        }
52✔
1803

1804
        cr, _ := RandCustomRecords(t, nil)
100✔
1805

100✔
1806
        return &Shutdown{
100✔
1807
                ChannelID:     RandChannelID(t),
100✔
1808
                Address:       addr,
100✔
1809
                ShutdownNonce: shutdownNonce,
100✔
1810
                CustomRecords: cr,
100✔
1811
        }
100✔
1812
}
1813

1814
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1815
// interface.
1816
var _ TestMessage = (*Stfu)(nil)
1817

1818
// RandTestMessage populates the message with random data suitable for testing.
1819
// It uses the rapid testing framework to generate random values.
1820
//
1821
// This is part of the TestMessage interface.
1822
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
106✔
1823
        m := &Stfu{
106✔
1824
                ChanID:    RandChannelID(t),
106✔
1825
                Initiator: rapid.Bool().Draw(t, "initiator"),
106✔
1826
        }
106✔
1827

106✔
1828
        extraData := RandExtraOpaqueData(t, nil)
106✔
1829
        if len(extraData) > 0 {
193✔
1830
                m.ExtraData = extraData
87✔
1831
        }
87✔
1832

1833
        return m
106✔
1834
}
1835

1836
// A compile time check to ensure UpdateAddHTLC implements the
1837
// lnwire.TestMessage interface.
1838
var _ TestMessage = (*UpdateAddHTLC)(nil)
1839

1840
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1841
//
1842
// This is part of the TestMessage interface.
1843
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1844
        msg := &UpdateAddHTLC{
100✔
1845
                ChanID: RandChannelID(t),
100✔
1846
                ID:     rapid.Uint64().Draw(t, "id"),
100✔
1847
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
100✔
1848
                Expiry: rapid.Uint32().Draw(t, "expiry"),
100✔
1849
        }
100✔
1850

100✔
1851
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
100✔
1852
        copy(msg.PaymentHash[:], hashBytes)
100✔
1853

100✔
1854
        onionBytes := rapid.SliceOfN(
100✔
1855
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
100✔
1856
        ).Draw(t, "onionBlob")
100✔
1857
        copy(msg.OnionBlob[:], onionBytes)
100✔
1858

100✔
1859
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
100✔
1860
        if numRecords > 0 {
186✔
1861
                msg.CustomRecords, _ = RandCustomRecords(t, nil)
86✔
1862
        }
86✔
1863

1864
        // 50/50 chance to add a blinding point
1865
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
151✔
1866
                pubKey := RandPubKey(t)
51✔
1867

51✔
1868
                msg.BlindingPoint = tlv.SomeRecordT(
51✔
1869
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
51✔
1870
                )
51✔
1871
        }
51✔
1872

1873
        return msg
100✔
1874
}
1875

1876
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1877
// interface.
1878
var _ TestMessage = (*UpdateFailHTLC)(nil)
1879

1880
// RandTestMessage populates the message with random data suitable for testing.
1881
// It uses the rapid testing framework to generate random values.
1882
//
1883
// This is part of the TestMessage interface.
1884
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1885
        return &UpdateFailHTLC{
100✔
1886
                ChanID:    RandChannelID(t),
100✔
1887
                ID:        rapid.Uint64().Draw(t, "id"),
100✔
1888
                Reason:    RandOpaqueReason(t),
100✔
1889
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1890
        }
100✔
1891
}
100✔
1892

1893
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1894
// TestMessage interface.
1895
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1896

1897
// RandTestMessage populates the message with random data suitable for testing.
1898
// It uses the rapid testing framework to generate random values.
1899
//
1900
// This is part of the TestMessage interface.
1901
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1902
        return &UpdateFailMalformedHTLC{
100✔
1903
                ChanID:       RandChannelID(t),
100✔
1904
                ID:           rapid.Uint64().Draw(t, "id"),
100✔
1905
                ShaOnionBlob: RandSHA256Hash(t),
100✔
1906
                FailureCode:  RandFailCode(t),
100✔
1907
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1908
        }
100✔
1909
}
100✔
1910

1911
// A compile time check to ensure UpdateFee implements the TestMessage
1912
// interface.
1913
var _ TestMessage = (*UpdateFee)(nil)
1914

1915
// RandTestMessage populates the message with random data suitable for testing.
1916
// It uses the rapid testing framework to generate random values.
1917
//
1918
// This is part of the TestMessage interface.
1919
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
100✔
1920
        return &UpdateFee{
100✔
1921
                ChanID:    RandChannelID(t),
100✔
1922
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
100✔
1923
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1924
        }
100✔
1925
}
100✔
1926

1927
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1928
// interface.
1929
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1930

1931
// RandTestMessage populates the message with random data suitable for testing.
1932
// It uses the rapid testing framework to generate random values.
1933
//
1934
// This is part of the TestMessage interface.
1935
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1936
        msg := &UpdateFulfillHTLC{
100✔
1937
                ChanID:          RandChannelID(t),
100✔
1938
                ID:              rapid.Uint64().Draw(t, "id"),
100✔
1939
                PaymentPreimage: RandPaymentPreimage(t),
100✔
1940
        }
100✔
1941

100✔
1942
        cr, ignoreRecords := RandCustomRecords(t, nil)
100✔
1943
        msg.CustomRecords = cr
100✔
1944

100✔
1945
        randData := RandExtraOpaqueData(t, ignoreRecords)
100✔
1946
        if len(randData) > 0 {
179✔
1947
                msg.ExtraData = randData
79✔
1948
        }
79✔
1949

1950
        return msg
100✔
1951
}
1952

1953
// A compile time check to ensure Warning implements the lnwire.TestMessage
1954
// interface.
1955
var _ TestMessage = (*Warning)(nil)
1956

1957
// RandTestMessage populates the message with random data suitable for testing.
1958
// It uses the rapid testing framework to generate random values.
1959
//
1960
// This is part of the TestMessage interface.
1961
func (c *Warning) RandTestMessage(t *rapid.T) Message {
109✔
1962
        msg := &Warning{
109✔
1963
                ChanID: RandChannelID(t),
109✔
1964
        }
109✔
1965

109✔
1966
        useASCII := rapid.Bool().Draw(t, "useASCII")
109✔
1967
        if useASCII {
169✔
1968
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
60✔
1969
                data := make([]byte, length)
60✔
1970
                for i := 0; i < length; i++ {
1,531✔
1971
                        data[i] = byte(
1,471✔
1972
                                rapid.IntRange(32, 126).Draw(
1,471✔
1973
                                        t, fmt.Sprintf("warningDataByte-%d", i),
1,471✔
1974
                                ),
1,471✔
1975
                        )
1,471✔
1976
                }
1,471✔
1977
                msg.Data = data
60✔
1978
        } else {
49✔
1979
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
49✔
1980
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
49✔
1981
                        t, "warningData",
49✔
1982
                )
49✔
1983
        }
49✔
1984

1985
        return msg
109✔
1986
}
1987

1988
// A compile time check to ensure Error implements the lnwire.TestMessage
1989
// interface.
1990
var _ TestMessage = (*Error)(nil)
1991

1992
// RandTestMessage populates the message with random data suitable for testing.
1993
// It uses the rapid testing framework to generate random values.
1994
//
1995
// This is part of the TestMessage interface.
1996
func (c *Error) RandTestMessage(t *rapid.T) Message {
100✔
1997
        msg := &Error{
100✔
1998
                ChanID: RandChannelID(t),
100✔
1999
        }
100✔
2000

100✔
2001
        useASCII := rapid.Bool().Draw(t, "useASCII")
100✔
2002
        if useASCII {
145✔
2003
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
45✔
2004
                data := make([]byte, length)
45✔
2005
                for i := 0; i < length; i++ {
1,213✔
2006
                        data[i] = byte(
1,168✔
2007
                                rapid.IntRange(32, 126).Draw(
1,168✔
2008
                                        t, fmt.Sprintf("errorDataByte-%d", i),
1,168✔
2009
                                ),
1,168✔
2010
                        )
1,168✔
2011
                }
1,168✔
2012
                msg.Data = data
45✔
2013
        } else {
55✔
2014
                // Generate random binary data
55✔
2015
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
55✔
2016
                msg.Data = rapid.SliceOfN(
55✔
2017
                        rapid.Byte(), length, length,
55✔
2018
                ).Draw(t, "errorData")
55✔
2019
        }
55✔
2020

2021
        return msg
100✔
2022
}
2023

2024
// genValidHostname generates a random valid hostname according to BOLT #7
2025
// rules.
2026
func genValidHostname(t *rapid.T) string {
147✔
2027
        // Valid characters: a-z, A-Z, 0-9, -, .
147✔
2028
        validChars := "abcdefghijklmnopqrstuvwxyzABCDE" +
147✔
2029
                "FGHIJKLMNOPQRSTUVWXYZ0123456789-."
147✔
2030

147✔
2031
        // Generate hostname length between 1 and 255 characters.
147✔
2032
        length := rapid.IntRange(1, 255).Draw(t, "hostname_length")
147✔
2033

147✔
2034
        hostname := make([]byte, length)
147✔
2035
        for i := 0; i < length; i++ {
9,542✔
2036
                charIndex := rapid.IntRange(0, len(validChars)-1).Draw(
9,395✔
2037
                        t, fmt.Sprintf("char_%d", i),
9,395✔
2038
                )
9,395✔
2039
                hostname[i] = validChars[charIndex]
9,395✔
2040
        }
9,395✔
2041

2042
        return string(hostname)
147✔
2043
}
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