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

lightningnetwork / lnd / 16313570092

16 Jul 2025 07:46AM UTC coverage: 57.583% (-9.7%) from 67.321%
16313570092

push

github

web-flow
Merge pull request #9751 from starius/bump-deps

multi: update Go to 1.23.10 and update some packages

98678 of 171367 relevant lines covered (57.58%)

1.79 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
                ExtraData: RandExtraOpaqueData(t, nil),
×
797
        }
×
798

×
799
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
800

×
801
        if includeLocalNonce {
×
802
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
×
803
        }
×
804

805
        return msg
×
806
}
807

808
// A compile time check to ensure DynPropose implements the lnwire.TestMessage
809
// interface.
810
var _ TestMessage = (*DynPropose)(nil)
811

812
// RandTestMessage populates the message with random data suitable for testing.
813
// It uses the rapid testing framework to generate random values.
814
//
815
// This is part of the TestMessage interface.
816
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
×
817
        msg := &DynPropose{
×
818
                ChanID:    RandChannelID(t),
×
819
                ExtraData: RandExtraOpaqueData(t, nil),
×
820
        }
×
821

×
822
        // Randomly decide which optional fields to include
×
823
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
824
        includeMaxValueInFlight := rapid.Bool().Draw(
×
825
                t, "includeMaxValueInFlight",
×
826
        )
×
827
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
828
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
829
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
830
                t, "includeMaxAcceptedHTLCs",
×
831
        )
×
832
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
833

×
834
        // Generate random values for each included field
×
835
        if includeDustLimit {
×
836
                var rec tlv.RecordT[tlv.TlvType0, btcutil.Amount]
×
837
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
838
                rec.Val = val
×
839
                msg.DustLimit = tlv.SomeRecordT(rec)
×
840
        }
×
841

842
        if includeMaxValueInFlight {
×
843
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
×
844
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
845
                rec.Val = val
×
846
                msg.MaxValueInFlight = tlv.SomeRecordT(rec)
×
847
        }
×
848

849
        if includeChannelReserve {
×
850
                var rec tlv.RecordT[tlv.TlvType6, btcutil.Amount]
×
851
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
852
                rec.Val = val
×
853
                msg.ChannelReserve = tlv.SomeRecordT(rec)
×
854
        }
×
855

856
        if includeCsvDelay {
×
857
                csvDelay := msg.CsvDelay.Zero()
×
858
                val := rapid.Uint16().Draw(t, "csvDelay")
×
859
                csvDelay.Val = val
×
860
                msg.CsvDelay = tlv.SomeRecordT(csvDelay)
×
861
        }
×
862

863
        if includeMaxAcceptedHTLCs {
×
864
                maxHtlcs := msg.MaxAcceptedHTLCs.Zero()
×
865
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
866
                msg.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
867
        }
×
868

869
        if includeChannelType {
×
870
                chanType := msg.ChannelType.Zero()
×
871
                chanType.Val = *RandChannelType(t)
×
872
                msg.ChannelType = tlv.SomeRecordT(chanType)
×
873
        }
×
874

875
        return msg
×
876
}
877

878
// A compile time check to ensure DynReject implements the lnwire.TestMessage
879
// interface.
880
var _ TestMessage = (*DynReject)(nil)
881

882
// RandTestMessage populates the message with random data suitable for testing.
883
// It uses the rapid testing framework to generate random values.
884
//
885
// This is part of the TestMessage interface.
886
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
×
887
        featureVec := NewRawFeatureVector()
×
888

×
889
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
×
890
        for i := 0; i < numFeatures; i++ {
×
891
                bit := FeatureBit(
×
892
                        rapid.IntRange(0, 31).Draw(
×
893
                                t, fmt.Sprintf("rejectionBit-%d", i),
×
894
                        ),
×
895
                )
×
896
                featureVec.Set(bit)
×
897
        }
×
898

899
        var extraData ExtraOpaqueData
×
900
        randData := RandExtraOpaqueData(t, nil)
×
901
        if len(randData) > 0 {
×
902
                extraData = randData
×
903
        }
×
904

905
        return &DynReject{
×
906
                ChanID:           RandChannelID(t),
×
907
                UpdateRejections: *featureVec,
×
908
                ExtraData:        extraData,
×
909
        }
×
910
}
911

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

916
// RandTestMessage populates the message with random data suitable for testing.
917
// It uses the rapid testing framework to generate random values.
918
//
919
// This is part of the TestMessage interface.
920
func (dc *DynCommit) RandTestMessage(t *rapid.T) Message {
×
921
        chanID := RandChannelID(t)
×
922

×
923
        da := &DynAck{
×
924
                ChanID: chanID,
×
925
        }
×
926

×
927
        dp := &DynPropose{
×
928
                ChanID: chanID,
×
929
        }
×
930

×
931
        // Randomly decide which optional fields to include
×
932
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
933
        includeMaxValueInFlight := rapid.Bool().Draw(
×
934
                t, "includeMaxValueInFlight",
×
935
        )
×
936
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
937
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
938
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
939
                t, "includeMaxAcceptedHTLCs",
×
940
        )
×
941
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
942

×
943
        // Generate random values for each included field
×
944
        if includeDustLimit {
×
945
                var rec tlv.RecordT[tlv.TlvType0, btcutil.Amount]
×
946
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
947
                rec.Val = val
×
948
                dp.DustLimit = tlv.SomeRecordT(rec)
×
949
        }
×
950

951
        if includeMaxValueInFlight {
×
952
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
×
953
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
954
                rec.Val = val
×
955
                dp.MaxValueInFlight = tlv.SomeRecordT(rec)
×
956
        }
×
957

958
        if includeChannelReserve {
×
959
                var rec tlv.RecordT[tlv.TlvType6, btcutil.Amount]
×
960
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
961
                rec.Val = val
×
962
                dp.ChannelReserve = tlv.SomeRecordT(rec)
×
963
        }
×
964

965
        if includeCsvDelay {
×
966
                csvDelay := dp.CsvDelay.Zero()
×
967
                val := rapid.Uint16().Draw(t, "csvDelay")
×
968
                csvDelay.Val = val
×
969
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
×
970
        }
×
971

972
        if includeMaxAcceptedHTLCs {
×
973
                maxHtlcs := dp.MaxAcceptedHTLCs.Zero()
×
974
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
975
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
976
        }
×
977

978
        if includeChannelType {
×
979
                chanType := dp.ChannelType.Zero()
×
980
                chanType.Val = *RandChannelType(t)
×
981
                dp.ChannelType = tlv.SomeRecordT(chanType)
×
982
        }
×
983

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

990
        return &DynCommit{
×
991
                DynPropose: *dp,
×
992
                DynAck:     *da,
×
993
                ExtraData:  extraData,
×
994
        }
×
995
}
996

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

1001
// RandTestMessage populates the message with random data suitable for testing.
1002
// It uses the rapid testing framework to generate random values.
1003
//
1004
// This is part of the TestMessage interface.
1005
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
×
1006
        var pendingChanID [32]byte
×
1007
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1008
                t, "pendingChanID",
×
1009
        )
×
1010
        copy(pendingChanID[:], pendingChanIDBytes)
×
1011

×
1012
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
1013
        var partialSig OptPartialSigWithNonceTLV
×
1014
        var commitSig Sig
×
1015

×
1016
        if includePartialSig {
×
1017
                sigWithNonce := RandPartialSigWithNonce(t)
×
1018
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
1019

×
1020
                // When using partial sig, CommitSig should be empty/blank.
×
1021
                commitSig = Sig{}
×
1022
        } else {
×
1023
                commitSig = RandSignature(t)
×
1024
        }
×
1025

1026
        return &FundingCreated{
×
1027
                PendingChannelID: pendingChanID,
×
1028
                FundingPoint:     RandOutPoint(t),
×
1029
                CommitSig:        commitSig,
×
1030
                PartialSig:       partialSig,
×
1031
                ExtraData:        RandExtraOpaqueData(t, nil),
×
1032
        }
×
1033
}
1034

1035
// A compile time check to ensure FundingSigned implements the
1036
// lnwire.TestMessage interface.
1037
var _ TestMessage = (*FundingSigned)(nil)
1038

1039
// RandTestMessage populates the message with random data suitable for testing.
1040
// It uses the rapid testing framework to generate random values.
1041
//
1042
// This is part of the TestMessage interface.
1043
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
×
1044
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
1045

×
1046
        msg := &FundingSigned{
×
1047
                ChanID:    RandChannelID(t),
×
1048
                ExtraData: RandExtraOpaqueData(t, nil),
×
1049
        }
×
1050

×
1051
        if usePartialSig {
×
1052
                sigWithNonce := RandPartialSigWithNonce(t)
×
1053
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
1054

×
1055
                msg.CommitSig = Sig{}
×
1056
        } else {
×
1057
                msg.CommitSig = RandSignature(t)
×
1058
        }
×
1059

1060
        return msg
×
1061
}
1062

1063
// A compile time check to ensure GossipTimestampRange implements the
1064
// lnwire.TestMessage interface.
1065
var _ TestMessage = (*GossipTimestampRange)(nil)
1066

1067
// RandTestMessage populates the message with random data suitable for testing.
1068
// It uses the rapid testing framework to generate random values.
1069
//
1070
// This is part of the TestMessage interface.
1071
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
×
1072
        var chainHash chainhash.Hash
×
1073
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
1074
        copy(chainHash[:], hashBytes)
×
1075

×
1076
        msg := &GossipTimestampRange{
×
1077
                ChainHash:      chainHash,
×
1078
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
×
1079
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
×
1080
                ExtraData:      RandExtraOpaqueData(t, nil),
×
1081
        }
×
1082

×
1083
        includeFirstBlockHeight := rapid.Bool().Draw(
×
1084
                t, "includeFirstBlockHeight",
×
1085
        )
×
1086
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
×
1087

×
1088
        if includeFirstBlockHeight {
×
1089
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
×
1090
                msg.FirstBlockHeight = tlv.SomeRecordT(
×
1091
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
×
1092
                )
×
1093
        }
×
1094

1095
        if includeBlockRange {
×
1096
                blockRange := rapid.Uint32().Draw(t, "blockRange")
×
1097
                msg.BlockRange = tlv.SomeRecordT(
×
1098
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
×
1099
                )
×
1100
        }
×
1101

1102
        return msg
×
1103
}
1104

1105
// RandTestMessage populates the message with random data suitable for testing.
1106
// It uses the rapid testing framework to generate random values.
1107
//
1108
// This is part of the TestMessage interface.
1109
func (msg *Init) RandTestMessage(t *rapid.T) Message {
×
1110
        global := NewRawFeatureVector()
×
1111
        local := NewRawFeatureVector()
×
1112

×
1113
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
×
1114
        for i := 0; i < numGlobalFeatures; i++ {
×
1115
                bit := FeatureBit(
×
1116
                        rapid.IntRange(0, 100).Draw(
×
1117
                                t, fmt.Sprintf("globalFeatureBit%d", i),
×
1118
                        ),
×
1119
                )
×
1120
                global.Set(bit)
×
1121
        }
×
1122

1123
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
×
1124
        for i := 0; i < numLocalFeatures; i++ {
×
1125
                bit := FeatureBit(
×
1126
                        rapid.IntRange(0, 100).Draw(
×
1127
                                t, fmt.Sprintf("localFeatureBit%d", i),
×
1128
                        ),
×
1129
                )
×
1130
                local.Set(bit)
×
1131
        }
×
1132

1133
        return NewInitMessage(global, local)
×
1134
}
1135

1136
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1137
// interface.
1138
var _ TestMessage = (*KickoffSig)(nil)
1139

1140
// RandTestMessage populates the message with random data suitable for testing.
1141
// It uses the rapid testing framework to generate random values.
1142
//
1143
// This is part of the TestMessage interface.
1144
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
×
1145
        return &KickoffSig{
×
1146
                ChanID:    RandChannelID(t),
×
1147
                Signature: RandSignature(t),
×
1148
                ExtraData: RandExtraOpaqueData(t, nil),
×
1149
        }
×
1150
}
×
1151

1152
// A compile time check to ensure NodeAnnouncement implements the
1153
// lnwire.TestMessage interface.
1154
var _ TestMessage = (*NodeAnnouncement)(nil)
1155

1156
// RandTestMessage populates the message with random data suitable for testing.
1157
// It uses the rapid testing framework to generate random values.
1158
//
1159
// This is part of the TestMessage interface.
1160
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
×
1161
        // Generate random compressed public key for node ID
×
1162
        pubKey := RandPubKey(t)
×
1163
        var nodeID [33]byte
×
1164
        copy(nodeID[:], pubKey.SerializeCompressed())
×
1165

×
1166
        // Generate random RGB color
×
1167
        rgbColor := color.RGBA{
×
1168
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
×
1169
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
×
1170
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
×
1171
        }
×
1172

×
1173
        return &NodeAnnouncement{
×
1174
                Signature: RandSignature(t),
×
1175
                Features:  RandFeatureVector(t),
×
1176
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
1177
                        t, "timestamp"),
×
1178
                ),
×
1179
                NodeID:          nodeID,
×
1180
                RGBColor:        rgbColor,
×
1181
                Alias:           RandNodeAlias(t),
×
1182
                Addresses:       RandNetAddrs(t),
×
1183
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
1184
        }
×
1185
}
×
1186

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

1191
// RandTestMessage populates the message with random data suitable for testing.
1192
// It uses the rapid testing framework to generate random values.
1193
//
1194
// This is part of the TestMessage interface.
1195
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
×
1196
        chainHash := RandChainHash(t)
×
1197
        var hash chainhash.Hash
×
1198
        copy(hash[:], chainHash[:])
×
1199

×
1200
        var pendingChanID [32]byte
×
1201
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1202
                t, "pendingChanID",
×
1203
        )
×
1204
        copy(pendingChanID[:], pendingChanIDBytes)
×
1205

×
1206
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
1207
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
×
1208
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
1209

×
1210
        var channelFlags FundingFlag
×
1211
        if rapid.Bool().Draw(t, "announceChannel") {
×
1212
                channelFlags |= FFAnnounceChannel
×
1213
        }
×
1214

1215
        var localNonce OptMusig2NonceTLV
×
1216
        if includeLocalNonce {
×
1217
                nonce := RandMusig2Nonce(t)
×
1218
                localNonce = tlv.SomeRecordT(
×
1219
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
1220
                )
×
1221
        }
×
1222

1223
        var channelType *ChannelType
×
1224
        if includeChannelType {
×
1225
                channelType = RandChannelType(t)
×
1226
        }
×
1227

1228
        var leaseExpiry *LeaseExpiry
×
1229
        if includeLeaseExpiry {
×
1230
                leaseExpiry = RandLeaseExpiry(t)
×
1231
        }
×
1232

1233
        return &OpenChannel{
×
1234
                ChainHash:        hash,
×
1235
                PendingChannelID: pendingChanID,
×
1236
                FundingAmount: btcutil.Amount(
×
1237
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
×
1238
                ),
×
1239
                PushAmount: MilliSatoshi(
×
1240
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
×
1241
                ),
×
1242
                DustLimit: btcutil.Amount(
×
1243
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
×
1244
                ),
×
1245
                MaxValueInFlight: MilliSatoshi(
×
1246
                        rapid.IntRange(10000, 1000000).Draw(
×
1247
                                t, "maxValueInFlight",
×
1248
                        ),
×
1249
                ),
×
1250
                ChannelReserve: btcutil.Amount(
×
1251
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
×
1252
                ),
×
1253
                HtlcMinimum: MilliSatoshi(
×
1254
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
×
1255
                ),
×
1256
                FeePerKiloWeight: uint32(
×
1257
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
×
1258
                ),
×
1259
                CsvDelay: uint16(
×
1260
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
×
1261
                ),
×
1262
                MaxAcceptedHTLCs: uint16(
×
1263
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
×
1264
                ),
×
1265
                FundingKey:            RandPubKey(t),
×
1266
                RevocationPoint:       RandPubKey(t),
×
1267
                PaymentPoint:          RandPubKey(t),
×
1268
                DelayedPaymentPoint:   RandPubKey(t),
×
1269
                HtlcPoint:             RandPubKey(t),
×
1270
                FirstCommitmentPoint:  RandPubKey(t),
×
1271
                ChannelFlags:          channelFlags,
×
1272
                UpfrontShutdownScript: RandDeliveryAddress(t),
×
1273
                ChannelType:           channelType,
×
1274
                LeaseExpiry:           leaseExpiry,
×
1275
                LocalNonce:            localNonce,
×
1276
                ExtraData:             RandExtraOpaqueData(t, nil),
×
1277
        }
×
1278
}
1279

1280
// A compile time check to ensure Ping implements the lnwire.TestMessage
1281
// interface.
1282
var _ TestMessage = (*Ping)(nil)
1283

1284
// RandTestMessage populates the message with random data suitable for testing.
1285
// It uses the rapid testing framework to generate random values.
1286
//
1287
// This is part of the TestMessage interface.
1288
func (p *Ping) RandTestMessage(t *rapid.T) Message {
×
1289
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
×
1290
                t, "numPongBytes"),
×
1291
        )
×
1292

×
1293
        // Generate padding bytes (but keeping within allowed message size)
×
1294
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
×
1295
        maxPaddingLen := MaxMsgBody - 4
×
1296
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
×
1297
                t, "paddingLen",
×
1298
        )
×
1299
        padding := make(PingPayload, paddingLen)
×
1300

×
1301
        // Fill padding with random bytes
×
1302
        for i := 0; i < paddingLen; i++ {
×
1303
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
×
1304
                        t, fmt.Sprintf("paddingByte%d", i)),
×
1305
                )
×
1306
        }
×
1307

1308
        return &Ping{
×
1309
                NumPongBytes: numPongBytes,
×
1310
                PaddingBytes: padding,
×
1311
        }
×
1312
}
1313

1314
// A compile time check to ensure Pong implements the lnwire.TestMessage
1315
// interface.
1316
var _ TestMessage = (*Pong)(nil)
1317

1318
// RandTestMessage populates the message with random data suitable for testing.
1319
// It uses the rapid testing framework to generate random values.
1320
//
1321
// This is part of the TestMessage interface.
1322
func (p *Pong) RandTestMessage(t *rapid.T) Message {
×
1323
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
×
1324
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
×
1325
                t, "pongPayload",
×
1326
        )
×
1327

×
1328
        return &Pong{
×
1329
                PongBytes: payload,
×
1330
        }
×
1331
}
×
1332

1333
// A compile time check to ensure QueryChannelRange implements the
1334
// lnwire.TestMessage interface.
1335
var _ TestMessage = (*QueryChannelRange)(nil)
1336

1337
// RandTestMessage populates the message with random data suitable for testing.
1338
// It uses the rapid testing framework to generate random values.
1339
//
1340
// This is part of the TestMessage interface.
1341
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
×
1342
        msg := &QueryChannelRange{
×
1343
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
1344
                        t, "firstBlockHeight"),
×
1345
                ),
×
1346
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
1347
                        t, "numBlocks"),
×
1348
                ),
×
1349
                ExtraData: RandExtraOpaqueData(t, nil),
×
1350
        }
×
1351

×
1352
        // Generate chain hash
×
1353
        chainHash := RandChainHash(t)
×
1354
        var chainHashObj chainhash.Hash
×
1355
        copy(chainHashObj[:], chainHash[:])
×
1356
        msg.ChainHash = chainHashObj
×
1357

×
1358
        // Randomly include QueryOptions
×
1359
        if rapid.Bool().Draw(t, "includeQueryOptions") {
×
1360
                queryOptions := &QueryOptions{}
×
1361
                *queryOptions = QueryOptions(*RandFeatureVector(t))
×
1362
                msg.QueryOptions = queryOptions
×
1363
        }
×
1364

1365
        return msg
×
1366
}
1367

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

1372
// RandTestMessage populates the message with random data suitable for testing.
1373
// It uses the rapid testing framework to generate random values.
1374
//
1375
// This is part of the TestMessage interface.
1376
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
×
1377
        var chainHash chainhash.Hash
×
1378
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
1379
        copy(chainHash[:], hashBytes)
×
1380

×
1381
        encodingType := EncodingSortedPlain
×
1382
        if rapid.Bool().Draw(t, "useZlibEncoding") {
×
1383
                encodingType = EncodingSortedZlib
×
1384
        }
×
1385

1386
        msg := &QueryShortChanIDs{
×
1387
                ChainHash:    chainHash,
×
1388
                EncodingType: encodingType,
×
1389
                ExtraData:    RandExtraOpaqueData(t, nil),
×
1390
                noSort:       false,
×
1391
        }
×
1392

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

×
1395
        // Generate sorted short channel IDs.
×
1396
        shortChanIDs := make([]ShortChannelID, numIDs)
×
1397
        for i := 0; i < numIDs; i++ {
×
1398
                shortChanIDs[i] = RandShortChannelID(t)
×
1399

×
1400
                // Ensure they're properly sorted.
×
1401
                if i > 0 && shortChanIDs[i].ToUint64() <=
×
1402
                        shortChanIDs[i-1].ToUint64() {
×
1403

×
1404
                        // Ensure this ID is larger than the previous one.
×
1405
                        shortChanIDs[i] = NewShortChanIDFromInt(
×
1406
                                shortChanIDs[i-1].ToUint64() + 1,
×
1407
                        )
×
1408
                }
×
1409
        }
1410

1411
        msg.ShortChanIDs = shortChanIDs
×
1412

×
1413
        return msg
×
1414
}
1415

1416
// A compile time check to ensure ReplyChannelRange implements the
1417
// lnwire.TestMessage interface.
1418
var _ TestMessage = (*ReplyChannelRange)(nil)
1419

1420
// RandTestMessage populates the message with random data suitable for testing.
1421
// It uses the rapid testing framework to generate random values.
1422
//
1423
// This is part of the TestMessage interface.
1424
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
×
1425
        msg := &ReplyChannelRange{
×
1426
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
1427
                        t, "firstBlockHeight"),
×
1428
                ),
×
1429
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
1430
                        t, "numBlocks"),
×
1431
                ),
×
1432
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
×
1433
                EncodingType: QueryEncoding(
×
1434
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
×
1435
                ),
×
1436
                ExtraData: RandExtraOpaqueData(t, nil),
×
1437
        }
×
1438

×
1439
        msg.ChainHash = RandChainHash(t)
×
1440

×
1441
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
×
1442
        if numShortChanIDs == 0 {
×
1443
                return msg
×
1444
        }
×
1445

1446
        scidSet := fn.NewSet[ShortChannelID]()
×
1447
        scids := make([]ShortChannelID, numShortChanIDs)
×
1448
        for i := 0; i < numShortChanIDs; i++ {
×
1449
                scid := RandShortChannelID(t)
×
1450
                for scidSet.Contains(scid) {
×
1451
                        scid = RandShortChannelID(t)
×
1452
                }
×
1453

1454
                scids[i] = scid
×
1455

×
1456
                scidSet.Add(scid)
×
1457
        }
1458

1459
        // Make sure there're no duplicates.
1460
        msg.ShortChanIDs = scids
×
1461

×
1462
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
×
1463
                msg.Timestamps = make(Timestamps, numShortChanIDs)
×
1464
                for i := 0; i < numShortChanIDs; i++ {
×
1465
                        msg.Timestamps[i] = ChanUpdateTimestamps{
×
1466
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
×
1467
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
×
1468
                        }
×
1469
                }
×
1470
        }
1471

1472
        return msg
×
1473
}
1474

1475
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1476
// lnwire.TestMessage interface.
1477
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1478

1479
// RandTestMessage populates the message with random data suitable for testing.
1480
// It uses the rapid testing framework to generate random values.
1481
//
1482
// This is part of the TestMessage interface.
1483
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
×
1484
        var chainHash chainhash.Hash
×
1485
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
1486
        copy(chainHash[:], hashBytes)
×
1487

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

×
1490
        return &ReplyShortChanIDsEnd{
×
1491
                ChainHash: chainHash,
×
1492
                Complete:  complete,
×
1493
                ExtraData: RandExtraOpaqueData(t, nil),
×
1494
        }
×
1495
}
×
1496

1497
// RandTestMessage returns a RevokeAndAck message populated with random data.
1498
//
1499
// This is part of the TestMessage interface.
1500
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
×
1501
        msg := NewRevokeAndAck()
×
1502

×
1503
        var chanID ChannelID
×
1504
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
×
1505
        copy(chanID[:], bytes)
×
1506
        msg.ChanID = chanID
×
1507

×
1508
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
×
1509
        copy(msg.Revocation[:], revBytes)
×
1510

×
1511
        msg.NextRevocationKey = RandPubKey(t)
×
1512

×
1513
        if rapid.Bool().Draw(t, "includeLocalNonce") {
×
1514
                var nonce Musig2Nonce
×
1515
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1516
                        t, "nonce",
×
1517
                )
×
1518
                copy(nonce[:], nonceBytes)
×
1519

×
1520
                msg.LocalNonce = tlv.SomeRecordT(
×
1521
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
1522
                )
×
1523
        }
×
1524

1525
        return msg
×
1526
}
1527

1528
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1529
// interface.
1530
var _ TestMessage = (*Shutdown)(nil)
1531

1532
// RandTestMessage populates the message with random data suitable for testing.
1533
// It uses the rapid testing framework to generate random values.
1534
//
1535
// This is part of the TestMessage interface.
1536
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
×
1537
        // Generate random delivery address
×
1538
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
×
1539
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
×
1540

×
1541
        // Generate random address length based on type
×
1542
        var addrLen int
×
1543
        switch addrType {
×
1544
        // P2PKH
1545
        case 0:
×
1546
                addrLen = 25
×
1547
        // P2SH
1548
        case 1:
×
1549
                addrLen = 23
×
1550
        // P2WPKH
1551
        case 2:
×
1552
                addrLen = 22
×
1553
        // P2WSH
1554
        case 3:
×
1555
                addrLen = 34
×
1556
        // P2TR
1557
        case 4:
×
1558
                addrLen = 34
×
1559
        }
1560

1561
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
×
1562
                t, "address",
×
1563
        )
×
1564

×
1565
        // Randomly decide whether to include a shutdown nonce
×
1566
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
×
1567
        var shutdownNonce ShutdownNonceTLV
×
1568

×
1569
        if includeNonce {
×
1570
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
×
1571
        }
×
1572

1573
        cr, _ := RandCustomRecords(t, nil, true)
×
1574

×
1575
        return &Shutdown{
×
1576
                ChannelID:     RandChannelID(t),
×
1577
                Address:       addr,
×
1578
                ShutdownNonce: shutdownNonce,
×
1579
                CustomRecords: cr,
×
1580
        }
×
1581
}
1582

1583
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1584
// interface.
1585
var _ TestMessage = (*Stfu)(nil)
1586

1587
// RandTestMessage populates the message with random data suitable for testing.
1588
// It uses the rapid testing framework to generate random values.
1589
//
1590
// This is part of the TestMessage interface.
1591
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
×
1592
        m := &Stfu{
×
1593
                ChanID:    RandChannelID(t),
×
1594
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
1595
        }
×
1596

×
1597
        extraData := RandExtraOpaqueData(t, nil)
×
1598
        if len(extraData) > 0 {
×
1599
                m.ExtraData = extraData
×
1600
        }
×
1601

1602
        return m
×
1603
}
1604

1605
// A compile time check to ensure UpdateAddHTLC implements the
1606
// lnwire.TestMessage interface.
1607
var _ TestMessage = (*UpdateAddHTLC)(nil)
1608

1609
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1610
//
1611
// This is part of the TestMessage interface.
1612
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
×
1613
        msg := &UpdateAddHTLC{
×
1614
                ChanID: RandChannelID(t),
×
1615
                ID:     rapid.Uint64().Draw(t, "id"),
×
1616
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
×
1617
                Expiry: rapid.Uint32().Draw(t, "expiry"),
×
1618
        }
×
1619

×
1620
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
×
1621
        copy(msg.PaymentHash[:], hashBytes)
×
1622

×
1623
        onionBytes := rapid.SliceOfN(
×
1624
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
×
1625
        ).Draw(t, "onionBlob")
×
1626
        copy(msg.OnionBlob[:], onionBytes)
×
1627

×
1628
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
×
1629
        if numRecords > 0 {
×
1630
                msg.CustomRecords, _ = RandCustomRecords(t, nil, true)
×
1631
        }
×
1632

1633
        // 50/50 chance to add a blinding point
1634
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
×
1635
                pubKey := RandPubKey(t)
×
1636

×
1637
                msg.BlindingPoint = tlv.SomeRecordT(
×
1638
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
×
1639
                )
×
1640
        }
×
1641

1642
        return msg
×
1643
}
1644

1645
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1646
// interface.
1647
var _ TestMessage = (*UpdateFailHTLC)(nil)
1648

1649
// RandTestMessage populates the message with random data suitable for testing.
1650
// It uses the rapid testing framework to generate random values.
1651
//
1652
// This is part of the TestMessage interface.
1653
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
×
1654
        return &UpdateFailHTLC{
×
1655
                ChanID:    RandChannelID(t),
×
1656
                ID:        rapid.Uint64().Draw(t, "id"),
×
1657
                Reason:    RandOpaqueReason(t),
×
1658
                ExtraData: RandExtraOpaqueData(t, nil),
×
1659
        }
×
1660
}
×
1661

1662
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1663
// TestMessage interface.
1664
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1665

1666
// RandTestMessage populates the message with random data suitable for testing.
1667
// It uses the rapid testing framework to generate random values.
1668
//
1669
// This is part of the TestMessage interface.
1670
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
×
1671
        return &UpdateFailMalformedHTLC{
×
1672
                ChanID:       RandChannelID(t),
×
1673
                ID:           rapid.Uint64().Draw(t, "id"),
×
1674
                ShaOnionBlob: RandSHA256Hash(t),
×
1675
                FailureCode:  RandFailCode(t),
×
1676
                ExtraData:    RandExtraOpaqueData(t, nil),
×
1677
        }
×
1678
}
×
1679

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

1684
// RandTestMessage populates the message with random data suitable for testing.
1685
// It uses the rapid testing framework to generate random values.
1686
//
1687
// This is part of the TestMessage interface.
1688
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
×
1689
        return &UpdateFee{
×
1690
                ChanID:    RandChannelID(t),
×
1691
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
×
1692
                ExtraData: RandExtraOpaqueData(t, nil),
×
1693
        }
×
1694
}
×
1695

1696
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1697
// interface.
1698
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1699

1700
// RandTestMessage populates the message with random data suitable for testing.
1701
// It uses the rapid testing framework to generate random values.
1702
//
1703
// This is part of the TestMessage interface.
1704
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
×
1705
        msg := &UpdateFulfillHTLC{
×
1706
                ChanID:          RandChannelID(t),
×
1707
                ID:              rapid.Uint64().Draw(t, "id"),
×
1708
                PaymentPreimage: RandPaymentPreimage(t),
×
1709
        }
×
1710

×
1711
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
×
1712
        msg.CustomRecords = cr
×
1713

×
1714
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
1715
        if len(randData) > 0 {
×
1716
                msg.ExtraData = randData
×
1717
        }
×
1718

1719
        return msg
×
1720
}
1721

1722
// A compile time check to ensure Warning implements the lnwire.TestMessage
1723
// interface.
1724
var _ TestMessage = (*Warning)(nil)
1725

1726
// RandTestMessage populates the message with random data suitable for testing.
1727
// It uses the rapid testing framework to generate random values.
1728
//
1729
// This is part of the TestMessage interface.
1730
func (c *Warning) RandTestMessage(t *rapid.T) Message {
×
1731
        msg := &Warning{
×
1732
                ChanID: RandChannelID(t),
×
1733
        }
×
1734

×
1735
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
1736
        if useASCII {
×
1737
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
1738
                data := make([]byte, length)
×
1739
                for i := 0; i < length; i++ {
×
1740
                        data[i] = byte(
×
1741
                                rapid.IntRange(32, 126).Draw(
×
1742
                                        t, fmt.Sprintf("warningDataByte-%d", i),
×
1743
                                ),
×
1744
                        )
×
1745
                }
×
1746
                msg.Data = data
×
1747
        } else {
×
1748
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
1749
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
×
1750
                        t, "warningData",
×
1751
                )
×
1752
        }
×
1753

1754
        return msg
×
1755
}
1756

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

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

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

1790
        return msg
×
1791
}
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