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

lightningnetwork / lnd / 18311693651

07 Oct 2025 11:50AM UTC coverage: 66.67% (+0.03%) from 66.641%
18311693651

Pull #10273

github

web-flow
Merge f3ebaff4e into 87aed739e
Pull Request #10273: fix height hint Zero issue in utxonursery

37 of 39 new or added lines in 1 file covered. (94.87%)

60 existing lines in 16 files now uncovered.

137303 of 205944 relevant lines covered (66.67%)

21266.08 hits per line

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

99.79
/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 {
100✔
40
        var pendingChanID [32]byte
100✔
41
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
42
                t, "pendingChanID",
100✔
43
        )
100✔
44
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
45

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

100✔
51
        if includeChannelType {
151✔
52
                channelType = RandChannelType(t)
51✔
53
        }
51✔
54

55
        var leaseExpiry *LeaseExpiry
100✔
56
        if includeLeaseExpiry {
149✔
57
                leaseExpiry = RandLeaseExpiry(t)
49✔
58
        }
49✔
59

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

68
        return &AcceptChannel{
100✔
69
                PendingChannelID: pendingChanID,
100✔
70
                DustLimit: btcutil.Amount(
100✔
71
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
100✔
72
                ),
100✔
73
                MaxValueInFlight: MilliSatoshi(
100✔
74
                        rapid.IntRange(10000, 1000000).Draw(
100✔
75
                                t, "maxValueInFlight",
100✔
76
                        ),
100✔
77
                ),
100✔
78
                ChannelReserve: btcutil.Amount(
100✔
79
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
100✔
80
                ),
100✔
81
                HtlcMinimum: MilliSatoshi(
100✔
82
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
100✔
83
                ),
100✔
84
                MinAcceptDepth: uint32(
100✔
85
                        rapid.IntRange(1, 10).Draw(t, "minAcceptDepth"),
100✔
86
                ),
100✔
87
                CsvDelay: uint16(
100✔
88
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
100✔
89
                ),
100✔
90
                MaxAcceptedHTLCs: uint16(
100✔
91
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
100✔
92
                ),
100✔
93
                FundingKey:            RandPubKey(t),
100✔
94
                RevocationPoint:       RandPubKey(t),
100✔
95
                PaymentPoint:          RandPubKey(t),
100✔
96
                DelayedPaymentPoint:   RandPubKey(t),
100✔
97
                HtlcPoint:             RandPubKey(t),
100✔
98
                FirstCommitmentPoint:  RandPubKey(t),
100✔
99
                UpfrontShutdownScript: RandDeliveryAddress(t),
100✔
100
                ChannelType:           channelType,
100✔
101
                LeaseExpiry:           leaseExpiry,
100✔
102
                LocalNonce:            localNonce,
100✔
103
                ExtraData:             RandExtraOpaqueData(t, nil),
100✔
104
        }
100✔
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 {
173✔
153
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
73✔
154
        }
73✔
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 {
146✔
184
                nodeID1, nodeID2 = nodeID2, nodeID1
46✔
185
        }
46✔
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 {
149✔
227
                nodeID1, nodeID2 = nodeID2, nodeID1
49✔
228
        }
49✔
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 {
177✔
261
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
77✔
262
        }
77✔
263

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

275
        if rapid.Bool().Draw(t, "includeBitcoinKey2") {
145✔
276
                var bitcoinKey2 [33]byte
45✔
277
                copy(bitcoinKey2[:], RandPubKey(t).SerializeCompressed())
45✔
278
                msg.BitcoinKey2 = tlv.SomeRecordT(
45✔
279
                        tlv.NewPrimitiveRecord[tlv.TlvType14, [33]byte](
45✔
280
                                bitcoinKey2,
45✔
281
                        ),
45✔
282
                )
45✔
283
        }
45✔
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 {
145✔
328
                scid := RandShortChannelID(t)
45✔
329
                msg.AliasScid = &scid
45✔
330
        }
45✔
331

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

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

344
        if includeAnnouncementBitcoinNonce {
152✔
345
                nonce := RandMusig2Nonce(t)
52✔
346
                msg.AnnouncementBitcoinNonce = tlv.SomeRecordT(
52✔
347
                        tlv.NewRecordT[tlv.TlvType2, Musig2Nonce](nonce),
52✔
348
                )
52✔
349
        }
52✔
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 {
146✔
381
                nonce := RandMusig2Nonce(t)
46✔
382
                msg.LocalNonce = SomeMusig2Nonce(nonce)
46✔
383
        }
46✔
384

385
        if includeDynHeight {
148✔
386
                height := DynHeight(rapid.Uint64().Draw(t, "dynHeight"))
48✔
387
                msg.DynHeight = fn.Some(height)
48✔
388
        }
48✔
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 {
159✔
407
                msgFlags |= ChanUpdateRequiredMaxHtlc
59✔
408
        }
59✔
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 {
143✔
415
                chanFlags |= ChanUpdateDirection
43✔
416
        }
43✔
417

418
        // Randomly decide if channel is disabled
419
        isDisabled := rapid.Bool().Draw(t, "isDisabled")
100✔
420
        if isDisabled {
150✔
421
                chanFlags |= ChanUpdateDisabled
50✔
422
        }
50✔
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 {
141✔
434
                maxHtlc = 0
41✔
435
        }
41✔
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 {
147✔
447
                if customRecords == nil {
57✔
448
                        customRecords = make(CustomRecords)
10✔
449
                }
10✔
450

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

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

47✔
470
                customRecords[uint64(FeeRecordType)] = b.Bytes()
47✔
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") {
152✔
517
                disabledFlags |= ChanUpdateDisableIncoming
52✔
518
        }
52✔
519
        if rapid.Bool().Draw(t, "disableOutgoing") {
151✔
520
                disabledFlags |= ChanUpdateDisableOutgoing
51✔
521
        }
51✔
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") {
152✔
575
                base := rapid.IntRange(-1000, 1000).Draw(t, "inFeeBase")
52✔
576
                rate := rapid.IntRange(-1000, 1000).Draw(t, "inFeeProp")
52✔
577
                fee := Fee{
52✔
578
                        BaseFee: int32(base),
52✔
579
                        FeeRate: int32(rate),
52✔
580
                }
52✔
581
                msg.InboundFee = tlv.SomeRecordT(
52✔
582
                        tlv.NewRecordT[tlv.TlvType55555](fee),
52✔
583
                )
52✔
584
        }
52✔
585

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

100✔
589
        if rapid.Bool().Draw(t, "isSecondPeer") {
158✔
590
                msg.SecondPeer = tlv.SomeRecordT(
58✔
591
                        tlv.RecordT[tlv.TlvType8, TrueBoolean]{},
58✔
592
                )
58✔
593
        }
58✔
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 {
100✔
607
        msg := &ClosingComplete{
100✔
608
                ChannelID: RandChannelID(t),
100✔
609
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
100✔
610
                        t, "feeSatoshis"),
100✔
611
                ),
100✔
612
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
100✔
613
                        t, "lockTime",
100✔
614
                ),
100✔
615
                CloseeScript: RandDeliveryAddress(t),
100✔
616
                CloserScript: RandDeliveryAddress(t),
100✔
617
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
618
        }
100✔
619

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

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

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

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

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

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

661
        return msg
100✔
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 {
100✔
673
        msg := &ClosingSig{
100✔
674
                ChannelID:    RandChannelID(t),
100✔
675
                CloseeScript: RandDeliveryAddress(t),
100✔
676
                CloserScript: RandDeliveryAddress(t),
100✔
677
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
678
        }
100✔
679

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

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

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

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

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

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

721
        return msg
100✔
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 {
160✔
747
                sigBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
60✔
748
                        t, "sigScalar",
60✔
749
                )
60✔
750
                var s btcec.ModNScalar
60✔
751
                _ = s.SetByteSlice(sigBytes)
60✔
752

60✔
753
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
60✔
754
                msg.Signature = Sig{}
60✔
755
        } else {
100✔
756
                msg.Signature = RandSignature(t)
40✔
757
        }
40✔
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++ {
855✔
781
                htlcSigs[i] = RandSignature(t)
755✔
782
        }
755✔
783

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

788
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
789
        if includePartialSig {
148✔
790
                sigWithNonce := RandPartialSigWithNonce(t)
48✔
791
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
48✔
792
        }
48✔
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 {
11✔
806
        msgType := MessageType(
11✔
807
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
11✔
808
                        t, "customMsgType",
11✔
809
                ),
11✔
810
        )
11✔
811

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

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

822
        return msg
11✔
823
}
824

825
// A compile time check to ensure DynAck implements the lnwire.TestMessage
826
// interface.
827
var _ TestMessage = (*DynAck)(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 (da *DynAck) RandTestMessage(t *rapid.T) Message {
100✔
834
        msg := &DynAck{
100✔
835
                ChanID: RandChannelID(t),
100✔
836
        }
100✔
837

100✔
838
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
839
        if includeLocalNonce {
146✔
840
                nonce := RandMusig2Nonce(t)
46✔
841
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
46✔
842
                msg.LocalNonce = tlv.SomeRecordT(rec)
46✔
843
        }
46✔
844

845
        // Create a tlv type lists to hold all known records which will be
846
        // ignored when creating ExtraData records.
847
        ignoreRecords := fn.NewSet[uint64]()
100✔
848
        for i := range uint64(15) {
1,600✔
849
                // Ignore known records.
1,500✔
850
                if i%2 == 0 {
2,300✔
851
                        ignoreRecords.Add(i)
800✔
852
                }
800✔
853
        }
854

855
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
100✔
856

100✔
857
        return msg
100✔
858
}
859

860
// A compile time check to ensure DynPropose implements the lnwire.TestMessage
861
// interface.
862
var _ TestMessage = (*DynPropose)(nil)
863

864
// RandTestMessage populates the message with random data suitable for testing.
865
// It uses the rapid testing framework to generate random values.
866
//
867
// This is part of the TestMessage interface.
868
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
100✔
869
        msg := &DynPropose{
100✔
870
                ChanID: RandChannelID(t),
100✔
871
        }
100✔
872

100✔
873
        // Randomly decide which optional fields to include
100✔
874
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
100✔
875
        includeMaxValueInFlight := rapid.Bool().Draw(
100✔
876
                t, "includeMaxValueInFlight",
100✔
877
        )
100✔
878
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
100✔
879
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
100✔
880
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
100✔
881
                t, "includeMaxAcceptedHTLCs",
100✔
882
        )
100✔
883
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
884

100✔
885
        // Generate random values for each included field
100✔
886
        if includeDustLimit {
147✔
887
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
47✔
888
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
47✔
889
                rec.Val = tlv.NewBigSizeT(val)
47✔
890
                msg.DustLimit = tlv.SomeRecordT(rec)
47✔
891
        }
47✔
892

893
        if includeMaxValueInFlight {
148✔
894
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
48✔
895
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
48✔
896
                rec.Val = val
48✔
897
                msg.MaxValueInFlight = tlv.SomeRecordT(rec)
48✔
898
        }
48✔
899

900
        if includeChannelReserve {
145✔
901
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
45✔
902
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
45✔
903
                rec.Val = tlv.NewBigSizeT(val)
45✔
904
                msg.ChannelReserve = tlv.SomeRecordT(rec)
45✔
905
        }
45✔
906

907
        if includeCsvDelay {
155✔
908
                csvDelay := msg.CsvDelay.Zero()
55✔
909
                val := rapid.Uint16().Draw(t, "csvDelay")
55✔
910
                csvDelay.Val = val
55✔
911
                msg.CsvDelay = tlv.SomeRecordT(csvDelay)
55✔
912
        }
55✔
913

914
        if includeMaxAcceptedHTLCs {
143✔
915
                maxHtlcs := msg.MaxAcceptedHTLCs.Zero()
43✔
916
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
43✔
917
                msg.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
43✔
918
        }
43✔
919

920
        if includeChannelType {
159✔
921
                chanType := msg.ChannelType.Zero()
59✔
922
                chanType.Val = *RandChannelType(t)
59✔
923
                msg.ChannelType = tlv.SomeRecordT(chanType)
59✔
924
        }
59✔
925

926
        // Create a tlv type lists to hold all known records which will be
927
        // ignored when creating ExtraData records.
928
        ignoreRecords := fn.NewSet[uint64]()
100✔
929
        for i := range uint64(13) {
1,400✔
930
                // Ignore known records.
1,300✔
931
                if i%2 == 0 {
2,000✔
932
                        ignoreRecords.Add(i)
700✔
933
                }
700✔
934
        }
935

936
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
100✔
937

100✔
938
        return msg
100✔
939
}
940

941
// A compile time check to ensure DynReject implements the lnwire.TestMessage
942
// interface.
943
var _ TestMessage = (*DynReject)(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.
949
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
100✔
950
        featureVec := NewRawFeatureVector()
100✔
951

100✔
952
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
100✔
953
        for i := 0; i < numFeatures; i++ {
451✔
954
                bit := FeatureBit(
351✔
955
                        rapid.IntRange(0, 31).Draw(
351✔
956
                                t, fmt.Sprintf("rejectionBit-%d", i),
351✔
957
                        ),
351✔
958
                )
351✔
959
                featureVec.Set(bit)
351✔
960
        }
351✔
961

962
        var extraData ExtraOpaqueData
100✔
963
        randData := RandExtraOpaqueData(t, nil)
100✔
964
        if len(randData) > 0 {
183✔
965
                extraData = randData
83✔
966
        }
83✔
967

968
        return &DynReject{
100✔
969
                ChanID:           RandChannelID(t),
100✔
970
                UpdateRejections: *featureVec,
100✔
971
                ExtraData:        extraData,
100✔
972
        }
100✔
973
}
974

975
// A compile time check to ensure DynCommit implements the lnwire.TestMessage
976
// interface.
977
var _ TestMessage = (*DynCommit)(nil)
978

979
// RandTestMessage populates the message with random data suitable for testing.
980
// It uses the rapid testing framework to generate random values.
981
//
982
// This is part of the TestMessage interface.
983
func (dc *DynCommit) RandTestMessage(t *rapid.T) Message {
100✔
984
        chanID := RandChannelID(t)
100✔
985

100✔
986
        da := &DynAck{
100✔
987
                ChanID: chanID,
100✔
988
        }
100✔
989

100✔
990
        dp := &DynPropose{
100✔
991
                ChanID: chanID,
100✔
992
        }
100✔
993

100✔
994
        // Randomly decide which optional fields to include
100✔
995
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
100✔
996
        includeMaxValueInFlight := rapid.Bool().Draw(
100✔
997
                t, "includeMaxValueInFlight",
100✔
998
        )
100✔
999
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
100✔
1000
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
100✔
1001
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
100✔
1002
                t, "includeMaxAcceptedHTLCs",
100✔
1003
        )
100✔
1004
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
1005

100✔
1006
        // Generate random values for each included field
100✔
1007
        if includeDustLimit {
147✔
1008
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
47✔
1009
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
47✔
1010
                rec.Val = tlv.NewBigSizeT(val)
47✔
1011
                dp.DustLimit = tlv.SomeRecordT(rec)
47✔
1012
        }
47✔
1013

1014
        if includeMaxValueInFlight {
152✔
1015
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
52✔
1016
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
52✔
1017
                rec.Val = val
52✔
1018
                dp.MaxValueInFlight = tlv.SomeRecordT(rec)
52✔
1019
        }
52✔
1020

1021
        if includeChannelReserve {
155✔
1022
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
55✔
1023
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
55✔
1024
                rec.Val = tlv.NewBigSizeT(val)
55✔
1025
                dp.ChannelReserve = tlv.SomeRecordT(rec)
55✔
1026
        }
55✔
1027

1028
        if includeCsvDelay {
149✔
1029
                csvDelay := dp.CsvDelay.Zero()
49✔
1030
                val := rapid.Uint16().Draw(t, "csvDelay")
49✔
1031
                csvDelay.Val = val
49✔
1032
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
49✔
1033
        }
49✔
1034

1035
        if includeMaxAcceptedHTLCs {
146✔
1036
                maxHtlcs := dp.MaxAcceptedHTLCs.Zero()
46✔
1037
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
46✔
1038
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
46✔
1039
        }
46✔
1040

1041
        if includeChannelType {
158✔
1042
                chanType := dp.ChannelType.Zero()
58✔
1043
                chanType.Val = *RandChannelType(t)
58✔
1044
                dp.ChannelType = tlv.SomeRecordT(chanType)
58✔
1045
        }
58✔
1046

1047
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
1048
        if includeLocalNonce {
145✔
1049
                nonce := RandMusig2Nonce(t)
45✔
1050
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
45✔
1051
                da.LocalNonce = tlv.SomeRecordT(rec)
45✔
1052
        }
45✔
1053

1054
        // Create a tlv type lists to hold all known records which will be
1055
        // ignored when creating ExtraData records.
1056
        ignoreRecords := fn.NewSet[uint64]()
100✔
1057
        for i := range uint64(15) {
1,600✔
1058
                // Ignore known records.
1,500✔
1059
                if i%2 == 0 {
2,300✔
1060
                        ignoreRecords.Add(i)
800✔
1061
                }
800✔
1062
        }
1063
        msg := &DynCommit{
100✔
1064
                DynPropose: *dp,
100✔
1065
                DynAck:     *da,
100✔
1066
        }
100✔
1067

100✔
1068
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
100✔
1069

100✔
1070
        return msg
100✔
1071
}
1072

1073
// A compile time check to ensure FundingCreated implements the TestMessage
1074
// interface.
1075
var _ TestMessage = (*FundingCreated)(nil)
1076

1077
// RandTestMessage populates the message with random data suitable for testing.
1078
// It uses the rapid testing framework to generate random values.
1079
//
1080
// This is part of the TestMessage interface.
1081
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
100✔
1082
        var pendingChanID [32]byte
100✔
1083
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1084
                t, "pendingChanID",
100✔
1085
        )
100✔
1086
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1087

100✔
1088
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
1089
        var partialSig OptPartialSigWithNonceTLV
100✔
1090
        var commitSig Sig
100✔
1091

100✔
1092
        if includePartialSig {
151✔
1093
                sigWithNonce := RandPartialSigWithNonce(t)
51✔
1094
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
51✔
1095

51✔
1096
                // When using partial sig, CommitSig should be empty/blank.
51✔
1097
                commitSig = Sig{}
51✔
1098
        } else {
100✔
1099
                commitSig = RandSignature(t)
49✔
1100
        }
49✔
1101

1102
        return &FundingCreated{
100✔
1103
                PendingChannelID: pendingChanID,
100✔
1104
                FundingPoint:     RandOutPoint(t),
100✔
1105
                CommitSig:        commitSig,
100✔
1106
                PartialSig:       partialSig,
100✔
1107
                ExtraData:        RandExtraOpaqueData(t, nil),
100✔
1108
        }
100✔
1109
}
1110

1111
// A compile time check to ensure FundingSigned implements the
1112
// lnwire.TestMessage interface.
1113
var _ TestMessage = (*FundingSigned)(nil)
1114

1115
// RandTestMessage populates the message with random data suitable for testing.
1116
// It uses the rapid testing framework to generate random values.
1117
//
1118
// This is part of the TestMessage interface.
1119
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
100✔
1120
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
1121

100✔
1122
        msg := &FundingSigned{
100✔
1123
                ChanID:    RandChannelID(t),
100✔
1124
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1125
        }
100✔
1126

100✔
1127
        if usePartialSig {
151✔
1128
                sigWithNonce := RandPartialSigWithNonce(t)
51✔
1129
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
51✔
1130

51✔
1131
                msg.CommitSig = Sig{}
51✔
1132
        } else {
100✔
1133
                msg.CommitSig = RandSignature(t)
49✔
1134
        }
49✔
1135

1136
        return msg
100✔
1137
}
1138

1139
// A compile time check to ensure GossipTimestampRange implements the
1140
// lnwire.TestMessage interface.
1141
var _ TestMessage = (*GossipTimestampRange)(nil)
1142

1143
// RandTestMessage populates the message with random data suitable for testing.
1144
// It uses the rapid testing framework to generate random values.
1145
//
1146
// This is part of the TestMessage interface.
1147
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
100✔
1148
        var chainHash chainhash.Hash
100✔
1149
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1150
        copy(chainHash[:], hashBytes)
100✔
1151

100✔
1152
        msg := &GossipTimestampRange{
100✔
1153
                ChainHash:      chainHash,
100✔
1154
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
100✔
1155
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
100✔
1156
                ExtraData:      RandExtraOpaqueData(t, nil),
100✔
1157
        }
100✔
1158

100✔
1159
        includeFirstBlockHeight := rapid.Bool().Draw(
100✔
1160
                t, "includeFirstBlockHeight",
100✔
1161
        )
100✔
1162
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
100✔
1163

100✔
1164
        if includeFirstBlockHeight {
156✔
1165
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
56✔
1166
                msg.FirstBlockHeight = tlv.SomeRecordT(
56✔
1167
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
56✔
1168
                )
56✔
1169
        }
56✔
1170

1171
        if includeBlockRange {
151✔
1172
                blockRange := rapid.Uint32().Draw(t, "blockRange")
51✔
1173
                msg.BlockRange = tlv.SomeRecordT(
51✔
1174
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
51✔
1175
                )
51✔
1176
        }
51✔
1177

1178
        return msg
100✔
1179
}
1180

1181
// RandTestMessage populates the message with random data suitable for testing.
1182
// It uses the rapid testing framework to generate random values.
1183
//
1184
// This is part of the TestMessage interface.
1185
func (msg *Init) RandTestMessage(t *rapid.T) Message {
101✔
1186
        global := NewRawFeatureVector()
101✔
1187
        local := NewRawFeatureVector()
101✔
1188

101✔
1189
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
101✔
1190
        for i := 0; i < numGlobalFeatures; i++ {
896✔
1191
                bit := FeatureBit(
795✔
1192
                        rapid.IntRange(0, 100).Draw(
795✔
1193
                                t, fmt.Sprintf("globalFeatureBit%d", i),
795✔
1194
                        ),
795✔
1195
                )
795✔
1196
                global.Set(bit)
795✔
1197
        }
795✔
1198

1199
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
101✔
1200
        for i := 0; i < numLocalFeatures; i++ {
892✔
1201
                bit := FeatureBit(
791✔
1202
                        rapid.IntRange(0, 100).Draw(
791✔
1203
                                t, fmt.Sprintf("localFeatureBit%d", i),
791✔
1204
                        ),
791✔
1205
                )
791✔
1206
                local.Set(bit)
791✔
1207
        }
791✔
1208

1209
        ignoreRecords := fn.NewSet[uint64]()
101✔
1210

101✔
1211
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
101✔
1212

101✔
1213
        return NewInitMessage(global, local)
101✔
1214
}
1215

1216
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1217
// interface.
1218
var _ TestMessage = (*KickoffSig)(nil)
1219

1220
// RandTestMessage populates the message with random data suitable for testing.
1221
// It uses the rapid testing framework to generate random values.
1222
//
1223
// This is part of the TestMessage interface.
1224
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
100✔
1225
        return &KickoffSig{
100✔
1226
                ChanID:    RandChannelID(t),
100✔
1227
                Signature: RandSignature(t),
100✔
1228
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1229
        }
100✔
1230
}
100✔
1231

1232
// A compile time check to ensure NodeAnnouncement1 implements the
1233
// lnwire.TestMessage interface.
1234
var _ TestMessage = (*NodeAnnouncement1)(nil)
1235

1236
// A compile time check to ensure NodeAnnouncement2 implements the
1237
// lnwire.TestMessage interface.
1238
var _ TestMessage = (*NodeAnnouncement2)(nil)
1239

1240
// RandTestMessage populates the message with random data suitable for testing.
1241
// It uses the rapid testing framework to generate random values.
1242
//
1243
// This is part of the TestMessage interface.
1244
func (a *NodeAnnouncement1) RandTestMessage(t *rapid.T) Message {
100✔
1245
        // Generate random compressed public key for node ID
100✔
1246
        pubKey := RandPubKey(t)
100✔
1247
        var nodeID [33]byte
100✔
1248
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1249

100✔
1250
        // Generate random RGB color
100✔
1251
        rgbColor := color.RGBA{
100✔
1252
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
100✔
1253
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
100✔
1254
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
100✔
1255
        }
100✔
1256

100✔
1257
        return &NodeAnnouncement1{
100✔
1258
                Signature: RandSignature(t),
100✔
1259
                Features:  RandFeatureVector(t),
100✔
1260
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
1261
                        t, "timestamp"),
100✔
1262
                ),
100✔
1263
                NodeID:          nodeID,
100✔
1264
                RGBColor:        rgbColor,
100✔
1265
                Alias:           RandNodeAlias(t),
100✔
1266
                Addresses:       RandNetAddrs(t),
100✔
1267
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
1268
        }
100✔
1269
}
100✔
1270

1271
// RandTestMessage populates the message with random data suitable for testing.
1272
// It uses the rapid testing framework to generate random values.
1273
//
1274
// This is part of the TestMessage interface.
1275
func (n *NodeAnnouncement2) RandTestMessage(t *rapid.T) Message {
100✔
1276
        features := RandFeatureVector(t)
100✔
1277
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
100✔
1278

100✔
1279
        // Generate random compressed public key for node ID
100✔
1280
        pubKey := RandPubKey(t)
100✔
1281
        var nodeID [33]byte
100✔
1282
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1283

100✔
1284
        msg := &NodeAnnouncement2{
100✔
1285
                Features: tlv.NewRecordT[tlv.TlvType0](*features),
100✔
1286
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType2](
100✔
1287
                        blockHeight,
100✔
1288
                ),
100✔
1289
                NodeID:            tlv.NewPrimitiveRecord[tlv.TlvType4](nodeID),
100✔
1290
                ExtraSignedFields: make(map[uint64][]byte),
100✔
1291
        }
100✔
1292

100✔
1293
        msg.Signature.Val = RandSignature(t)
100✔
1294
        msg.Signature.Val.ForceSchnorr()
100✔
1295

100✔
1296
        // Test optional fields one by one
100✔
1297
        if rapid.Bool().Draw(t, "includeColor") {
148✔
1298
                rgbColor := Color{
48✔
1299
                        R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
48✔
1300
                        G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
48✔
1301
                        B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
48✔
1302
                }
48✔
1303
                colorRecord := tlv.ZeroRecordT[tlv.TlvType1, Color]()
48✔
1304
                colorRecord.Val = rgbColor
48✔
1305
                msg.Color = tlv.SomeRecordT(colorRecord)
48✔
1306
        }
48✔
1307

1308
        if rapid.Bool().Draw(t, "includeAlias") {
154✔
1309
                aliasBytes := RandNodeAlias2(t)
54✔
1310
                aliasRecord := tlv.ZeroRecordT[tlv.TlvType3, NodeAlias2]()
54✔
1311
                aliasRecord.Val = aliasBytes
54✔
1312
                msg.Alias = tlv.SomeRecordT(aliasRecord)
54✔
1313
        }
54✔
1314

1315
        if rapid.Bool().Draw(t, "includeIPV4Addrs") {
151✔
1316
                ipv4Addrs := make(IPV4Addrs, 1)
51✔
1317
                ip := make(net.IP, 4)
51✔
1318
                ip[0] = uint8(rapid.IntRange(1, 223).Draw(t, "ip4_0"))
51✔
1319
                ip[1] = uint8(rapid.IntRange(0, 255).Draw(t, "ip4_1"))
51✔
1320
                ip[2] = uint8(rapid.IntRange(0, 255).Draw(t, "ip4_2"))
51✔
1321
                ip[3] = uint8(rapid.IntRange(1, 254).Draw(t, "ip4_3"))
51✔
1322

51✔
1323
                ipv4Addrs[0] = &net.TCPAddr{
51✔
1324
                        IP:   ip,
51✔
1325
                        Port: rapid.IntRange(1, 65535).Draw(t, "port4"),
51✔
1326
                }
51✔
1327

51✔
1328
                ipv4Record := tlv.ZeroRecordT[tlv.TlvType5, IPV4Addrs]()
51✔
1329
                ipv4Record.Val = ipv4Addrs
51✔
1330
                msg.IPV4Addrs = tlv.SomeRecordT(ipv4Record)
51✔
1331
        }
51✔
1332

1333
        if rapid.Bool().Draw(t, "includeIPV6Addrs") {
153✔
1334
                ipv6Addrs := make(IPV6Addrs, 1)
53✔
1335
                ip := make(net.IP, 16)
53✔
1336
                // Generate random IPv6 address.
53✔
1337
                for j := 0; j < 16; j++ {
901✔
1338
                        ip[j] = uint8(rapid.IntRange(0, 255).Draw(
848✔
1339
                                t, fmt.Sprintf("ip6_%d", j)),
848✔
1340
                        )
848✔
1341
                }
848✔
1342

1343
                ipv6Addrs[0] = &net.TCPAddr{
53✔
1344
                        IP:   ip,
53✔
1345
                        Port: rapid.IntRange(1, 65535).Draw(t, "port6"),
53✔
1346
                }
53✔
1347

53✔
1348
                ipv6Record := tlv.ZeroRecordT[tlv.TlvType7, IPV6Addrs]()
53✔
1349
                ipv6Record.Val = ipv6Addrs
53✔
1350
                msg.IPV6Addrs = tlv.SomeRecordT(ipv6Record)
53✔
1351
        }
1352

1353
        if rapid.Bool().Draw(t, "includeTorV3Addrs") {
157✔
1354
                torV3Addrs := make(TorV3Addrs, 1)
57✔
1355
                onionBytes := rapid.SliceOfN(rapid.Byte(), 35, 35).Draw(
57✔
1356
                        t, "onion",
57✔
1357
                )
57✔
1358
                onionService := tor.Base32Encoding.EncodeToString(onionBytes) +
57✔
1359
                        tor.OnionSuffix
57✔
1360

57✔
1361
                torV3Addrs[0] = &tor.OnionAddr{
57✔
1362
                        OnionService: onionService,
57✔
1363
                        Port: rapid.IntRange(1, 65535).Draw(
57✔
1364
                                t, "torPort",
57✔
1365
                        ),
57✔
1366
                }
57✔
1367

57✔
1368
                torV3Record := tlv.ZeroRecordT[tlv.TlvType9, TorV3Addrs]()
57✔
1369
                torV3Record.Val = torV3Addrs
57✔
1370
                msg.TorV3Addrs = tlv.SomeRecordT(torV3Record)
57✔
1371
        }
57✔
1372

1373
        if rapid.Bool().Draw(t, "includeDNSHostName") {
162✔
1374
                // Generate a valid DNS hostname.
62✔
1375
                hostname := genValidHostname(t)
62✔
1376
                port := rapid.Uint16Range(1, 65535).Draw(t, "dnsPort")
62✔
1377

62✔
1378
                dnsAddr := DNSAddress{
62✔
1379
                        Hostname: hostname,
62✔
1380
                        Port:     port,
62✔
1381
                }
62✔
1382

62✔
1383
                dnsRecord := tlv.ZeroRecordT[tlv.TlvType11, DNSAddress]()
62✔
1384
                dnsRecord.Val = dnsAddr
62✔
1385
                msg.DNSHostName = tlv.SomeRecordT(dnsRecord)
62✔
1386
        }
62✔
1387

1388
        randRecs, _ := RandSignedRangeRecords(t)
100✔
1389
        if len(randRecs) > 0 {
187✔
1390
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
87✔
1391
        }
87✔
1392

1393
        return msg
100✔
1394
}
1395

1396
// A compile time check to ensure OpenChannel implements the TestMessage
1397
// interface.
1398
var _ TestMessage = (*OpenChannel)(nil)
1399

1400
// RandTestMessage populates the message with random data suitable for testing.
1401
// It uses the rapid testing framework to generate random values.
1402
//
1403
// This is part of the TestMessage interface.
1404
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
100✔
1405
        chainHash := RandChainHash(t)
100✔
1406
        var hash chainhash.Hash
100✔
1407
        copy(hash[:], chainHash[:])
100✔
1408

100✔
1409
        var pendingChanID [32]byte
100✔
1410
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1411
                t, "pendingChanID",
100✔
1412
        )
100✔
1413
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1414

100✔
1415
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
1416
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
100✔
1417
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
1418

100✔
1419
        var channelFlags FundingFlag
100✔
1420
        if rapid.Bool().Draw(t, "announceChannel") {
143✔
1421
                channelFlags |= FFAnnounceChannel
43✔
1422
        }
43✔
1423

1424
        var localNonce OptMusig2NonceTLV
100✔
1425
        if includeLocalNonce {
156✔
1426
                nonce := RandMusig2Nonce(t)
56✔
1427
                localNonce = tlv.SomeRecordT(
56✔
1428
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
56✔
1429
                )
56✔
1430
        }
56✔
1431

1432
        var channelType *ChannelType
100✔
1433
        if includeChannelType {
143✔
1434
                channelType = RandChannelType(t)
43✔
1435
        }
43✔
1436

1437
        var leaseExpiry *LeaseExpiry
100✔
1438
        if includeLeaseExpiry {
150✔
1439
                leaseExpiry = RandLeaseExpiry(t)
50✔
1440
        }
50✔
1441

1442
        return &OpenChannel{
100✔
1443
                ChainHash:        hash,
100✔
1444
                PendingChannelID: pendingChanID,
100✔
1445
                FundingAmount: btcutil.Amount(
100✔
1446
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
100✔
1447
                ),
100✔
1448
                PushAmount: MilliSatoshi(
100✔
1449
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
100✔
1450
                ),
100✔
1451
                DustLimit: btcutil.Amount(
100✔
1452
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
100✔
1453
                ),
100✔
1454
                MaxValueInFlight: MilliSatoshi(
100✔
1455
                        rapid.IntRange(10000, 1000000).Draw(
100✔
1456
                                t, "maxValueInFlight",
100✔
1457
                        ),
100✔
1458
                ),
100✔
1459
                ChannelReserve: btcutil.Amount(
100✔
1460
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
100✔
1461
                ),
100✔
1462
                HtlcMinimum: MilliSatoshi(
100✔
1463
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
100✔
1464
                ),
100✔
1465
                FeePerKiloWeight: uint32(
100✔
1466
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
100✔
1467
                ),
100✔
1468
                CsvDelay: uint16(
100✔
1469
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
100✔
1470
                ),
100✔
1471
                MaxAcceptedHTLCs: uint16(
100✔
1472
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
100✔
1473
                ),
100✔
1474
                FundingKey:            RandPubKey(t),
100✔
1475
                RevocationPoint:       RandPubKey(t),
100✔
1476
                PaymentPoint:          RandPubKey(t),
100✔
1477
                DelayedPaymentPoint:   RandPubKey(t),
100✔
1478
                HtlcPoint:             RandPubKey(t),
100✔
1479
                FirstCommitmentPoint:  RandPubKey(t),
100✔
1480
                ChannelFlags:          channelFlags,
100✔
1481
                UpfrontShutdownScript: RandDeliveryAddress(t),
100✔
1482
                ChannelType:           channelType,
100✔
1483
                LeaseExpiry:           leaseExpiry,
100✔
1484
                LocalNonce:            localNonce,
100✔
1485
                ExtraData:             RandExtraOpaqueData(t, nil),
100✔
1486
        }
100✔
1487
}
1488

1489
// A compile time check to ensure Ping implements the lnwire.TestMessage
1490
// interface.
1491
var _ TestMessage = (*Ping)(nil)
1492

1493
// RandTestMessage populates the message with random data suitable for testing.
1494
// It uses the rapid testing framework to generate random values.
1495
//
1496
// This is part of the TestMessage interface.
1497
func (p *Ping) RandTestMessage(t *rapid.T) Message {
100✔
1498
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
100✔
1499
                t, "numPongBytes"),
100✔
1500
        )
100✔
1501

100✔
1502
        // Generate padding bytes (but keeping within allowed message size)
100✔
1503
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
100✔
1504
        maxPaddingLen := MaxMsgBody - 4
100✔
1505
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
100✔
1506
                t, "paddingLen",
100✔
1507
        )
100✔
1508
        padding := make(PingPayload, paddingLen)
100✔
1509

100✔
1510
        // Fill padding with random bytes
100✔
1511
        for i := 0; i < paddingLen; i++ {
833,642✔
1512
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
833,542✔
1513
                        t, fmt.Sprintf("paddingByte%d", i)),
833,542✔
1514
                )
833,542✔
1515
        }
833,542✔
1516

1517
        return &Ping{
100✔
1518
                NumPongBytes: numPongBytes,
100✔
1519
                PaddingBytes: padding,
100✔
1520
        }
100✔
1521
}
1522

1523
// A compile time check to ensure Pong implements the lnwire.TestMessage
1524
// interface.
1525
var _ TestMessage = (*Pong)(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.
1531
func (p *Pong) RandTestMessage(t *rapid.T) Message {
102✔
1532
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
102✔
1533
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
102✔
1534
                t, "pongPayload",
102✔
1535
        )
102✔
1536

102✔
1537
        return &Pong{
102✔
1538
                PongBytes: payload,
102✔
1539
        }
102✔
1540
}
102✔
1541

1542
// A compile time check to ensure QueryChannelRange implements the
1543
// lnwire.TestMessage interface.
1544
var _ TestMessage = (*QueryChannelRange)(nil)
1545

1546
// RandTestMessage populates the message with random data suitable for testing.
1547
// It uses the rapid testing framework to generate random values.
1548
//
1549
// This is part of the TestMessage interface.
1550
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
100✔
1551
        msg := &QueryChannelRange{
100✔
1552
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1553
                        t, "firstBlockHeight"),
100✔
1554
                ),
100✔
1555
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1556
                        t, "numBlocks"),
100✔
1557
                ),
100✔
1558
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1559
        }
100✔
1560

100✔
1561
        // Generate chain hash
100✔
1562
        chainHash := RandChainHash(t)
100✔
1563
        var chainHashObj chainhash.Hash
100✔
1564
        copy(chainHashObj[:], chainHash[:])
100✔
1565
        msg.ChainHash = chainHashObj
100✔
1566

100✔
1567
        // Randomly include QueryOptions
100✔
1568
        if rapid.Bool().Draw(t, "includeQueryOptions") {
155✔
1569
                queryOptions := &QueryOptions{}
55✔
1570
                *queryOptions = QueryOptions(*RandFeatureVector(t))
55✔
1571
                msg.QueryOptions = queryOptions
55✔
1572
        }
55✔
1573

1574
        return msg
100✔
1575
}
1576

1577
// A compile time check to ensure QueryShortChanIDs implements the
1578
// lnwire.TestMessage interface.
1579
var _ TestMessage = (*QueryShortChanIDs)(nil)
1580

1581
// RandTestMessage populates the message with random data suitable for testing.
1582
// It uses the rapid testing framework to generate random values.
1583
//
1584
// This is part of the TestMessage interface.
1585
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
100✔
1586
        var chainHash chainhash.Hash
100✔
1587
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1588
        copy(chainHash[:], hashBytes)
100✔
1589

100✔
1590
        encodingType := EncodingSortedPlain
100✔
1591
        if rapid.Bool().Draw(t, "useZlibEncoding") {
150✔
1592
                encodingType = EncodingSortedZlib
50✔
1593
        }
50✔
1594

1595
        msg := &QueryShortChanIDs{
100✔
1596
                ChainHash:    chainHash,
100✔
1597
                EncodingType: encodingType,
100✔
1598
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1599
                noSort:       false,
100✔
1600
        }
100✔
1601

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

100✔
1604
        // Generate sorted short channel IDs.
100✔
1605
        shortChanIDs := make([]ShortChannelID, numIDs)
100✔
1606
        for i := 0; i < numIDs; i++ {
960✔
1607
                shortChanIDs[i] = RandShortChannelID(t)
860✔
1608

860✔
1609
                // Ensure they're properly sorted.
860✔
1610
                if i > 0 && shortChanIDs[i].ToUint64() <=
860✔
1611
                        shortChanIDs[i-1].ToUint64() {
1,457✔
1612

597✔
1613
                        // Ensure this ID is larger than the previous one.
597✔
1614
                        shortChanIDs[i] = NewShortChanIDFromInt(
597✔
1615
                                shortChanIDs[i-1].ToUint64() + 1,
597✔
1616
                        )
597✔
1617
                }
597✔
1618
        }
1619

1620
        msg.ShortChanIDs = shortChanIDs
100✔
1621

100✔
1622
        return msg
100✔
1623
}
1624

1625
// A compile time check to ensure ReplyChannelRange implements the
1626
// lnwire.TestMessage interface.
1627
var _ TestMessage = (*ReplyChannelRange)(nil)
1628

1629
// RandTestMessage populates the message with random data suitable for testing.
1630
// It uses the rapid testing framework to generate random values.
1631
//
1632
// This is part of the TestMessage interface.
1633
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
100✔
1634
        msg := &ReplyChannelRange{
100✔
1635
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1636
                        t, "firstBlockHeight"),
100✔
1637
                ),
100✔
1638
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1639
                        t, "numBlocks"),
100✔
1640
                ),
100✔
1641
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
100✔
1642
                EncodingType: QueryEncoding(
100✔
1643
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
100✔
1644
                ),
100✔
1645
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1646
        }
100✔
1647

100✔
1648
        msg.ChainHash = RandChainHash(t)
100✔
1649

100✔
1650
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
100✔
1651
        if numShortChanIDs == 0 {
111✔
1652
                return msg
11✔
1653
        }
11✔
1654

1655
        scidSet := fn.NewSet[ShortChannelID]()
89✔
1656
        scids := make([]ShortChannelID, numShortChanIDs)
89✔
1657
        for i := 0; i < numShortChanIDs; i++ {
848✔
1658
                scid := RandShortChannelID(t)
759✔
1659
                for scidSet.Contains(scid) {
875✔
1660
                        scid = RandShortChannelID(t)
116✔
1661
                }
116✔
1662

1663
                scids[i] = scid
759✔
1664

759✔
1665
                scidSet.Add(scid)
759✔
1666
        }
1667

1668
        // Make sure there're no duplicates.
1669
        msg.ShortChanIDs = scids
89✔
1670

89✔
1671
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
127✔
1672
                msg.Timestamps = make(Timestamps, numShortChanIDs)
38✔
1673
                for i := 0; i < numShortChanIDs; i++ {
317✔
1674
                        msg.Timestamps[i] = ChanUpdateTimestamps{
279✔
1675
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
279✔
1676
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
279✔
1677
                        }
279✔
1678
                }
279✔
1679
        }
1680

1681
        return msg
89✔
1682
}
1683

1684
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1685
// lnwire.TestMessage interface.
1686
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1687

1688
// RandTestMessage populates the message with random data suitable for testing.
1689
// It uses the rapid testing framework to generate random values.
1690
//
1691
// This is part of the TestMessage interface.
1692
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
100✔
1693
        var chainHash chainhash.Hash
100✔
1694
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1695
        copy(chainHash[:], hashBytes)
100✔
1696

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

100✔
1699
        return &ReplyShortChanIDsEnd{
100✔
1700
                ChainHash: chainHash,
100✔
1701
                Complete:  complete,
100✔
1702
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1703
        }
100✔
1704
}
100✔
1705

1706
// RandTestMessage returns a RevokeAndAck message populated with random data.
1707
//
1708
// This is part of the TestMessage interface.
1709
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
100✔
1710
        msg := NewRevokeAndAck()
100✔
1711

100✔
1712
        var chanID ChannelID
100✔
1713
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
100✔
1714
        copy(chanID[:], bytes)
100✔
1715
        msg.ChanID = chanID
100✔
1716

100✔
1717
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
100✔
1718
        copy(msg.Revocation[:], revBytes)
100✔
1719

100✔
1720
        msg.NextRevocationKey = RandPubKey(t)
100✔
1721

100✔
1722
        if rapid.Bool().Draw(t, "includeLocalNonce") {
147✔
1723
                var nonce Musig2Nonce
47✔
1724
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
47✔
1725
                        t, "nonce",
47✔
1726
                )
47✔
1727
                copy(nonce[:], nonceBytes)
47✔
1728

47✔
1729
                msg.LocalNonce = tlv.SomeRecordT(
47✔
1730
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
47✔
1731
                )
47✔
1732
        }
47✔
1733

1734
        return msg
100✔
1735
}
1736

1737
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1738
// interface.
1739
var _ TestMessage = (*Shutdown)(nil)
1740

1741
// RandTestMessage populates the message with random data suitable for testing.
1742
// It uses the rapid testing framework to generate random values.
1743
//
1744
// This is part of the TestMessage interface.
1745
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
100✔
1746
        // Generate random delivery address
100✔
1747
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
100✔
1748
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
100✔
1749

100✔
1750
        // Generate random address length based on type
100✔
1751
        var addrLen int
100✔
1752
        switch addrType {
100✔
1753
        // P2PKH
1754
        case 0:
37✔
1755
                addrLen = 25
37✔
1756
        // P2SH
1757
        case 1:
25✔
1758
                addrLen = 23
25✔
1759
        // P2WPKH
1760
        case 2:
14✔
1761
                addrLen = 22
14✔
1762
        // P2WSH
1763
        case 3:
9✔
1764
                addrLen = 34
9✔
1765
        // P2TR
1766
        case 4:
15✔
1767
                addrLen = 34
15✔
1768
        }
1769

1770
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
100✔
1771
                t, "address",
100✔
1772
        )
100✔
1773

100✔
1774
        // Randomly decide whether to include a shutdown nonce
100✔
1775
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
100✔
1776
        var shutdownNonce ShutdownNonceTLV
100✔
1777

100✔
1778
        if includeNonce {
140✔
1779
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
40✔
1780
        }
40✔
1781

1782
        cr, _ := RandCustomRecords(t, nil)
100✔
1783

100✔
1784
        return &Shutdown{
100✔
1785
                ChannelID:     RandChannelID(t),
100✔
1786
                Address:       addr,
100✔
1787
                ShutdownNonce: shutdownNonce,
100✔
1788
                CustomRecords: cr,
100✔
1789
        }
100✔
1790
}
1791

1792
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1793
// interface.
1794
var _ TestMessage = (*Stfu)(nil)
1795

1796
// RandTestMessage populates the message with random data suitable for testing.
1797
// It uses the rapid testing framework to generate random values.
1798
//
1799
// This is part of the TestMessage interface.
1800
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
107✔
1801
        m := &Stfu{
107✔
1802
                ChanID:    RandChannelID(t),
107✔
1803
                Initiator: rapid.Bool().Draw(t, "initiator"),
107✔
1804
        }
107✔
1805

107✔
1806
        extraData := RandExtraOpaqueData(t, nil)
107✔
1807
        if len(extraData) > 0 {
193✔
1808
                m.ExtraData = extraData
86✔
1809
        }
86✔
1810

1811
        return m
107✔
1812
}
1813

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

1818
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1819
//
1820
// This is part of the TestMessage interface.
1821
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1822
        msg := &UpdateAddHTLC{
100✔
1823
                ChanID: RandChannelID(t),
100✔
1824
                ID:     rapid.Uint64().Draw(t, "id"),
100✔
1825
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
100✔
1826
                Expiry: rapid.Uint32().Draw(t, "expiry"),
100✔
1827
        }
100✔
1828

100✔
1829
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
100✔
1830
        copy(msg.PaymentHash[:], hashBytes)
100✔
1831

100✔
1832
        onionBytes := rapid.SliceOfN(
100✔
1833
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
100✔
1834
        ).Draw(t, "onionBlob")
100✔
1835
        copy(msg.OnionBlob[:], onionBytes)
100✔
1836

100✔
1837
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
100✔
1838
        if numRecords > 0 {
175✔
1839
                msg.CustomRecords, _ = RandCustomRecords(t, nil)
75✔
1840
        }
75✔
1841

1842
        // 50/50 chance to add a blinding point
1843
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
150✔
1844
                pubKey := RandPubKey(t)
50✔
1845

50✔
1846
                msg.BlindingPoint = tlv.SomeRecordT(
50✔
1847
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
50✔
1848
                )
50✔
1849
        }
50✔
1850

1851
        return msg
100✔
1852
}
1853

1854
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1855
// interface.
1856
var _ TestMessage = (*UpdateFailHTLC)(nil)
1857

1858
// RandTestMessage populates the message with random data suitable for testing.
1859
// It uses the rapid testing framework to generate random values.
1860
//
1861
// This is part of the TestMessage interface.
1862
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1863
        return &UpdateFailHTLC{
100✔
1864
                ChanID:    RandChannelID(t),
100✔
1865
                ID:        rapid.Uint64().Draw(t, "id"),
100✔
1866
                Reason:    RandOpaqueReason(t),
100✔
1867
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1868
        }
100✔
1869
}
100✔
1870

1871
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1872
// TestMessage interface.
1873
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1874

1875
// RandTestMessage populates the message with random data suitable for testing.
1876
// It uses the rapid testing framework to generate random values.
1877
//
1878
// This is part of the TestMessage interface.
1879
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1880
        return &UpdateFailMalformedHTLC{
100✔
1881
                ChanID:       RandChannelID(t),
100✔
1882
                ID:           rapid.Uint64().Draw(t, "id"),
100✔
1883
                ShaOnionBlob: RandSHA256Hash(t),
100✔
1884
                FailureCode:  RandFailCode(t),
100✔
1885
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1886
        }
100✔
1887
}
100✔
1888

1889
// A compile time check to ensure UpdateFee implements the TestMessage
1890
// interface.
1891
var _ TestMessage = (*UpdateFee)(nil)
1892

1893
// RandTestMessage populates the message with random data suitable for testing.
1894
// It uses the rapid testing framework to generate random values.
1895
//
1896
// This is part of the TestMessage interface.
1897
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
100✔
1898
        return &UpdateFee{
100✔
1899
                ChanID:    RandChannelID(t),
100✔
1900
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
100✔
1901
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1902
        }
100✔
1903
}
100✔
1904

1905
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1906
// interface.
1907
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1908

1909
// RandTestMessage populates the message with random data suitable for testing.
1910
// It uses the rapid testing framework to generate random values.
1911
//
1912
// This is part of the TestMessage interface.
1913
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1914
        msg := &UpdateFulfillHTLC{
100✔
1915
                ChanID:          RandChannelID(t),
100✔
1916
                ID:              rapid.Uint64().Draw(t, "id"),
100✔
1917
                PaymentPreimage: RandPaymentPreimage(t),
100✔
1918
        }
100✔
1919

100✔
1920
        cr, ignoreRecords := RandCustomRecords(t, nil)
100✔
1921
        msg.CustomRecords = cr
100✔
1922

100✔
1923
        randData := RandExtraOpaqueData(t, ignoreRecords)
100✔
1924
        if len(randData) > 0 {
175✔
1925
                msg.ExtraData = randData
75✔
1926
        }
75✔
1927

1928
        return msg
100✔
1929
}
1930

1931
// A compile time check to ensure Warning implements the lnwire.TestMessage
1932
// interface.
1933
var _ TestMessage = (*Warning)(nil)
1934

1935
// RandTestMessage populates the message with random data suitable for testing.
1936
// It uses the rapid testing framework to generate random values.
1937
//
1938
// This is part of the TestMessage interface.
1939
func (c *Warning) RandTestMessage(t *rapid.T) Message {
109✔
1940
        msg := &Warning{
109✔
1941
                ChanID: RandChannelID(t),
109✔
1942
        }
109✔
1943

109✔
1944
        useASCII := rapid.Bool().Draw(t, "useASCII")
109✔
1945
        if useASCII {
154✔
1946
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
45✔
1947
                data := make([]byte, length)
45✔
1948
                for i := 0; i < length; i++ {
1,272✔
1949
                        data[i] = byte(
1,227✔
1950
                                rapid.IntRange(32, 126).Draw(
1,227✔
1951
                                        t, fmt.Sprintf("warningDataByte-%d", i),
1,227✔
1952
                                ),
1,227✔
1953
                        )
1,227✔
1954
                }
1,227✔
1955
                msg.Data = data
45✔
1956
        } else {
64✔
1957
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
64✔
1958
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
64✔
1959
                        t, "warningData",
64✔
1960
                )
64✔
1961
        }
64✔
1962

1963
        return msg
109✔
1964
}
1965

1966
// A compile time check to ensure Error implements the lnwire.TestMessage
1967
// interface.
1968
var _ TestMessage = (*Error)(nil)
1969

1970
// RandTestMessage populates the message with random data suitable for testing.
1971
// It uses the rapid testing framework to generate random values.
1972
//
1973
// This is part of the TestMessage interface.
1974
func (c *Error) RandTestMessage(t *rapid.T) Message {
100✔
1975
        msg := &Error{
100✔
1976
                ChanID: RandChannelID(t),
100✔
1977
        }
100✔
1978

100✔
1979
        useASCII := rapid.Bool().Draw(t, "useASCII")
100✔
1980
        if useASCII {
150✔
1981
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
50✔
1982
                data := make([]byte, length)
50✔
1983
                for i := 0; i < length; i++ {
1,778✔
1984
                        data[i] = byte(
1,728✔
1985
                                rapid.IntRange(32, 126).Draw(
1,728✔
1986
                                        t, fmt.Sprintf("errorDataByte-%d", i),
1,728✔
1987
                                ),
1,728✔
1988
                        )
1,728✔
1989
                }
1,728✔
1990
                msg.Data = data
50✔
1991
        } else {
50✔
1992
                // Generate random binary data
50✔
1993
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
50✔
1994
                msg.Data = rapid.SliceOfN(
50✔
1995
                        rapid.Byte(), length, length,
50✔
1996
                ).Draw(t, "errorData")
50✔
1997
        }
50✔
1998

1999
        return msg
100✔
2000
}
2001

2002
// genValidHostname generates a random valid hostname according to BOLT #7
2003
// rules.
2004
func genValidHostname(t *rapid.T) string {
162✔
2005
        // Valid characters: a-z, A-Z, 0-9, -, .
162✔
2006
        validChars := "abcdefghijklmnopqrstuvwxyzABCDE" +
162✔
2007
                "FGHIJKLMNOPQRSTUVWXYZ0123456789-."
162✔
2008

162✔
2009
        // Generate hostname length between 1 and 255 characters.
162✔
2010
        length := rapid.IntRange(1, 255).Draw(t, "hostname_length")
162✔
2011

162✔
2012
        hostname := make([]byte, length)
162✔
2013
        for i := 0; i < length; i++ {
13,132✔
2014
                charIndex := rapid.IntRange(0, len(validChars)-1).Draw(
12,970✔
2015
                        t, fmt.Sprintf("char_%d", i),
12,970✔
2016
                )
12,970✔
2017
                hostname[i] = validChars[charIndex]
12,970✔
2018
        }
12,970✔
2019

2020
        return string(hostname)
162✔
2021
}
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