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

lightningnetwork / lnd / 16263831630

14 Jul 2025 10:00AM UTC coverage: 67.315% (-0.02%) from 67.339%
16263831630

Pull #10072

github

web-flow
Merge 480167d37 into 5bb227774
Pull Request #10072: [1/2] lnwire: fix encoding customized TLV records

265 of 275 new or added lines in 8 files covered. (96.36%)

101 existing lines in 19 files now uncovered.

135293 of 200984 relevant lines covered (67.32%)

21801.32 hits per line

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

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

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

100✔
49
        if includeChannelType {
151✔
50
                channelType = RandChannelType(t)
51✔
51
        }
51✔
52

53
        var leaseExpiry *LeaseExpiry
100✔
54
        if includeLeaseExpiry {
147✔
55
                leaseExpiry = RandLeaseExpiry(t)
47✔
56
        }
47✔
57

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

66
        return &AcceptChannel{
100✔
67
                PendingChannelID: pendingChanID,
100✔
68
                DustLimit: btcutil.Amount(
100✔
69
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
100✔
70
                ),
100✔
71
                MaxValueInFlight: MilliSatoshi(
100✔
72
                        rapid.IntRange(10000, 1000000).Draw(
100✔
73
                                t, "maxValueInFlight",
100✔
74
                        ),
100✔
75
                ),
100✔
76
                ChannelReserve: btcutil.Amount(
100✔
77
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
100✔
78
                ),
100✔
79
                HtlcMinimum: MilliSatoshi(
100✔
80
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
100✔
81
                ),
100✔
82
                MinAcceptDepth: uint32(
100✔
83
                        rapid.IntRange(1, 10).Draw(t, "minAcceptDepth"),
100✔
84
                ),
100✔
85
                CsvDelay: uint16(
100✔
86
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
100✔
87
                ),
100✔
88
                MaxAcceptedHTLCs: uint16(
100✔
89
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
100✔
90
                ),
100✔
91
                FundingKey:            RandPubKey(t),
100✔
92
                RevocationPoint:       RandPubKey(t),
100✔
93
                PaymentPoint:          RandPubKey(t),
100✔
94
                DelayedPaymentPoint:   RandPubKey(t),
100✔
95
                HtlcPoint:             RandPubKey(t),
100✔
96
                FirstCommitmentPoint:  RandPubKey(t),
100✔
97
                UpfrontShutdownScript: RandDeliveryAddress(t),
100✔
98
                ChannelType:           channelType,
100✔
99
                LeaseExpiry:           leaseExpiry,
100✔
100
                LocalNonce:            localNonce,
100✔
101
                ExtraData:             RandExtraOpaqueData(t, nil),
100✔
102
        }
100✔
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 {
100✔
114
        return &AnnounceSignatures1{
100✔
115
                ChannelID:        RandChannelID(t),
100✔
116
                ShortChannelID:   RandShortChannelID(t),
100✔
117
                NodeSignature:    RandSignature(t),
100✔
118
                BitcoinSignature: RandSignature(t),
100✔
119
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
100✔
120
        }
100✔
121
}
100✔
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 {
100✔
132
        return &AnnounceSignatures2{
100✔
133
                ChannelID:        RandChannelID(t),
100✔
134
                ShortChannelID:   RandShortChannelID(t),
100✔
135
                PartialSignature: *RandPartialSig(t),
100✔
136
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
100✔
137
        }
100✔
138
}
100✔
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 {
100✔
149
        // Generate Node IDs and Bitcoin keys (compressed public keys)
100✔
150
        node1PubKey := RandPubKey(t)
100✔
151
        node2PubKey := RandPubKey(t)
100✔
152
        bitcoin1PubKey := RandPubKey(t)
100✔
153
        bitcoin2PubKey := RandPubKey(t)
100✔
154

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

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

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

100✔
173
        return &ChannelAnnouncement1{
100✔
174
                NodeSig1:        RandSignature(t),
100✔
175
                NodeSig2:        RandSignature(t),
100✔
176
                BitcoinSig1:     RandSignature(t),
100✔
177
                BitcoinSig2:     RandSignature(t),
100✔
178
                Features:        RandFeatureVector(t),
100✔
179
                ChainHash:       hash,
100✔
180
                ShortChannelID:  RandShortChannelID(t),
100✔
181
                NodeID1:         nodeID1,
100✔
182
                NodeID2:         nodeID2,
100✔
183
                BitcoinKey1:     bitcoinKey1,
100✔
184
                BitcoinKey2:     bitcoinKey2,
100✔
185
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
186
        }
100✔
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 {
100✔
198
        features := RandFeatureVector(t)
100✔
199
        shortChanID := RandShortChannelID(t)
100✔
200
        capacity := uint64(rapid.IntRange(1, 16777215).Draw(t, "capacity"))
100✔
201

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

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

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

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

100✔
238
        msg.Signature.ForceSchnorr()
100✔
239

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

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

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

272
        return msg
100✔
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 {
100✔
284
        msg := &ChannelReady{
100✔
285
                ChanID:                 RandChannelID(t),
100✔
286
                NextPerCommitmentPoint: RandPubKey(t),
100✔
287
                ExtraData:              RandExtraOpaqueData(t, nil),
100✔
288
        }
100✔
289

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

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

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

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

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

323
        return msg
100✔
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 {
100✔
335
        msg := &ChannelReestablish{
100✔
336
                ChanID: RandChannelID(t),
100✔
337
                NextLocalCommitHeight: rapid.Uint64().Draw(
100✔
338
                        t, "nextLocalCommitHeight",
100✔
339
                ),
100✔
340
                RemoteCommitTailHeight: rapid.Uint64().Draw(
100✔
341
                        t, "remoteCommitTailHeight",
100✔
342
                ),
100✔
343
                LastRemoteCommitSecret:    RandPaymentPreimage(t),
100✔
344
                LocalUnrevokedCommitPoint: RandPubKey(t),
100✔
345
                ExtraData:                 RandExtraOpaqueData(t, nil),
100✔
346
        }
100✔
347

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

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

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

362
        return msg
100✔
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 {
100✔
374
        // Generate random message flags
100✔
375
        // Randomly decide whether to include max HTLC field
100✔
376
        includeMaxHtlc := rapid.Bool().Draw(t, "includeMaxHtlc")
100✔
377
        var msgFlags ChanUpdateMsgFlags
100✔
378
        if includeMaxHtlc {
154✔
379
                msgFlags |= ChanUpdateRequiredMaxHtlc
54✔
380
        }
54✔
381

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

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

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

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

100✔
404
        // If max HTLC flag is not set, we need to zero the value
100✔
405
        if !includeMaxHtlc {
146✔
406
                maxHtlc = 0
46✔
407
        }
46✔
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 (
100✔
414
                customRecords, _ = RandCustomRecords(t, nil, false)
100✔
415
                inboundFee       tlv.OptionalRecordT[tlv.TlvType55555, Fee]
100✔
416
        )
100✔
417
        includeInboundFee := rapid.Bool().Draw(t, "includeInboundFee")
100✔
418
        if includeInboundFee {
148✔
419
                if customRecords == nil {
61✔
420
                        customRecords = make(CustomRecords)
13✔
421
                }
13✔
422

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

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

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

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

100✔
448
        return &ChannelUpdate1{
100✔
449
                Signature:      RandSignature(t),
100✔
450
                ChainHash:      hash,
100✔
451
                ShortChannelID: RandShortChannelID(t),
100✔
452
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
453
                        t, "timestamp"),
100✔
454
                ),
100✔
455
                MessageFlags: msgFlags,
100✔
456
                ChannelFlags: chanFlags,
100✔
457
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
100✔
458
                        t, "timelockDelta"),
100✔
459
                ),
100✔
460
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
100✔
461
                        t, "htlcMinimum"),
100✔
462
                ),
100✔
463
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
464
                        t, "baseFee"),
100✔
465
                ),
100✔
466
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
467
                        t, "feeRate"),
100✔
468
                ),
100✔
469
                HtlcMaximumMsat: maxHtlc,
100✔
470
                InboundFee:      inboundFee,
100✔
471
                ExtraOpaqueData: extraBytes,
100✔
472
        }
100✔
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 {
100✔
484
        shortChanID := RandShortChannelID(t)
100✔
485
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
100✔
486

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

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

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

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

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

100✔
546
        msg.Signature.ForceSchnorr()
100✔
547

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

554
        return msg
100✔
555
}
556

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

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

100✔
579
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
100✔
580
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
100✔
581
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
100✔
582

100✔
583
        // Ensure at least one signature is present.
100✔
584
        if !includeCloserNoClosee && !includeNoCloserClosee &&
100✔
585
                !includeCloserAndClosee {
107✔
586

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

599
        if includeCloserNoClosee {
155✔
600
                sig := RandSignature(t)
55✔
601
                msg.CloserNoClosee = tlv.SomeRecordT(
55✔
602
                        tlv.NewRecordT[tlv.TlvType1](sig),
55✔
603
                )
55✔
604
        }
55✔
605

606
        if includeNoCloserClosee {
153✔
607
                sig := RandSignature(t)
53✔
608
                msg.NoCloserClosee = tlv.SomeRecordT(
53✔
609
                        tlv.NewRecordT[tlv.TlvType2](sig),
53✔
610
                )
53✔
611
        }
53✔
612

613
        if includeCloserAndClosee {
156✔
614
                sig := RandSignature(t)
56✔
615
                msg.CloserAndClosee = tlv.SomeRecordT(
56✔
616
                        tlv.NewRecordT[tlv.TlvType3](sig),
56✔
617
                )
56✔
618
        }
56✔
619

620
        return msg
100✔
621
}
622

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

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

101✔
639
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
101✔
640
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
101✔
641
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
101✔
642

101✔
643
        // Ensure at least one signature is present.
101✔
644
        if !includeCloserNoClosee && !includeNoCloserClosee &&
101✔
645
                !includeCloserAndClosee {
116✔
646

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

659
        if includeCloserNoClosee {
152✔
660
                sig := RandSignature(t)
51✔
661
                msg.CloserNoClosee = tlv.SomeRecordT(
51✔
662
                        tlv.NewRecordT[tlv.TlvType1](sig),
51✔
663
                )
51✔
664
        }
51✔
665

666
        if includeNoCloserClosee {
154✔
667
                sig := RandSignature(t)
53✔
668
                msg.NoCloserClosee = tlv.SomeRecordT(
53✔
669
                        tlv.NewRecordT[tlv.TlvType2](sig),
53✔
670
                )
53✔
671
        }
53✔
672

673
        if includeCloserAndClosee {
149✔
674
                sig := RandSignature(t)
48✔
675
                msg.CloserAndClosee = tlv.SomeRecordT(
48✔
676
                        tlv.NewRecordT[tlv.TlvType3](sig),
48✔
677
                )
48✔
678
        }
48✔
679

680
        return msg
101✔
681
}
682

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

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

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

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

55✔
712
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
55✔
713
                msg.Signature = Sig{}
55✔
714
        } else {
101✔
715
                msg.Signature = RandSignature(t)
46✔
716
        }
46✔
717

718
        return msg
101✔
719
}
720

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

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

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

743
        if len(htlcSigs) > 0 {
186✔
744
                sig.HtlcSigs = htlcSigs
86✔
745
        }
86✔
746

747
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
748
        if includePartialSig {
147✔
749
                sigWithNonce := RandPartialSigWithNonce(t)
47✔
750
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
47✔
751
        }
47✔
752

753
        return sig
100✔
754
}
755

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

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

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

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

781
        return msg
10✔
782
}
783

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

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

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

804
        msg.ExtraData = RandUnknownRecords(t, 14)
100✔
805

100✔
806
        return msg
100✔
807
}
808

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

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

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

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

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

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

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

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

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

875
        msg.ExtraData = RandUnknownRecords(t, 12)
101✔
876

101✔
877
        return msg
101✔
878
}
879

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

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

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

901
        var extraData ExtraOpaqueData
100✔
902
        randData := RandExtraOpaqueData(t, nil)
100✔
903
        if len(randData) > 0 {
178✔
904
                extraData = randData
78✔
905
        }
78✔
906

907
        return &DynReject{
100✔
908
                ChanID:           RandChannelID(t),
100✔
909
                UpdateRejections: *featureVec,
100✔
910
                ExtraData:        extraData,
100✔
911
        }
100✔
912
}
913

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

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

100✔
925
        da := &DynAck{
100✔
926
                ChanID: chanID,
100✔
927
        }
100✔
928

100✔
929
        dp := &DynPropose{
100✔
930
                ChanID: chanID,
100✔
931
        }
100✔
932

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

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

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

960
        if includeChannelReserve {
145✔
961
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
45✔
962
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
45✔
963
                rec.Val = tlv.NewBigSizeT(val)
45✔
964
                dp.ChannelReserve = tlv.SomeRecordT(rec)
45✔
965
        }
45✔
966

967
        if includeCsvDelay {
149✔
968
                csvDelay := dp.CsvDelay.Zero()
49✔
969
                val := rapid.Uint16().Draw(t, "csvDelay")
49✔
970
                csvDelay.Val = val
49✔
971
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
49✔
972
        }
49✔
973

974
        if includeMaxAcceptedHTLCs {
136✔
975
                maxHtlcs := dp.MaxAcceptedHTLCs.Zero()
36✔
976
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
36✔
977
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
36✔
978
        }
36✔
979

980
        if includeChannelType {
147✔
981
                chanType := dp.ChannelType.Zero()
47✔
982
                chanType.Val = *RandChannelType(t)
47✔
983
                dp.ChannelType = tlv.SomeRecordT(chanType)
47✔
984
        }
47✔
985

986
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
987
        if includeLocalNonce {
147✔
988
                nonce := RandMusig2Nonce(t)
47✔
989
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
47✔
990
                da.LocalNonce = tlv.SomeRecordT(rec)
47✔
991
        }
47✔
992

993
        msg := &DynCommit{
100✔
994
                DynPropose: *dp,
100✔
995
                DynAck:     *da,
100✔
996
        }
100✔
997

100✔
998
        msg.ExtraData = RandUnknownRecords(t, 14)
100✔
999

100✔
1000
        return msg
100✔
1001
}
1002

1003
// A compile time check to ensure FundingCreated implements the TestMessage
1004
// interface.
1005
var _ TestMessage = (*FundingCreated)(nil)
1006

1007
// RandTestMessage populates the message with random data suitable for testing.
1008
// It uses the rapid testing framework to generate random values.
1009
//
1010
// This is part of the TestMessage interface.
1011
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
100✔
1012
        var pendingChanID [32]byte
100✔
1013
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1014
                t, "pendingChanID",
100✔
1015
        )
100✔
1016
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1017

100✔
1018
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
1019
        var partialSig OptPartialSigWithNonceTLV
100✔
1020
        var commitSig Sig
100✔
1021

100✔
1022
        if includePartialSig {
144✔
1023
                sigWithNonce := RandPartialSigWithNonce(t)
44✔
1024
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
44✔
1025

44✔
1026
                // When using partial sig, CommitSig should be empty/blank.
44✔
1027
                commitSig = Sig{}
44✔
1028
        } else {
100✔
1029
                commitSig = RandSignature(t)
56✔
1030
        }
56✔
1031

1032
        return &FundingCreated{
100✔
1033
                PendingChannelID: pendingChanID,
100✔
1034
                FundingPoint:     RandOutPoint(t),
100✔
1035
                CommitSig:        commitSig,
100✔
1036
                PartialSig:       partialSig,
100✔
1037
                ExtraData:        RandExtraOpaqueData(t, nil),
100✔
1038
        }
100✔
1039
}
1040

1041
// A compile time check to ensure FundingSigned implements the
1042
// lnwire.TestMessage interface.
1043
var _ TestMessage = (*FundingSigned)(nil)
1044

1045
// RandTestMessage populates the message with random data suitable for testing.
1046
// It uses the rapid testing framework to generate random values.
1047
//
1048
// This is part of the TestMessage interface.
1049
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
100✔
1050
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
1051

100✔
1052
        msg := &FundingSigned{
100✔
1053
                ChanID:    RandChannelID(t),
100✔
1054
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1055
        }
100✔
1056

100✔
1057
        if usePartialSig {
157✔
1058
                sigWithNonce := RandPartialSigWithNonce(t)
57✔
1059
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
57✔
1060

57✔
1061
                msg.CommitSig = Sig{}
57✔
1062
        } else {
100✔
1063
                msg.CommitSig = RandSignature(t)
43✔
1064
        }
43✔
1065

1066
        return msg
100✔
1067
}
1068

1069
// A compile time check to ensure GossipTimestampRange implements the
1070
// lnwire.TestMessage interface.
1071
var _ TestMessage = (*GossipTimestampRange)(nil)
1072

1073
// RandTestMessage populates the message with random data suitable for testing.
1074
// It uses the rapid testing framework to generate random values.
1075
//
1076
// This is part of the TestMessage interface.
1077
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
100✔
1078
        var chainHash chainhash.Hash
100✔
1079
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1080
        copy(chainHash[:], hashBytes)
100✔
1081

100✔
1082
        msg := &GossipTimestampRange{
100✔
1083
                ChainHash:      chainHash,
100✔
1084
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
100✔
1085
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
100✔
1086
                ExtraData:      RandExtraOpaqueData(t, nil),
100✔
1087
        }
100✔
1088

100✔
1089
        includeFirstBlockHeight := rapid.Bool().Draw(
100✔
1090
                t, "includeFirstBlockHeight",
100✔
1091
        )
100✔
1092
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
100✔
1093

100✔
1094
        if includeFirstBlockHeight {
148✔
1095
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
48✔
1096
                msg.FirstBlockHeight = tlv.SomeRecordT(
48✔
1097
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
48✔
1098
                )
48✔
1099
        }
48✔
1100

1101
        if includeBlockRange {
147✔
1102
                blockRange := rapid.Uint32().Draw(t, "blockRange")
47✔
1103
                msg.BlockRange = tlv.SomeRecordT(
47✔
1104
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
47✔
1105
                )
47✔
1106
        }
47✔
1107

1108
        return msg
100✔
1109
}
1110

1111
// RandTestMessage populates the message with random data suitable for testing.
1112
// It uses the rapid testing framework to generate random values.
1113
//
1114
// This is part of the TestMessage interface.
1115
func (msg *Init) RandTestMessage(t *rapid.T) Message {
100✔
1116
        global := NewRawFeatureVector()
100✔
1117
        local := NewRawFeatureVector()
100✔
1118

100✔
1119
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
100✔
1120
        for i := 0; i < numGlobalFeatures; i++ {
868✔
1121
                bit := FeatureBit(
768✔
1122
                        rapid.IntRange(0, 100).Draw(
768✔
1123
                                t, fmt.Sprintf("globalFeatureBit%d", i),
768✔
1124
                        ),
768✔
1125
                )
768✔
1126
                global.Set(bit)
768✔
1127
        }
768✔
1128

1129
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
100✔
1130
        for i := 0; i < numLocalFeatures; i++ {
772✔
1131
                bit := FeatureBit(
672✔
1132
                        rapid.IntRange(0, 100).Draw(
672✔
1133
                                t, fmt.Sprintf("localFeatureBit%d", i),
672✔
1134
                        ),
672✔
1135
                )
672✔
1136
                local.Set(bit)
672✔
1137
        }
672✔
1138

1139
        return NewInitMessage(global, local)
100✔
1140
}
1141

1142
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1143
// interface.
1144
var _ TestMessage = (*KickoffSig)(nil)
1145

1146
// RandTestMessage populates the message with random data suitable for testing.
1147
// It uses the rapid testing framework to generate random values.
1148
//
1149
// This is part of the TestMessage interface.
1150
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
100✔
1151
        return &KickoffSig{
100✔
1152
                ChanID:    RandChannelID(t),
100✔
1153
                Signature: RandSignature(t),
100✔
1154
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1155
        }
100✔
1156
}
100✔
1157

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

1162
// RandTestMessage populates the message with random data suitable for testing.
1163
// It uses the rapid testing framework to generate random values.
1164
//
1165
// This is part of the TestMessage interface.
1166
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
100✔
1167
        // Generate random compressed public key for node ID
100✔
1168
        pubKey := RandPubKey(t)
100✔
1169
        var nodeID [33]byte
100✔
1170
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1171

100✔
1172
        // Generate random RGB color
100✔
1173
        rgbColor := color.RGBA{
100✔
1174
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
100✔
1175
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
100✔
1176
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
100✔
1177
        }
100✔
1178

100✔
1179
        return &NodeAnnouncement{
100✔
1180
                Signature: RandSignature(t),
100✔
1181
                Features:  RandFeatureVector(t),
100✔
1182
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
1183
                        t, "timestamp"),
100✔
1184
                ),
100✔
1185
                NodeID:          nodeID,
100✔
1186
                RGBColor:        rgbColor,
100✔
1187
                Alias:           RandNodeAlias(t),
100✔
1188
                Addresses:       RandNetAddrs(t),
100✔
1189
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
1190
        }
100✔
1191
}
100✔
1192

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

1197
// RandTestMessage populates the message with random data suitable for testing.
1198
// It uses the rapid testing framework to generate random values.
1199
//
1200
// This is part of the TestMessage interface.
1201
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
100✔
1202
        chainHash := RandChainHash(t)
100✔
1203
        var hash chainhash.Hash
100✔
1204
        copy(hash[:], chainHash[:])
100✔
1205

100✔
1206
        var pendingChanID [32]byte
100✔
1207
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1208
                t, "pendingChanID",
100✔
1209
        )
100✔
1210
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1211

100✔
1212
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
1213
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
100✔
1214
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
1215

100✔
1216
        var channelFlags FundingFlag
100✔
1217
        if rapid.Bool().Draw(t, "announceChannel") {
152✔
1218
                channelFlags |= FFAnnounceChannel
52✔
1219
        }
52✔
1220

1221
        var localNonce OptMusig2NonceTLV
100✔
1222
        if includeLocalNonce {
152✔
1223
                nonce := RandMusig2Nonce(t)
52✔
1224
                localNonce = tlv.SomeRecordT(
52✔
1225
                        tlv.NewRecordT[NonceRecordTypeT](nonce),
52✔
1226
                )
52✔
1227
        }
52✔
1228

1229
        var channelType *ChannelType
100✔
1230
        if includeChannelType {
145✔
1231
                channelType = RandChannelType(t)
45✔
1232
        }
45✔
1233

1234
        var leaseExpiry *LeaseExpiry
100✔
1235
        if includeLeaseExpiry {
153✔
1236
                leaseExpiry = RandLeaseExpiry(t)
53✔
1237
        }
53✔
1238

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

1286
// A compile time check to ensure Ping implements the lnwire.TestMessage
1287
// interface.
1288
var _ TestMessage = (*Ping)(nil)
1289

1290
// RandTestMessage populates the message with random data suitable for testing.
1291
// It uses the rapid testing framework to generate random values.
1292
//
1293
// This is part of the TestMessage interface.
1294
func (p *Ping) RandTestMessage(t *rapid.T) Message {
100✔
1295
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
100✔
1296
                t, "numPongBytes"),
100✔
1297
        )
100✔
1298

100✔
1299
        // Generate padding bytes (but keeping within allowed message size)
100✔
1300
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
100✔
1301
        maxPaddingLen := MaxMsgBody - 4
100✔
1302
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
100✔
1303
                t, "paddingLen",
100✔
1304
        )
100✔
1305
        padding := make(PingPayload, paddingLen)
100✔
1306

100✔
1307
        // Fill padding with random bytes
100✔
1308
        for i := 0; i < paddingLen; i++ {
483,782✔
1309
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
483,682✔
1310
                        t, fmt.Sprintf("paddingByte%d", i)),
483,682✔
1311
                )
483,682✔
1312
        }
483,682✔
1313

1314
        return &Ping{
100✔
1315
                NumPongBytes: numPongBytes,
100✔
1316
                PaddingBytes: padding,
100✔
1317
        }
100✔
1318
}
1319

1320
// A compile time check to ensure Pong implements the lnwire.TestMessage
1321
// interface.
1322
var _ TestMessage = (*Pong)(nil)
1323

1324
// RandTestMessage populates the message with random data suitable for testing.
1325
// It uses the rapid testing framework to generate random values.
1326
//
1327
// This is part of the TestMessage interface.
1328
func (p *Pong) RandTestMessage(t *rapid.T) Message {
100✔
1329
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
100✔
1330
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
100✔
1331
                t, "pongPayload",
100✔
1332
        )
100✔
1333

100✔
1334
        return &Pong{
100✔
1335
                PongBytes: payload,
100✔
1336
        }
100✔
1337
}
100✔
1338

1339
// A compile time check to ensure QueryChannelRange implements the
1340
// lnwire.TestMessage interface.
1341
var _ TestMessage = (*QueryChannelRange)(nil)
1342

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

100✔
1358
        // Generate chain hash
100✔
1359
        chainHash := RandChainHash(t)
100✔
1360
        var chainHashObj chainhash.Hash
100✔
1361
        copy(chainHashObj[:], chainHash[:])
100✔
1362
        msg.ChainHash = chainHashObj
100✔
1363

100✔
1364
        // Randomly include QueryOptions
100✔
1365
        if rapid.Bool().Draw(t, "includeQueryOptions") {
155✔
1366
                queryOptions := &QueryOptions{}
55✔
1367
                *queryOptions = QueryOptions(*RandFeatureVector(t))
55✔
1368
                msg.QueryOptions = queryOptions
55✔
1369
        }
55✔
1370

1371
        return msg
100✔
1372
}
1373

1374
// A compile time check to ensure QueryShortChanIDs implements the
1375
// lnwire.TestMessage interface.
1376
var _ TestMessage = (*QueryShortChanIDs)(nil)
1377

1378
// RandTestMessage populates the message with random data suitable for testing.
1379
// It uses the rapid testing framework to generate random values.
1380
//
1381
// This is part of the TestMessage interface.
1382
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
100✔
1383
        var chainHash chainhash.Hash
100✔
1384
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1385
        copy(chainHash[:], hashBytes)
100✔
1386

100✔
1387
        encodingType := EncodingSortedPlain
100✔
1388
        if rapid.Bool().Draw(t, "useZlibEncoding") {
153✔
1389
                encodingType = EncodingSortedZlib
53✔
1390
        }
53✔
1391

1392
        msg := &QueryShortChanIDs{
100✔
1393
                ChainHash:    chainHash,
100✔
1394
                EncodingType: encodingType,
100✔
1395
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1396
                noSort:       false,
100✔
1397
        }
100✔
1398

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

100✔
1401
        // Generate sorted short channel IDs.
100✔
1402
        shortChanIDs := make([]ShortChannelID, numIDs)
100✔
1403
        for i := 0; i < numIDs; i++ {
928✔
1404
                shortChanIDs[i] = RandShortChannelID(t)
828✔
1405

828✔
1406
                // Ensure they're properly sorted.
828✔
1407
                if i > 0 && shortChanIDs[i].ToUint64() <=
828✔
1408
                        shortChanIDs[i-1].ToUint64() {
1,401✔
1409

573✔
1410
                        // Ensure this ID is larger than the previous one.
573✔
1411
                        shortChanIDs[i] = NewShortChanIDFromInt(
573✔
1412
                                shortChanIDs[i-1].ToUint64() + 1,
573✔
1413
                        )
573✔
1414
                }
573✔
1415
        }
1416

1417
        msg.ShortChanIDs = shortChanIDs
100✔
1418

100✔
1419
        return msg
100✔
1420
}
1421

1422
// A compile time check to ensure ReplyChannelRange implements the
1423
// lnwire.TestMessage interface.
1424
var _ TestMessage = (*ReplyChannelRange)(nil)
1425

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

100✔
1445
        msg.ChainHash = RandChainHash(t)
100✔
1446

100✔
1447
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
100✔
1448
        if numShortChanIDs == 0 {
113✔
1449
                return msg
13✔
1450
        }
13✔
1451

1452
        scidSet := fn.NewSet[ShortChannelID]()
87✔
1453
        scids := make([]ShortChannelID, numShortChanIDs)
87✔
1454
        for i := 0; i < numShortChanIDs; i++ {
859✔
1455
                scid := RandShortChannelID(t)
772✔
1456
                for scidSet.Contains(scid) {
872✔
1457
                        scid = RandShortChannelID(t)
100✔
1458
                }
100✔
1459

1460
                scids[i] = scid
772✔
1461

772✔
1462
                scidSet.Add(scid)
772✔
1463
        }
1464

1465
        // Make sure there're no duplicates.
1466
        msg.ShortChanIDs = scids
87✔
1467

87✔
1468
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
127✔
1469
                msg.Timestamps = make(Timestamps, numShortChanIDs)
40✔
1470
                for i := 0; i < numShortChanIDs; i++ {
393✔
1471
                        msg.Timestamps[i] = ChanUpdateTimestamps{
353✔
1472
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
353✔
1473
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
353✔
1474
                        }
353✔
1475
                }
353✔
1476
        }
1477

1478
        return msg
87✔
1479
}
1480

1481
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1482
// lnwire.TestMessage interface.
1483
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1484

1485
// RandTestMessage populates the message with random data suitable for testing.
1486
// It uses the rapid testing framework to generate random values.
1487
//
1488
// This is part of the TestMessage interface.
1489
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
100✔
1490
        var chainHash chainhash.Hash
100✔
1491
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1492
        copy(chainHash[:], hashBytes)
100✔
1493

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

100✔
1496
        return &ReplyShortChanIDsEnd{
100✔
1497
                ChainHash: chainHash,
100✔
1498
                Complete:  complete,
100✔
1499
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1500
        }
100✔
1501
}
100✔
1502

1503
// RandTestMessage returns a RevokeAndAck message populated with random data.
1504
//
1505
// This is part of the TestMessage interface.
1506
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
100✔
1507
        msg := NewRevokeAndAck()
100✔
1508

100✔
1509
        var chanID ChannelID
100✔
1510
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
100✔
1511
        copy(chanID[:], bytes)
100✔
1512
        msg.ChanID = chanID
100✔
1513

100✔
1514
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
100✔
1515
        copy(msg.Revocation[:], revBytes)
100✔
1516

100✔
1517
        msg.NextRevocationKey = RandPubKey(t)
100✔
1518

100✔
1519
        if rapid.Bool().Draw(t, "includeLocalNonce") {
141✔
1520
                var nonce Musig2Nonce
41✔
1521
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
41✔
1522
                        t, "nonce",
41✔
1523
                )
41✔
1524
                copy(nonce[:], nonceBytes)
41✔
1525

41✔
1526
                msg.LocalNonce = tlv.SomeRecordT(
41✔
1527
                        tlv.NewRecordT[NonceRecordTypeT](nonce),
41✔
1528
                )
41✔
1529
        }
41✔
1530

1531
        return msg
100✔
1532
}
1533

1534
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1535
// interface.
1536
var _ TestMessage = (*Shutdown)(nil)
1537

1538
// RandTestMessage populates the message with random data suitable for testing.
1539
// It uses the rapid testing framework to generate random values.
1540
//
1541
// This is part of the TestMessage interface.
1542
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
100✔
1543
        // Generate random delivery address
100✔
1544
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
100✔
1545
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
100✔
1546

100✔
1547
        // Generate random address length based on type
100✔
1548
        var addrLen int
100✔
1549
        switch addrType {
100✔
1550
        // P2PKH
1551
        case 0:
24✔
1552
                addrLen = 25
24✔
1553
        // P2SH
1554
        case 1:
25✔
1555
                addrLen = 23
25✔
1556
        // P2WPKH
1557
        case 2:
11✔
1558
                addrLen = 22
11✔
1559
        // P2WSH
1560
        case 3:
19✔
1561
                addrLen = 34
19✔
1562
        // P2TR
1563
        case 4:
21✔
1564
                addrLen = 34
21✔
1565
        }
1566

1567
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
100✔
1568
                t, "address",
100✔
1569
        )
100✔
1570

100✔
1571
        // Randomly decide whether to include a shutdown nonce
100✔
1572
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
100✔
1573
        var shutdownNonce ShutdownNonceTLV
100✔
1574

100✔
1575
        if includeNonce {
145✔
1576
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
45✔
1577
        }
45✔
1578

1579
        cr, _ := RandCustomRecords(t, nil, true)
100✔
1580

100✔
1581
        return &Shutdown{
100✔
1582
                ChannelID:     RandChannelID(t),
100✔
1583
                Address:       addr,
100✔
1584
                ShutdownNonce: shutdownNonce,
100✔
1585
                CustomRecords: cr,
100✔
1586
        }
100✔
1587
}
1588

1589
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1590
// interface.
1591
var _ TestMessage = (*Stfu)(nil)
1592

1593
// RandTestMessage populates the message with random data suitable for testing.
1594
// It uses the rapid testing framework to generate random values.
1595
//
1596
// This is part of the TestMessage interface.
1597
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
102✔
1598
        m := &Stfu{
102✔
1599
                ChanID:    RandChannelID(t),
102✔
1600
                Initiator: rapid.Bool().Draw(t, "initiator"),
102✔
1601
        }
102✔
1602

102✔
1603
        extraData := RandExtraOpaqueData(t, nil)
102✔
1604
        if len(extraData) > 0 {
182✔
1605
                m.ExtraData = extraData
80✔
1606
        }
80✔
1607

1608
        return m
102✔
1609
}
1610

1611
// A compile time check to ensure UpdateAddHTLC implements the
1612
// lnwire.TestMessage interface.
1613
var _ TestMessage = (*UpdateAddHTLC)(nil)
1614

1615
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1616
//
1617
// This is part of the TestMessage interface.
1618
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1619
        msg := &UpdateAddHTLC{
100✔
1620
                ChanID: RandChannelID(t),
100✔
1621
                ID:     rapid.Uint64().Draw(t, "id"),
100✔
1622
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
100✔
1623
                Expiry: rapid.Uint32().Draw(t, "expiry"),
100✔
1624
        }
100✔
1625

100✔
1626
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
100✔
1627
        copy(msg.PaymentHash[:], hashBytes)
100✔
1628

100✔
1629
        onionBytes := rapid.SliceOfN(
100✔
1630
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
100✔
1631
        ).Draw(t, "onionBlob")
100✔
1632
        copy(msg.OnionBlob[:], onionBytes)
100✔
1633

100✔
1634
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
100✔
1635
        if numRecords > 0 {
180✔
1636
                msg.CustomRecords, _ = RandCustomRecords(t, nil, true)
80✔
1637
        }
80✔
1638

1639
        // 50/50 chance to add a blinding point
1640
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
155✔
1641
                pubKey := RandPubKey(t)
55✔
1642

55✔
1643
                msg.BlindingPoint = tlv.SomeRecordT(
55✔
1644
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
55✔
1645
                )
55✔
1646
        }
55✔
1647

1648
        return msg
100✔
1649
}
1650

1651
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1652
// interface.
1653
var _ TestMessage = (*UpdateFailHTLC)(nil)
1654

1655
// RandTestMessage populates the message with random data suitable for testing.
1656
// It uses the rapid testing framework to generate random values.
1657
//
1658
// This is part of the TestMessage interface.
1659
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1660
        return &UpdateFailHTLC{
100✔
1661
                ChanID:    RandChannelID(t),
100✔
1662
                ID:        rapid.Uint64().Draw(t, "id"),
100✔
1663
                Reason:    RandOpaqueReason(t),
100✔
1664
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1665
        }
100✔
1666
}
100✔
1667

1668
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1669
// TestMessage interface.
1670
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1671

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

1686
// A compile time check to ensure UpdateFee implements the TestMessage
1687
// interface.
1688
var _ TestMessage = (*UpdateFee)(nil)
1689

1690
// RandTestMessage populates the message with random data suitable for testing.
1691
// It uses the rapid testing framework to generate random values.
1692
//
1693
// This is part of the TestMessage interface.
1694
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
100✔
1695
        return &UpdateFee{
100✔
1696
                ChanID:    RandChannelID(t),
100✔
1697
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
100✔
1698
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1699
        }
100✔
1700
}
100✔
1701

1702
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1703
// interface.
1704
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1705

1706
// RandTestMessage populates the message with random data suitable for testing.
1707
// It uses the rapid testing framework to generate random values.
1708
//
1709
// This is part of the TestMessage interface.
1710
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1711
        msg := &UpdateFulfillHTLC{
100✔
1712
                ChanID:          RandChannelID(t),
100✔
1713
                ID:              rapid.Uint64().Draw(t, "id"),
100✔
1714
                PaymentPreimage: RandPaymentPreimage(t),
100✔
1715
        }
100✔
1716

100✔
1717
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
100✔
1718
        msg.CustomRecords = cr
100✔
1719

100✔
1720
        randData := RandExtraOpaqueData(t, ignoreRecords)
100✔
1721
        if len(randData) > 0 {
180✔
1722
                msg.ExtraData = randData
80✔
1723
        }
80✔
1724

1725
        return msg
100✔
1726
}
1727

1728
// A compile time check to ensure Warning implements the lnwire.TestMessage
1729
// interface.
1730
var _ TestMessage = (*Warning)(nil)
1731

1732
// RandTestMessage populates the message with random data suitable for testing.
1733
// It uses the rapid testing framework to generate random values.
1734
//
1735
// This is part of the TestMessage interface.
1736
func (c *Warning) RandTestMessage(t *rapid.T) Message {
112✔
1737
        msg := &Warning{
112✔
1738
                ChanID: RandChannelID(t),
112✔
1739
        }
112✔
1740

112✔
1741
        useASCII := rapid.Bool().Draw(t, "useASCII")
112✔
1742
        if useASCII {
168✔
1743
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
56✔
1744
                data := make([]byte, length)
56✔
1745
                for i := 0; i < length; i++ {
1,687✔
1746
                        data[i] = byte(
1,631✔
1747
                                rapid.IntRange(32, 126).Draw(
1,631✔
1748
                                        t, fmt.Sprintf("warningDataByte-%d", i),
1,631✔
1749
                                ),
1,631✔
1750
                        )
1,631✔
1751
                }
1,631✔
1752
                msg.Data = data
56✔
1753
        } else {
56✔
1754
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
56✔
1755
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
56✔
1756
                        t, "warningData",
56✔
1757
                )
56✔
1758
        }
56✔
1759

1760
        return msg
112✔
1761
}
1762

1763
// A compile time check to ensure Error implements the lnwire.TestMessage
1764
// interface.
1765
var _ TestMessage = (*Error)(nil)
1766

1767
// RandTestMessage populates the message with random data suitable for testing.
1768
// It uses the rapid testing framework to generate random values.
1769
//
1770
// This is part of the TestMessage interface.
1771
func (c *Error) RandTestMessage(t *rapid.T) Message {
100✔
1772
        msg := &Error{
100✔
1773
                ChanID: RandChannelID(t),
100✔
1774
        }
100✔
1775

100✔
1776
        useASCII := rapid.Bool().Draw(t, "useASCII")
100✔
1777
        if useASCII {
142✔
1778
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
42✔
1779
                data := make([]byte, length)
42✔
1780
                for i := 0; i < length; i++ {
1,651✔
1781
                        data[i] = byte(
1,609✔
1782
                                rapid.IntRange(32, 126).Draw(
1,609✔
1783
                                        t, fmt.Sprintf("errorDataByte-%d", i),
1,609✔
1784
                                ),
1,609✔
1785
                        )
1,609✔
1786
                }
1,609✔
1787
                msg.Data = data
42✔
1788
        } else {
58✔
1789
                // Generate random binary data
58✔
1790
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
58✔
1791
                msg.Data = rapid.SliceOfN(
58✔
1792
                        rapid.Byte(), length, length,
58✔
1793
                ).Draw(t, "errorData")
58✔
1794
        }
58✔
1795

1796
        return msg
100✔
1797
}
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