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

lightningnetwork / lnd / 17011395530

16 Aug 2025 06:08PM UTC coverage: 57.298% (-9.5%) from 66.765%
17011395530

Pull #10167

github

web-flow
Merge 3c250722d into fb1adfc21
Pull Request #10167: multi: bump Go to 1.24.6

99112 of 172975 relevant lines covered (57.3%)

1.78 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/tlv"
14
        "github.com/stretchr/testify/require"
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
        // Randomly decide if an inbound fee should be included.
410
        // By default, our extra opaque data will just be random TLV but if we
411
        // include an inbound fee, then we will also set the record in the
412
        // extra opaque data.
413
        var (
×
414
                customRecords, _ = RandCustomRecords(t, nil, false)
×
415
                inboundFee       tlv.OptionalRecordT[tlv.TlvType55555, Fee]
×
416
        )
×
417
        includeInboundFee := rapid.Bool().Draw(t, "includeInboundFee")
×
418
        if includeInboundFee {
×
419
                if customRecords == nil {
×
420
                        customRecords = make(CustomRecords)
×
421
                }
×
422

423
                inFeeBase := int32(
×
424
                        rapid.IntRange(-1000, 1000).Draw(t, "inFeeBase"),
×
425
                )
×
426
                inFeeProp := int32(
×
427
                        rapid.IntRange(-1000, 1000).Draw(t, "inFeeProp"),
×
428
                )
×
429
                fee := Fee{
×
430
                        BaseFee: inFeeBase,
×
431
                        FeeRate: inFeeProp,
×
432
                }
×
433
                inboundFee = tlv.SomeRecordT(
×
434
                        tlv.NewRecordT[tlv.TlvType55555, Fee](fee),
×
435
                )
×
436

×
437
                var b bytes.Buffer
×
438
                feeRecord := fee.Record()
×
439
                err := feeRecord.Encode(&b)
×
440
                require.NoError(t, err)
×
441

×
442
                customRecords[uint64(FeeRecordType)] = b.Bytes()
×
443
        }
444

445
        extraBytes, err := customRecords.Serialize()
×
446
        require.NoError(t, err)
×
447

×
448
        return &ChannelUpdate1{
×
449
                Signature:      RandSignature(t),
×
450
                ChainHash:      hash,
×
451
                ShortChannelID: RandShortChannelID(t),
×
452
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
453
                        t, "timestamp"),
×
454
                ),
×
455
                MessageFlags: msgFlags,
×
456
                ChannelFlags: chanFlags,
×
457
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
×
458
                        t, "timelockDelta"),
×
459
                ),
×
460
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
×
461
                        t, "htlcMinimum"),
×
462
                ),
×
463
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
464
                        t, "baseFee"),
×
465
                ),
×
466
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
467
                        t, "feeRate"),
×
468
                ),
×
469
                HtlcMaximumMsat: maxHtlc,
×
470
                InboundFee:      inboundFee,
×
471
                ExtraOpaqueData: extraBytes,
×
472
        }
×
473
}
474

475
// A compile time check to ensure ChannelUpdate2 implements the
476
// lnwire.TestMessage interface.
477
var _ TestMessage = (*ChannelUpdate2)(nil)
478

479
// RandTestMessage populates the message with random data suitable for testing.
480
// It uses the rapid testing framework to generate random values.
481
//
482
// This is part of the TestMessage interface.
483
func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
×
484
        shortChanID := RandShortChannelID(t)
×
485
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
×
486

×
487
        var disabledFlags ChanUpdateDisableFlags
×
488
        if rapid.Bool().Draw(t, "disableIncoming") {
×
489
                disabledFlags |= ChanUpdateDisableIncoming
×
490
        }
×
491
        if rapid.Bool().Draw(t, "disableOutgoing") {
×
492
                disabledFlags |= ChanUpdateDisableOutgoing
×
493
        }
×
494

495
        cltvExpiryDelta := uint16(rapid.IntRange(10, 200).Draw(
×
496
                t, "cltvExpiryDelta"),
×
497
        )
×
498

×
499
        htlcMinMsat := MilliSatoshi(rapid.IntRange(1, 10000).Draw(
×
500
                t, "htlcMinMsat"),
×
501
        )
×
502
        htlcMaxMsat := MilliSatoshi(rapid.IntRange(10000, 100000000).Draw(
×
503
                t, "htlcMaxMsat"),
×
504
        )
×
505
        feeBaseMsat := uint32(rapid.IntRange(0, 10000).Draw(t, "feeBaseMsat"))
×
506
        feeProportionalMillionths := uint32(rapid.IntRange(0, 10000).Draw(
×
507
                t, "feeProportionalMillionths"),
×
508
        )
×
509

×
510
        chainHash := RandChainHash(t)
×
511
        var chainHashObj chainhash.Hash
×
512
        copy(chainHashObj[:], chainHash[:])
×
513

×
514
        //nolint:ll
×
515
        msg := &ChannelUpdate2{
×
516
                Signature: RandSignature(t),
×
517
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
×
518
                        chainHashObj,
×
519
                ),
×
520
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2, ShortChannelID](
×
521
                        shortChanID,
×
522
                ),
×
523
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType4, uint32](
×
524
                        blockHeight,
×
525
                ),
×
526
                DisabledFlags: tlv.NewPrimitiveRecord[tlv.TlvType6, ChanUpdateDisableFlags]( //nolint:ll
×
527
                        disabledFlags,
×
528
                ),
×
529
                CLTVExpiryDelta: tlv.NewPrimitiveRecord[tlv.TlvType10, uint16](
×
530
                        cltvExpiryDelta,
×
531
                ),
×
532
                HTLCMinimumMsat: tlv.NewPrimitiveRecord[tlv.TlvType12, MilliSatoshi](
×
533
                        htlcMinMsat,
×
534
                ),
×
535
                HTLCMaximumMsat: tlv.NewPrimitiveRecord[tlv.TlvType14, MilliSatoshi](
×
536
                        htlcMaxMsat,
×
537
                ),
×
538
                FeeBaseMsat: tlv.NewPrimitiveRecord[tlv.TlvType16, uint32](
×
539
                        feeBaseMsat,
×
540
                ),
×
541
                FeeProportionalMillionths: tlv.NewPrimitiveRecord[tlv.TlvType18, uint32](
×
542
                        feeProportionalMillionths,
×
543
                ),
×
544
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
545
        }
×
546

×
547
        msg.Signature.ForceSchnorr()
×
548

×
549
        if rapid.Bool().Draw(t, "isSecondPeer") {
×
550
                msg.SecondPeer = tlv.SomeRecordT(
×
551
                        tlv.RecordT[tlv.TlvType8, TrueBoolean]{},
×
552
                )
×
553
        }
×
554

555
        return msg
×
556
}
557

558
// A compile time check to ensure ClosingComplete implements the
559
// lnwire.TestMessage interface.
560
var _ TestMessage = (*ClosingComplete)(nil)
561

562
// RandTestMessage populates the message with random data suitable for testing.
563
// It uses the rapid testing framework to generate random values.
564
//
565
// This is part of the TestMessage interface.
566
func (c *ClosingComplete) RandTestMessage(t *rapid.T) Message {
×
567
        msg := &ClosingComplete{
×
568
                ChannelID: RandChannelID(t),
×
569
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
×
570
                        t, "feeSatoshis"),
×
571
                ),
×
572
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
×
573
                        t, "lockTime",
×
574
                ),
×
575
                CloseeScript: RandDeliveryAddress(t),
×
576
                CloserScript: RandDeliveryAddress(t),
×
577
                ExtraData:    RandExtraOpaqueData(t, nil),
×
578
        }
×
579

×
580
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
×
581
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
×
582
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
×
583

×
584
        // Ensure at least one signature is present.
×
585
        if !includeCloserNoClosee && !includeNoCloserClosee &&
×
586
                !includeCloserAndClosee {
×
587

×
588
                // If all are false, enable at least one randomly.
×
589
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
×
590
                switch choice {
×
591
                case 0:
×
592
                        includeCloserNoClosee = true
×
593
                case 1:
×
594
                        includeNoCloserClosee = true
×
595
                case 2:
×
596
                        includeCloserAndClosee = true
×
597
                }
598
        }
599

600
        if includeCloserNoClosee {
×
601
                sig := RandSignature(t)
×
602
                msg.CloserNoClosee = tlv.SomeRecordT(
×
603
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
×
604
                )
×
605
        }
×
606

607
        if includeNoCloserClosee {
×
608
                sig := RandSignature(t)
×
609
                msg.NoCloserClosee = tlv.SomeRecordT(
×
610
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
×
611
                )
×
612
        }
×
613

614
        if includeCloserAndClosee {
×
615
                sig := RandSignature(t)
×
616
                msg.CloserAndClosee = tlv.SomeRecordT(
×
617
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
×
618
                )
×
619
        }
×
620

621
        return msg
×
622
}
623

624
// A compile time check to ensure ClosingSig implements the lnwire.TestMessage
625
// interface.
626
var _ TestMessage = (*ClosingSig)(nil)
627

628
// RandTestMessage populates the message with random data suitable for testing.
629
// It uses the rapid testing framework to generate random values.
630
//
631
// This is part of the TestMessage interface.
632
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
×
633
        msg := &ClosingSig{
×
634
                ChannelID:    RandChannelID(t),
×
635
                CloseeScript: RandDeliveryAddress(t),
×
636
                CloserScript: RandDeliveryAddress(t),
×
637
                ExtraData:    RandExtraOpaqueData(t, nil),
×
638
        }
×
639

×
640
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
×
641
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
×
642
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
×
643

×
644
        // Ensure at least one signature is present.
×
645
        if !includeCloserNoClosee && !includeNoCloserClosee &&
×
646
                !includeCloserAndClosee {
×
647

×
648
                // If all are false, enable at least one randomly.
×
649
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
×
650
                switch choice {
×
651
                case 0:
×
652
                        includeCloserNoClosee = true
×
653
                case 1:
×
654
                        includeNoCloserClosee = true
×
655
                case 2:
×
656
                        includeCloserAndClosee = true
×
657
                }
658
        }
659

660
        if includeCloserNoClosee {
×
661
                sig := RandSignature(t)
×
662
                msg.CloserNoClosee = tlv.SomeRecordT(
×
663
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
×
664
                )
×
665
        }
×
666

667
        if includeNoCloserClosee {
×
668
                sig := RandSignature(t)
×
669
                msg.NoCloserClosee = tlv.SomeRecordT(
×
670
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
×
671
                )
×
672
        }
×
673

674
        if includeCloserAndClosee {
×
675
                sig := RandSignature(t)
×
676
                msg.CloserAndClosee = tlv.SomeRecordT(
×
677
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
×
678
                )
×
679
        }
×
680

681
        return msg
×
682
}
683

684
// A compile time check to ensure ClosingSigned implements the
685
// lnwire.TestMessage interface.
686
var _ TestMessage = (*ClosingSigned)(nil)
687

688
// RandTestMessage populates the message with random data suitable for testing.
689
// It uses the rapid testing framework to generate random values.
690
//
691
// This is part of the TestMessage interface.
692
func (c *ClosingSigned) RandTestMessage(t *rapid.T) Message {
×
693
        // Generate a random boolean to decide whether to include CommitSig or
×
694
        // PartialSig Since they're mutually exclusive, when one is populated,
×
695
        // the other must be blank.
×
696
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
697

×
698
        msg := &ClosingSigned{
×
699
                ChannelID: RandChannelID(t),
×
700
                FeeSatoshis: btcutil.Amount(
×
701
                        rapid.Int64Range(0, 1000000).Draw(t, "feeSatoshis"),
×
702
                ),
×
703
                ExtraData: RandExtraOpaqueData(t, nil),
×
704
        }
×
705

×
706
        if usePartialSig {
×
707
                sigBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
708
                        t, "sigScalar",
×
709
                )
×
710
                var s btcec.ModNScalar
×
711
                _ = s.SetByteSlice(sigBytes)
×
712

×
713
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
×
714
                msg.Signature = Sig{}
×
715
        } else {
×
716
                msg.Signature = RandSignature(t)
×
717
        }
×
718

719
        return msg
×
720
}
721

722
// A compile time check to ensure CommitSig implements the lnwire.TestMessage
723
// interface.
724
var _ TestMessage = (*CommitSig)(nil)
725

726
// RandTestMessage populates the message with random data suitable for testing.
727
// It uses the rapid testing framework to generate random values.
728
//
729
// This is part of the TestMessage interface.
730
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
×
731
        cr, _ := RandCustomRecords(t, nil, true)
×
732
        sig := &CommitSig{
×
733
                ChanID:        RandChannelID(t),
×
734
                CommitSig:     RandSignature(t),
×
735
                CustomRecords: cr,
×
736
        }
×
737

×
738
        numHtlcSigs := rapid.IntRange(0, 20).Draw(t, "numHtlcSigs")
×
739
        htlcSigs := make([]Sig, numHtlcSigs)
×
740
        for i := 0; i < numHtlcSigs; i++ {
×
741
                htlcSigs[i] = RandSignature(t)
×
742
        }
×
743

744
        if len(htlcSigs) > 0 {
×
745
                sig.HtlcSigs = htlcSigs
×
746
        }
×
747

748
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
749
        if includePartialSig {
×
750
                sigWithNonce := RandPartialSigWithNonce(t)
×
751
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
752
        }
×
753

754
        return sig
×
755
}
756

757
// A compile time check to ensure Custom implements the lnwire.TestMessage
758
// interface.
759
var _ TestMessage = (*Custom)(nil)
760

761
// RandTestMessage populates the message with random data suitable for testing.
762
// It uses the rapid testing framework to generate random values.
763
//
764
// This is part of the TestMessage interface.
765
func (c *Custom) RandTestMessage(t *rapid.T) Message {
×
766
        msgType := MessageType(
×
767
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
×
768
                        t, "customMsgType",
×
769
                ),
×
770
        )
×
771

×
772
        dataLen := rapid.IntRange(0, 1000).Draw(t, "customDataLength")
×
773
        data := rapid.SliceOfN(rapid.Byte(), dataLen, dataLen).Draw(
×
774
                t, "customData",
×
775
        )
×
776

×
777
        msg, err := NewCustom(msgType, data)
×
778
        if err != nil {
×
779
                panic(fmt.Sprintf("Error creating custom message: %v", err))
×
780
        }
781

782
        return msg
×
783
}
784

785
// A compile time check to ensure DynAck implements the lnwire.TestMessage
786
// interface.
787
var _ TestMessage = (*DynAck)(nil)
788

789
// RandTestMessage populates the message with random data suitable for testing.
790
// It uses the rapid testing framework to generate random values.
791
//
792
// This is part of the TestMessage interface.
793
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
×
794
        msg := &DynAck{
×
795
                ChanID: RandChannelID(t),
×
796
        }
×
797

×
798
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
799
        if includeLocalNonce {
×
800
                nonce := RandMusig2Nonce(t)
×
801
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
×
802
                msg.LocalNonce = tlv.SomeRecordT(rec)
×
803
        }
×
804

805
        // Create a tlv type lists to hold all known records which will be
806
        // ignored when creating ExtraData records.
807
        ignoreRecords := fn.NewSet[uint64]()
×
808
        for i := range uint64(15) {
×
809
                // Ignore known records.
×
810
                if i%2 == 0 {
×
811
                        ignoreRecords.Add(i)
×
812
                }
×
813
        }
814

815
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
×
816

×
817
        return msg
×
818
}
819

820
// A compile time check to ensure DynPropose implements the lnwire.TestMessage
821
// interface.
822
var _ TestMessage = (*DynPropose)(nil)
823

824
// RandTestMessage populates the message with random data suitable for testing.
825
// It uses the rapid testing framework to generate random values.
826
//
827
// This is part of the TestMessage interface.
828
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
×
829
        msg := &DynPropose{
×
830
                ChanID: RandChannelID(t),
×
831
        }
×
832

×
833
        // Randomly decide which optional fields to include
×
834
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
835
        includeMaxValueInFlight := rapid.Bool().Draw(
×
836
                t, "includeMaxValueInFlight",
×
837
        )
×
838
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
839
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
840
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
841
                t, "includeMaxAcceptedHTLCs",
×
842
        )
×
843
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
844

×
845
        // Generate random values for each included field
×
846
        if includeDustLimit {
×
847
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
×
848
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
849
                rec.Val = tlv.NewBigSizeT(val)
×
850
                msg.DustLimit = tlv.SomeRecordT(rec)
×
851
        }
×
852

853
        if includeMaxValueInFlight {
×
854
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
×
855
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
856
                rec.Val = val
×
857
                msg.MaxValueInFlight = tlv.SomeRecordT(rec)
×
858
        }
×
859

860
        if includeChannelReserve {
×
861
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
×
862
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
863
                rec.Val = tlv.NewBigSizeT(val)
×
864
                msg.ChannelReserve = tlv.SomeRecordT(rec)
×
865
        }
×
866

867
        if includeCsvDelay {
×
868
                csvDelay := msg.CsvDelay.Zero()
×
869
                val := rapid.Uint16().Draw(t, "csvDelay")
×
870
                csvDelay.Val = val
×
871
                msg.CsvDelay = tlv.SomeRecordT(csvDelay)
×
872
        }
×
873

874
        if includeMaxAcceptedHTLCs {
×
875
                maxHtlcs := msg.MaxAcceptedHTLCs.Zero()
×
876
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
877
                msg.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
878
        }
×
879

880
        if includeChannelType {
×
881
                chanType := msg.ChannelType.Zero()
×
882
                chanType.Val = *RandChannelType(t)
×
883
                msg.ChannelType = tlv.SomeRecordT(chanType)
×
884
        }
×
885

886
        // Create a tlv type lists to hold all known records which will be
887
        // ignored when creating ExtraData records.
888
        ignoreRecords := fn.NewSet[uint64]()
×
889
        for i := range uint64(13) {
×
890
                // Ignore known records.
×
891
                if i%2 == 0 {
×
892
                        ignoreRecords.Add(i)
×
893
                }
×
894
        }
895

896
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
×
897

×
898
        return msg
×
899
}
900

901
// A compile time check to ensure DynReject implements the lnwire.TestMessage
902
// interface.
903
var _ TestMessage = (*DynReject)(nil)
904

905
// RandTestMessage populates the message with random data suitable for testing.
906
// It uses the rapid testing framework to generate random values.
907
//
908
// This is part of the TestMessage interface.
909
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
×
910
        featureVec := NewRawFeatureVector()
×
911

×
912
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
×
913
        for i := 0; i < numFeatures; i++ {
×
914
                bit := FeatureBit(
×
915
                        rapid.IntRange(0, 31).Draw(
×
916
                                t, fmt.Sprintf("rejectionBit-%d", i),
×
917
                        ),
×
918
                )
×
919
                featureVec.Set(bit)
×
920
        }
×
921

922
        var extraData ExtraOpaqueData
×
923
        randData := RandExtraOpaqueData(t, nil)
×
924
        if len(randData) > 0 {
×
925
                extraData = randData
×
926
        }
×
927

928
        return &DynReject{
×
929
                ChanID:           RandChannelID(t),
×
930
                UpdateRejections: *featureVec,
×
931
                ExtraData:        extraData,
×
932
        }
×
933
}
934

935
// A compile time check to ensure DynCommit implements the lnwire.TestMessage
936
// interface.
937
var _ TestMessage = (*DynCommit)(nil)
938

939
// RandTestMessage populates the message with random data suitable for testing.
940
// It uses the rapid testing framework to generate random values.
941
//
942
// This is part of the TestMessage interface.
943
func (dc *DynCommit) RandTestMessage(t *rapid.T) Message {
×
944
        chanID := RandChannelID(t)
×
945

×
946
        da := &DynAck{
×
947
                ChanID: chanID,
×
948
        }
×
949

×
950
        dp := &DynPropose{
×
951
                ChanID: chanID,
×
952
        }
×
953

×
954
        // Randomly decide which optional fields to include
×
955
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
956
        includeMaxValueInFlight := rapid.Bool().Draw(
×
957
                t, "includeMaxValueInFlight",
×
958
        )
×
959
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
960
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
961
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
962
                t, "includeMaxAcceptedHTLCs",
×
963
        )
×
964
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
965

×
966
        // Generate random values for each included field
×
967
        if includeDustLimit {
×
968
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
×
969
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
970
                rec.Val = tlv.NewBigSizeT(val)
×
971
                dp.DustLimit = tlv.SomeRecordT(rec)
×
972
        }
×
973

974
        if includeMaxValueInFlight {
×
975
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
×
976
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
977
                rec.Val = val
×
978
                dp.MaxValueInFlight = tlv.SomeRecordT(rec)
×
979
        }
×
980

981
        if includeChannelReserve {
×
982
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
×
983
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
984
                rec.Val = tlv.NewBigSizeT(val)
×
985
                dp.ChannelReserve = tlv.SomeRecordT(rec)
×
986
        }
×
987

988
        if includeCsvDelay {
×
989
                csvDelay := dp.CsvDelay.Zero()
×
990
                val := rapid.Uint16().Draw(t, "csvDelay")
×
991
                csvDelay.Val = val
×
992
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
×
993
        }
×
994

995
        if includeMaxAcceptedHTLCs {
×
996
                maxHtlcs := dp.MaxAcceptedHTLCs.Zero()
×
997
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
998
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
999
        }
×
1000

1001
        if includeChannelType {
×
1002
                chanType := dp.ChannelType.Zero()
×
1003
                chanType.Val = *RandChannelType(t)
×
1004
                dp.ChannelType = tlv.SomeRecordT(chanType)
×
1005
        }
×
1006

1007
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
1008
        if includeLocalNonce {
×
1009
                nonce := RandMusig2Nonce(t)
×
1010
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
×
1011
                da.LocalNonce = tlv.SomeRecordT(rec)
×
1012
        }
×
1013

1014
        // Create a tlv type lists to hold all known records which will be
1015
        // ignored when creating ExtraData records.
1016
        ignoreRecords := fn.NewSet[uint64]()
×
1017
        for i := range uint64(15) {
×
1018
                // Ignore known records.
×
1019
                if i%2 == 0 {
×
1020
                        ignoreRecords.Add(i)
×
1021
                }
×
1022
        }
1023
        msg := &DynCommit{
×
1024
                DynPropose: *dp,
×
1025
                DynAck:     *da,
×
1026
        }
×
1027

×
1028
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
×
1029

×
1030
        return msg
×
1031
}
1032

1033
// A compile time check to ensure FundingCreated implements the TestMessage
1034
// interface.
1035
var _ TestMessage = (*FundingCreated)(nil)
1036

1037
// RandTestMessage populates the message with random data suitable for testing.
1038
// It uses the rapid testing framework to generate random values.
1039
//
1040
// This is part of the TestMessage interface.
1041
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
×
1042
        var pendingChanID [32]byte
×
1043
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1044
                t, "pendingChanID",
×
1045
        )
×
1046
        copy(pendingChanID[:], pendingChanIDBytes)
×
1047

×
1048
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
1049
        var partialSig OptPartialSigWithNonceTLV
×
1050
        var commitSig Sig
×
1051

×
1052
        if includePartialSig {
×
1053
                sigWithNonce := RandPartialSigWithNonce(t)
×
1054
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
1055

×
1056
                // When using partial sig, CommitSig should be empty/blank.
×
1057
                commitSig = Sig{}
×
1058
        } else {
×
1059
                commitSig = RandSignature(t)
×
1060
        }
×
1061

1062
        return &FundingCreated{
×
1063
                PendingChannelID: pendingChanID,
×
1064
                FundingPoint:     RandOutPoint(t),
×
1065
                CommitSig:        commitSig,
×
1066
                PartialSig:       partialSig,
×
1067
                ExtraData:        RandExtraOpaqueData(t, nil),
×
1068
        }
×
1069
}
1070

1071
// A compile time check to ensure FundingSigned implements the
1072
// lnwire.TestMessage interface.
1073
var _ TestMessage = (*FundingSigned)(nil)
1074

1075
// RandTestMessage populates the message with random data suitable for testing.
1076
// It uses the rapid testing framework to generate random values.
1077
//
1078
// This is part of the TestMessage interface.
1079
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
×
1080
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
1081

×
1082
        msg := &FundingSigned{
×
1083
                ChanID:    RandChannelID(t),
×
1084
                ExtraData: RandExtraOpaqueData(t, nil),
×
1085
        }
×
1086

×
1087
        if usePartialSig {
×
1088
                sigWithNonce := RandPartialSigWithNonce(t)
×
1089
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
1090

×
1091
                msg.CommitSig = Sig{}
×
1092
        } else {
×
1093
                msg.CommitSig = RandSignature(t)
×
1094
        }
×
1095

1096
        return msg
×
1097
}
1098

1099
// A compile time check to ensure GossipTimestampRange implements the
1100
// lnwire.TestMessage interface.
1101
var _ TestMessage = (*GossipTimestampRange)(nil)
1102

1103
// RandTestMessage populates the message with random data suitable for testing.
1104
// It uses the rapid testing framework to generate random values.
1105
//
1106
// This is part of the TestMessage interface.
1107
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
×
1108
        var chainHash chainhash.Hash
×
1109
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
1110
        copy(chainHash[:], hashBytes)
×
1111

×
1112
        msg := &GossipTimestampRange{
×
1113
                ChainHash:      chainHash,
×
1114
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
×
1115
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
×
1116
                ExtraData:      RandExtraOpaqueData(t, nil),
×
1117
        }
×
1118

×
1119
        includeFirstBlockHeight := rapid.Bool().Draw(
×
1120
                t, "includeFirstBlockHeight",
×
1121
        )
×
1122
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
×
1123

×
1124
        if includeFirstBlockHeight {
×
1125
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
×
1126
                msg.FirstBlockHeight = tlv.SomeRecordT(
×
1127
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
×
1128
                )
×
1129
        }
×
1130

1131
        if includeBlockRange {
×
1132
                blockRange := rapid.Uint32().Draw(t, "blockRange")
×
1133
                msg.BlockRange = tlv.SomeRecordT(
×
1134
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
×
1135
                )
×
1136
        }
×
1137

1138
        return msg
×
1139
}
1140

1141
// RandTestMessage populates the message with random data suitable for testing.
1142
// It uses the rapid testing framework to generate random values.
1143
//
1144
// This is part of the TestMessage interface.
1145
func (msg *Init) RandTestMessage(t *rapid.T) Message {
×
1146
        global := NewRawFeatureVector()
×
1147
        local := NewRawFeatureVector()
×
1148

×
1149
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
×
1150
        for i := 0; i < numGlobalFeatures; i++ {
×
1151
                bit := FeatureBit(
×
1152
                        rapid.IntRange(0, 100).Draw(
×
1153
                                t, fmt.Sprintf("globalFeatureBit%d", i),
×
1154
                        ),
×
1155
                )
×
1156
                global.Set(bit)
×
1157
        }
×
1158

1159
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
×
1160
        for i := 0; i < numLocalFeatures; i++ {
×
1161
                bit := FeatureBit(
×
1162
                        rapid.IntRange(0, 100).Draw(
×
1163
                                t, fmt.Sprintf("localFeatureBit%d", i),
×
1164
                        ),
×
1165
                )
×
1166
                local.Set(bit)
×
1167
        }
×
1168

1169
        return NewInitMessage(global, local)
×
1170
}
1171

1172
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1173
// interface.
1174
var _ TestMessage = (*KickoffSig)(nil)
1175

1176
// RandTestMessage populates the message with random data suitable for testing.
1177
// It uses the rapid testing framework to generate random values.
1178
//
1179
// This is part of the TestMessage interface.
1180
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
×
1181
        return &KickoffSig{
×
1182
                ChanID:    RandChannelID(t),
×
1183
                Signature: RandSignature(t),
×
1184
                ExtraData: RandExtraOpaqueData(t, nil),
×
1185
        }
×
1186
}
×
1187

1188
// A compile time check to ensure NodeAnnouncement implements the
1189
// lnwire.TestMessage interface.
1190
var _ TestMessage = (*NodeAnnouncement)(nil)
1191

1192
// RandTestMessage populates the message with random data suitable for testing.
1193
// It uses the rapid testing framework to generate random values.
1194
//
1195
// This is part of the TestMessage interface.
1196
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
×
1197
        // Generate random compressed public key for node ID
×
1198
        pubKey := RandPubKey(t)
×
1199
        var nodeID [33]byte
×
1200
        copy(nodeID[:], pubKey.SerializeCompressed())
×
1201

×
1202
        // Generate random RGB color
×
1203
        rgbColor := color.RGBA{
×
1204
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
×
1205
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
×
1206
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
×
1207
        }
×
1208

×
1209
        return &NodeAnnouncement{
×
1210
                Signature: RandSignature(t),
×
1211
                Features:  RandFeatureVector(t),
×
1212
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
1213
                        t, "timestamp"),
×
1214
                ),
×
1215
                NodeID:          nodeID,
×
1216
                RGBColor:        rgbColor,
×
1217
                Alias:           RandNodeAlias(t),
×
1218
                Addresses:       RandNetAddrs(t),
×
1219
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
1220
        }
×
1221
}
×
1222

1223
// A compile time check to ensure OpenChannel implements the TestMessage
1224
// interface.
1225
var _ TestMessage = (*OpenChannel)(nil)
1226

1227
// RandTestMessage populates the message with random data suitable for testing.
1228
// It uses the rapid testing framework to generate random values.
1229
//
1230
// This is part of the TestMessage interface.
1231
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
×
1232
        chainHash := RandChainHash(t)
×
1233
        var hash chainhash.Hash
×
1234
        copy(hash[:], chainHash[:])
×
1235

×
1236
        var pendingChanID [32]byte
×
1237
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1238
                t, "pendingChanID",
×
1239
        )
×
1240
        copy(pendingChanID[:], pendingChanIDBytes)
×
1241

×
1242
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
1243
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
×
1244
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
1245

×
1246
        var channelFlags FundingFlag
×
1247
        if rapid.Bool().Draw(t, "announceChannel") {
×
1248
                channelFlags |= FFAnnounceChannel
×
1249
        }
×
1250

1251
        var localNonce OptMusig2NonceTLV
×
1252
        if includeLocalNonce {
×
1253
                nonce := RandMusig2Nonce(t)
×
1254
                localNonce = tlv.SomeRecordT(
×
1255
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
1256
                )
×
1257
        }
×
1258

1259
        var channelType *ChannelType
×
1260
        if includeChannelType {
×
1261
                channelType = RandChannelType(t)
×
1262
        }
×
1263

1264
        var leaseExpiry *LeaseExpiry
×
1265
        if includeLeaseExpiry {
×
1266
                leaseExpiry = RandLeaseExpiry(t)
×
1267
        }
×
1268

1269
        return &OpenChannel{
×
1270
                ChainHash:        hash,
×
1271
                PendingChannelID: pendingChanID,
×
1272
                FundingAmount: btcutil.Amount(
×
1273
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
×
1274
                ),
×
1275
                PushAmount: MilliSatoshi(
×
1276
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
×
1277
                ),
×
1278
                DustLimit: btcutil.Amount(
×
1279
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
×
1280
                ),
×
1281
                MaxValueInFlight: MilliSatoshi(
×
1282
                        rapid.IntRange(10000, 1000000).Draw(
×
1283
                                t, "maxValueInFlight",
×
1284
                        ),
×
1285
                ),
×
1286
                ChannelReserve: btcutil.Amount(
×
1287
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
×
1288
                ),
×
1289
                HtlcMinimum: MilliSatoshi(
×
1290
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
×
1291
                ),
×
1292
                FeePerKiloWeight: uint32(
×
1293
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
×
1294
                ),
×
1295
                CsvDelay: uint16(
×
1296
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
×
1297
                ),
×
1298
                MaxAcceptedHTLCs: uint16(
×
1299
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
×
1300
                ),
×
1301
                FundingKey:            RandPubKey(t),
×
1302
                RevocationPoint:       RandPubKey(t),
×
1303
                PaymentPoint:          RandPubKey(t),
×
1304
                DelayedPaymentPoint:   RandPubKey(t),
×
1305
                HtlcPoint:             RandPubKey(t),
×
1306
                FirstCommitmentPoint:  RandPubKey(t),
×
1307
                ChannelFlags:          channelFlags,
×
1308
                UpfrontShutdownScript: RandDeliveryAddress(t),
×
1309
                ChannelType:           channelType,
×
1310
                LeaseExpiry:           leaseExpiry,
×
1311
                LocalNonce:            localNonce,
×
1312
                ExtraData:             RandExtraOpaqueData(t, nil),
×
1313
        }
×
1314
}
1315

1316
// A compile time check to ensure Ping implements the lnwire.TestMessage
1317
// interface.
1318
var _ TestMessage = (*Ping)(nil)
1319

1320
// RandTestMessage populates the message with random data suitable for testing.
1321
// It uses the rapid testing framework to generate random values.
1322
//
1323
// This is part of the TestMessage interface.
1324
func (p *Ping) RandTestMessage(t *rapid.T) Message {
×
1325
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
×
1326
                t, "numPongBytes"),
×
1327
        )
×
1328

×
1329
        // Generate padding bytes (but keeping within allowed message size)
×
1330
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
×
1331
        maxPaddingLen := MaxMsgBody - 4
×
1332
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
×
1333
                t, "paddingLen",
×
1334
        )
×
1335
        padding := make(PingPayload, paddingLen)
×
1336

×
1337
        // Fill padding with random bytes
×
1338
        for i := 0; i < paddingLen; i++ {
×
1339
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
×
1340
                        t, fmt.Sprintf("paddingByte%d", i)),
×
1341
                )
×
1342
        }
×
1343

1344
        return &Ping{
×
1345
                NumPongBytes: numPongBytes,
×
1346
                PaddingBytes: padding,
×
1347
        }
×
1348
}
1349

1350
// A compile time check to ensure Pong implements the lnwire.TestMessage
1351
// interface.
1352
var _ TestMessage = (*Pong)(nil)
1353

1354
// RandTestMessage populates the message with random data suitable for testing.
1355
// It uses the rapid testing framework to generate random values.
1356
//
1357
// This is part of the TestMessage interface.
1358
func (p *Pong) RandTestMessage(t *rapid.T) Message {
×
1359
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
×
1360
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
×
1361
                t, "pongPayload",
×
1362
        )
×
1363

×
1364
        return &Pong{
×
1365
                PongBytes: payload,
×
1366
        }
×
1367
}
×
1368

1369
// A compile time check to ensure QueryChannelRange implements the
1370
// lnwire.TestMessage interface.
1371
var _ TestMessage = (*QueryChannelRange)(nil)
1372

1373
// RandTestMessage populates the message with random data suitable for testing.
1374
// It uses the rapid testing framework to generate random values.
1375
//
1376
// This is part of the TestMessage interface.
1377
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
×
1378
        msg := &QueryChannelRange{
×
1379
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
1380
                        t, "firstBlockHeight"),
×
1381
                ),
×
1382
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
1383
                        t, "numBlocks"),
×
1384
                ),
×
1385
                ExtraData: RandExtraOpaqueData(t, nil),
×
1386
        }
×
1387

×
1388
        // Generate chain hash
×
1389
        chainHash := RandChainHash(t)
×
1390
        var chainHashObj chainhash.Hash
×
1391
        copy(chainHashObj[:], chainHash[:])
×
1392
        msg.ChainHash = chainHashObj
×
1393

×
1394
        // Randomly include QueryOptions
×
1395
        if rapid.Bool().Draw(t, "includeQueryOptions") {
×
1396
                queryOptions := &QueryOptions{}
×
1397
                *queryOptions = QueryOptions(*RandFeatureVector(t))
×
1398
                msg.QueryOptions = queryOptions
×
1399
        }
×
1400

1401
        return msg
×
1402
}
1403

1404
// A compile time check to ensure QueryShortChanIDs implements the
1405
// lnwire.TestMessage interface.
1406
var _ TestMessage = (*QueryShortChanIDs)(nil)
1407

1408
// RandTestMessage populates the message with random data suitable for testing.
1409
// It uses the rapid testing framework to generate random values.
1410
//
1411
// This is part of the TestMessage interface.
1412
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
×
1413
        var chainHash chainhash.Hash
×
1414
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
1415
        copy(chainHash[:], hashBytes)
×
1416

×
1417
        encodingType := EncodingSortedPlain
×
1418
        if rapid.Bool().Draw(t, "useZlibEncoding") {
×
1419
                encodingType = EncodingSortedZlib
×
1420
        }
×
1421

1422
        msg := &QueryShortChanIDs{
×
1423
                ChainHash:    chainHash,
×
1424
                EncodingType: encodingType,
×
1425
                ExtraData:    RandExtraOpaqueData(t, nil),
×
1426
                noSort:       false,
×
1427
        }
×
1428

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

×
1431
        // Generate sorted short channel IDs.
×
1432
        shortChanIDs := make([]ShortChannelID, numIDs)
×
1433
        for i := 0; i < numIDs; i++ {
×
1434
                shortChanIDs[i] = RandShortChannelID(t)
×
1435

×
1436
                // Ensure they're properly sorted.
×
1437
                if i > 0 && shortChanIDs[i].ToUint64() <=
×
1438
                        shortChanIDs[i-1].ToUint64() {
×
1439

×
1440
                        // Ensure this ID is larger than the previous one.
×
1441
                        shortChanIDs[i] = NewShortChanIDFromInt(
×
1442
                                shortChanIDs[i-1].ToUint64() + 1,
×
1443
                        )
×
1444
                }
×
1445
        }
1446

1447
        msg.ShortChanIDs = shortChanIDs
×
1448

×
1449
        return msg
×
1450
}
1451

1452
// A compile time check to ensure ReplyChannelRange implements the
1453
// lnwire.TestMessage interface.
1454
var _ TestMessage = (*ReplyChannelRange)(nil)
1455

1456
// RandTestMessage populates the message with random data suitable for testing.
1457
// It uses the rapid testing framework to generate random values.
1458
//
1459
// This is part of the TestMessage interface.
1460
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
×
1461
        msg := &ReplyChannelRange{
×
1462
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
1463
                        t, "firstBlockHeight"),
×
1464
                ),
×
1465
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
1466
                        t, "numBlocks"),
×
1467
                ),
×
1468
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
×
1469
                EncodingType: QueryEncoding(
×
1470
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
×
1471
                ),
×
1472
                ExtraData: RandExtraOpaqueData(t, nil),
×
1473
        }
×
1474

×
1475
        msg.ChainHash = RandChainHash(t)
×
1476

×
1477
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
×
1478
        if numShortChanIDs == 0 {
×
1479
                return msg
×
1480
        }
×
1481

1482
        scidSet := fn.NewSet[ShortChannelID]()
×
1483
        scids := make([]ShortChannelID, numShortChanIDs)
×
1484
        for i := 0; i < numShortChanIDs; i++ {
×
1485
                scid := RandShortChannelID(t)
×
1486
                for scidSet.Contains(scid) {
×
1487
                        scid = RandShortChannelID(t)
×
1488
                }
×
1489

1490
                scids[i] = scid
×
1491

×
1492
                scidSet.Add(scid)
×
1493
        }
1494

1495
        // Make sure there're no duplicates.
1496
        msg.ShortChanIDs = scids
×
1497

×
1498
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
×
1499
                msg.Timestamps = make(Timestamps, numShortChanIDs)
×
1500
                for i := 0; i < numShortChanIDs; i++ {
×
1501
                        msg.Timestamps[i] = ChanUpdateTimestamps{
×
1502
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
×
1503
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
×
1504
                        }
×
1505
                }
×
1506
        }
1507

1508
        return msg
×
1509
}
1510

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

1515
// RandTestMessage populates the message with random data suitable for testing.
1516
// It uses the rapid testing framework to generate random values.
1517
//
1518
// This is part of the TestMessage interface.
1519
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
×
1520
        var chainHash chainhash.Hash
×
1521
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
1522
        copy(chainHash[:], hashBytes)
×
1523

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

×
1526
        return &ReplyShortChanIDsEnd{
×
1527
                ChainHash: chainHash,
×
1528
                Complete:  complete,
×
1529
                ExtraData: RandExtraOpaqueData(t, nil),
×
1530
        }
×
1531
}
×
1532

1533
// RandTestMessage returns a RevokeAndAck message populated with random data.
1534
//
1535
// This is part of the TestMessage interface.
1536
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
×
1537
        msg := NewRevokeAndAck()
×
1538

×
1539
        var chanID ChannelID
×
1540
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
×
1541
        copy(chanID[:], bytes)
×
1542
        msg.ChanID = chanID
×
1543

×
1544
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
×
1545
        copy(msg.Revocation[:], revBytes)
×
1546

×
1547
        msg.NextRevocationKey = RandPubKey(t)
×
1548

×
1549
        if rapid.Bool().Draw(t, "includeLocalNonce") {
×
1550
                var nonce Musig2Nonce
×
1551
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1552
                        t, "nonce",
×
1553
                )
×
1554
                copy(nonce[:], nonceBytes)
×
1555

×
1556
                msg.LocalNonce = tlv.SomeRecordT(
×
1557
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
1558
                )
×
1559
        }
×
1560

1561
        return msg
×
1562
}
1563

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

1568
// RandTestMessage populates the message with random data suitable for testing.
1569
// It uses the rapid testing framework to generate random values.
1570
//
1571
// This is part of the TestMessage interface.
1572
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
×
1573
        // Generate random delivery address
×
1574
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
×
1575
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
×
1576

×
1577
        // Generate random address length based on type
×
1578
        var addrLen int
×
1579
        switch addrType {
×
1580
        // P2PKH
1581
        case 0:
×
1582
                addrLen = 25
×
1583
        // P2SH
1584
        case 1:
×
1585
                addrLen = 23
×
1586
        // P2WPKH
1587
        case 2:
×
1588
                addrLen = 22
×
1589
        // P2WSH
1590
        case 3:
×
1591
                addrLen = 34
×
1592
        // P2TR
1593
        case 4:
×
1594
                addrLen = 34
×
1595
        }
1596

1597
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
×
1598
                t, "address",
×
1599
        )
×
1600

×
1601
        // Randomly decide whether to include a shutdown nonce
×
1602
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
×
1603
        var shutdownNonce ShutdownNonceTLV
×
1604

×
1605
        if includeNonce {
×
1606
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
×
1607
        }
×
1608

1609
        cr, _ := RandCustomRecords(t, nil, true)
×
1610

×
1611
        return &Shutdown{
×
1612
                ChannelID:     RandChannelID(t),
×
1613
                Address:       addr,
×
1614
                ShutdownNonce: shutdownNonce,
×
1615
                CustomRecords: cr,
×
1616
        }
×
1617
}
1618

1619
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1620
// interface.
1621
var _ TestMessage = (*Stfu)(nil)
1622

1623
// RandTestMessage populates the message with random data suitable for testing.
1624
// It uses the rapid testing framework to generate random values.
1625
//
1626
// This is part of the TestMessage interface.
1627
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
×
1628
        m := &Stfu{
×
1629
                ChanID:    RandChannelID(t),
×
1630
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
1631
        }
×
1632

×
1633
        extraData := RandExtraOpaqueData(t, nil)
×
1634
        if len(extraData) > 0 {
×
1635
                m.ExtraData = extraData
×
1636
        }
×
1637

1638
        return m
×
1639
}
1640

1641
// A compile time check to ensure UpdateAddHTLC implements the
1642
// lnwire.TestMessage interface.
1643
var _ TestMessage = (*UpdateAddHTLC)(nil)
1644

1645
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1646
//
1647
// This is part of the TestMessage interface.
1648
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
×
1649
        msg := &UpdateAddHTLC{
×
1650
                ChanID: RandChannelID(t),
×
1651
                ID:     rapid.Uint64().Draw(t, "id"),
×
1652
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
×
1653
                Expiry: rapid.Uint32().Draw(t, "expiry"),
×
1654
        }
×
1655

×
1656
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
×
1657
        copy(msg.PaymentHash[:], hashBytes)
×
1658

×
1659
        onionBytes := rapid.SliceOfN(
×
1660
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
×
1661
        ).Draw(t, "onionBlob")
×
1662
        copy(msg.OnionBlob[:], onionBytes)
×
1663

×
1664
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
×
1665
        if numRecords > 0 {
×
1666
                msg.CustomRecords, _ = RandCustomRecords(t, nil, true)
×
1667
        }
×
1668

1669
        // 50/50 chance to add a blinding point
1670
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
×
1671
                pubKey := RandPubKey(t)
×
1672

×
1673
                msg.BlindingPoint = tlv.SomeRecordT(
×
1674
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
×
1675
                )
×
1676
        }
×
1677

1678
        return msg
×
1679
}
1680

1681
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1682
// interface.
1683
var _ TestMessage = (*UpdateFailHTLC)(nil)
1684

1685
// RandTestMessage populates the message with random data suitable for testing.
1686
// It uses the rapid testing framework to generate random values.
1687
//
1688
// This is part of the TestMessage interface.
1689
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
×
1690
        return &UpdateFailHTLC{
×
1691
                ChanID:    RandChannelID(t),
×
1692
                ID:        rapid.Uint64().Draw(t, "id"),
×
1693
                Reason:    RandOpaqueReason(t),
×
1694
                ExtraData: RandExtraOpaqueData(t, nil),
×
1695
        }
×
1696
}
×
1697

1698
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1699
// TestMessage interface.
1700
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1701

1702
// RandTestMessage populates the message with random data suitable for testing.
1703
// It uses the rapid testing framework to generate random values.
1704
//
1705
// This is part of the TestMessage interface.
1706
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
×
1707
        return &UpdateFailMalformedHTLC{
×
1708
                ChanID:       RandChannelID(t),
×
1709
                ID:           rapid.Uint64().Draw(t, "id"),
×
1710
                ShaOnionBlob: RandSHA256Hash(t),
×
1711
                FailureCode:  RandFailCode(t),
×
1712
                ExtraData:    RandExtraOpaqueData(t, nil),
×
1713
        }
×
1714
}
×
1715

1716
// A compile time check to ensure UpdateFee implements the TestMessage
1717
// interface.
1718
var _ TestMessage = (*UpdateFee)(nil)
1719

1720
// RandTestMessage populates the message with random data suitable for testing.
1721
// It uses the rapid testing framework to generate random values.
1722
//
1723
// This is part of the TestMessage interface.
1724
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
×
1725
        return &UpdateFee{
×
1726
                ChanID:    RandChannelID(t),
×
1727
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
×
1728
                ExtraData: RandExtraOpaqueData(t, nil),
×
1729
        }
×
1730
}
×
1731

1732
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1733
// interface.
1734
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1735

1736
// RandTestMessage populates the message with random data suitable for testing.
1737
// It uses the rapid testing framework to generate random values.
1738
//
1739
// This is part of the TestMessage interface.
1740
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
×
1741
        msg := &UpdateFulfillHTLC{
×
1742
                ChanID:          RandChannelID(t),
×
1743
                ID:              rapid.Uint64().Draw(t, "id"),
×
1744
                PaymentPreimage: RandPaymentPreimage(t),
×
1745
        }
×
1746

×
1747
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
×
1748
        msg.CustomRecords = cr
×
1749

×
1750
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
1751
        if len(randData) > 0 {
×
1752
                msg.ExtraData = randData
×
1753
        }
×
1754

1755
        return msg
×
1756
}
1757

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

1762
// RandTestMessage populates the message with random data suitable for testing.
1763
// It uses the rapid testing framework to generate random values.
1764
//
1765
// This is part of the TestMessage interface.
1766
func (c *Warning) RandTestMessage(t *rapid.T) Message {
×
1767
        msg := &Warning{
×
1768
                ChanID: RandChannelID(t),
×
1769
        }
×
1770

×
1771
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
1772
        if useASCII {
×
1773
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
1774
                data := make([]byte, length)
×
1775
                for i := 0; i < length; i++ {
×
1776
                        data[i] = byte(
×
1777
                                rapid.IntRange(32, 126).Draw(
×
1778
                                        t, fmt.Sprintf("warningDataByte-%d", i),
×
1779
                                ),
×
1780
                        )
×
1781
                }
×
1782
                msg.Data = data
×
1783
        } else {
×
1784
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
1785
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
×
1786
                        t, "warningData",
×
1787
                )
×
1788
        }
×
1789

1790
        return msg
×
1791
}
1792

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

1797
// RandTestMessage populates the message with random data suitable for testing.
1798
// It uses the rapid testing framework to generate random values.
1799
//
1800
// This is part of the TestMessage interface.
1801
func (c *Error) RandTestMessage(t *rapid.T) Message {
×
1802
        msg := &Error{
×
1803
                ChanID: RandChannelID(t),
×
1804
        }
×
1805

×
1806
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
1807
        if useASCII {
×
1808
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
1809
                data := make([]byte, length)
×
1810
                for i := 0; i < length; i++ {
×
1811
                        data[i] = byte(
×
1812
                                rapid.IntRange(32, 126).Draw(
×
1813
                                        t, fmt.Sprintf("errorDataByte-%d", i),
×
1814
                                ),
×
1815
                        )
×
1816
                }
×
1817
                msg.Data = data
×
1818
        } else {
×
1819
                // Generate random binary data
×
1820
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
1821
                msg.Data = rapid.SliceOfN(
×
1822
                        rapid.Byte(), length, length,
×
1823
                ).Draw(t, "errorData")
×
1824
        }
×
1825

1826
        return msg
×
1827
}
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