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

lightningnetwork / lnd / 14047728447

24 Mar 2025 11:05PM UTC coverage: 58.586% (-10.4%) from 68.992%
14047728447

Pull #9637

github

web-flow
Merge 12ecea36e into 67d2eac43
Pull Request #9637: feature: start to set the require bit for channel_type

96777 of 165188 relevant lines covered (58.59%)

1.82 hits per line

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

0.0
/lnwire/test_message.go
1
package lnwire
2

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
238
        msg.Signature.ForceSchnorr()
×
239

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

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

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

272
        return msg
×
273
}
274

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

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

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

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

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

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

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

323
        return msg
×
324
}
325

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

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

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

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

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

362
        return msg
×
363
}
364

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
507
        msg.Signature.ForceSchnorr()
×
508

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

515
        return msg
×
516
}
517

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

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

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

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

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

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

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

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

581
        return msg
×
582
}
583

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

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

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

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

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

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

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

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

641
        return msg
×
642
}
643

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

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

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

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

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

679
        return msg
×
680
}
681

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

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

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

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

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

714
        return sig
×
715
}
716

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

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

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

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

742
        return msg
×
743
}
744

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

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

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

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

765
        return msg
×
766
}
767

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

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

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

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

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

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

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

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

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

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

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

838
        return msg
×
839
}
840

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

938
        return msg
×
939
}
940

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

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

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

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

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

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

980
        return msg
×
981
}
982

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1243
        return msg
×
1244
}
1245

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

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

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

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

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

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

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

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

1289
        msg.ShortChanIDs = shortChanIDs
×
1290

×
1291
        return msg
×
1292
}
1293

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

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

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

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

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

1332
                scids[i] = scid
×
1333

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

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

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

1350
        return msg
×
1351
}
1352

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

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

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

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

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

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

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

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

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

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

1403
        return msg
×
1404
}
1405

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

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

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

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

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

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

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

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

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

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

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

1480
        return m
×
1481
}
1482

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

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

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

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

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

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

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

1520
        return msg
×
1521
}
1522

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

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

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

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

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

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

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

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

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

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

1597
        return msg
×
1598
}
1599

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

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

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

1632
        return msg
×
1633
}
1634

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

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

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

1668
        return msg
×
1669
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc