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

lightningnetwork / lnd / 15951470896

29 Jun 2025 04:23AM UTC coverage: 67.594% (-0.01%) from 67.606%
15951470896

Pull #9751

github

web-flow
Merge 599d9b051 into 6290edf14
Pull Request #9751: multi: update Go to 1.23.10 and update some packages

135088 of 199851 relevant lines covered (67.59%)

21909.44 hits per line

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

99.92
/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 {
144✔
55
                leaseExpiry = RandLeaseExpiry(t)
44✔
56
        }
44✔
57

58
        var localNonce OptMusig2NonceTLV
100✔
59
        if includeLocalNonce {
153✔
60
                nonce := RandMusig2Nonce(t)
53✔
61
                localNonce = tlv.SomeRecordT(
53✔
62
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
53✔
63
                )
53✔
64
        }
53✔
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 {
150✔
165
                nodeID1, nodeID2 = nodeID2, nodeID1
50✔
166
        }
50✔
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 {
151✔
208
                nodeID1, nodeID2 = nodeID2, nodeID1
51✔
209
        }
51✔
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.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
100✔
218
                        chainHashObj,
100✔
219
                ),
100✔
220
                Features: tlv.NewRecordT[tlv.TlvType2, RawFeatureVector](
100✔
221
                        *features,
100✔
222
                ),
100✔
223
                ShortChannelID: tlv.NewRecordT[tlv.TlvType4, ShortChannelID](
100✔
224
                        shortChanID,
100✔
225
                ),
100✔
226
                Capacity: tlv.NewPrimitiveRecord[tlv.TlvType6, uint64](
100✔
227
                        capacity,
100✔
228
                ),
100✔
229
                NodeID1: tlv.NewPrimitiveRecord[tlv.TlvType8, [33]byte](
100✔
230
                        nodeID1,
100✔
231
                ),
100✔
232
                NodeID2: tlv.NewPrimitiveRecord[tlv.TlvType10, [33]byte](
100✔
233
                        nodeID2,
100✔
234
                ),
100✔
235
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
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") {
149✔
242
                var bitcoinKey1 [33]byte
49✔
243
                copy(bitcoinKey1[:], RandPubKey(t).SerializeCompressed())
49✔
244
                msg.BitcoinKey1 = tlv.SomeRecordT(
49✔
245
                        tlv.NewPrimitiveRecord[tlv.TlvType12, [33]byte](
49✔
246
                                bitcoinKey1,
49✔
247
                        ),
49✔
248
                )
49✔
249
        }
49✔
250

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

261
        if rapid.Bool().Draw(t, "includeMerkleRootHash") {
144✔
262
                hash := RandSHA256Hash(t)
44✔
263
                var merkleRootHash [32]byte
44✔
264
                copy(merkleRootHash[:], hash[:])
44✔
265
                msg.MerkleRootHash = tlv.SomeRecordT(
44✔
266
                        tlv.NewPrimitiveRecord[tlv.TlvType16, [32]byte](
44✔
267
                                merkleRootHash,
44✔
268
                        ),
44✔
269
                )
44✔
270
        }
44✔
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 {
158✔
300
                scid := RandShortChannelID(t)
58✔
301
                msg.AliasScid = &scid
58✔
302
        }
58✔
303

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

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

316
        if includeAnnouncementBitcoinNonce {
142✔
317
                nonce := RandMusig2Nonce(t)
42✔
318
                msg.AnnouncementBitcoinNonce = tlv.SomeRecordT(
42✔
319
                        tlv.NewRecordT[tlv.TlvType2, Musig2Nonce](nonce),
42✔
320
                )
42✔
321
        }
42✔
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 {
150✔
353
                nonce := RandMusig2Nonce(t)
50✔
354
                msg.LocalNonce = SomeMusig2Nonce(nonce)
50✔
355
        }
50✔
356

357
        if includeDynHeight {
146✔
358
                height := DynHeight(rapid.Uint64().Draw(t, "dynHeight"))
46✔
359
                msg.DynHeight = fn.Some(height)
46✔
360
        }
46✔
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 {
153✔
379
                msgFlags |= ChanUpdateRequiredMaxHtlc
53✔
380
        }
53✔
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 {
144✔
387
                chanFlags |= ChanUpdateDirection
44✔
388
        }
44✔
389

390
        // Randomly decide if channel is disabled
391
        isDisabled := rapid.Bool().Draw(t, "isDisabled")
100✔
392
        if isDisabled {
160✔
393
                chanFlags |= ChanUpdateDisabled
60✔
394
        }
60✔
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 {
147✔
406
                maxHtlc = 0
47✔
407
        }
47✔
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 {
150✔
419
                if customRecords == nil {
60✔
420
                        customRecords = make(CustomRecords)
10✔
421
                }
10✔
422

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

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

50✔
442
                customRecords[uint64(FeeRecordType)] = b.Bytes()
50✔
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") {
142✔
489
                disabledFlags |= ChanUpdateDisableIncoming
42✔
490
        }
42✔
491
        if rapid.Bool().Draw(t, "disableOutgoing") {
153✔
492
                disabledFlags |= ChanUpdateDisableOutgoing
53✔
493
        }
53✔
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
        //nolint:ll
100✔
515
        msg := &ChannelUpdate2{
100✔
516
                Signature: RandSignature(t),
100✔
517
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
100✔
518
                        chainHashObj,
100✔
519
                ),
100✔
520
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2, ShortChannelID](
100✔
521
                        shortChanID,
100✔
522
                ),
100✔
523
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType4, uint32](
100✔
524
                        blockHeight,
100✔
525
                ),
100✔
526
                DisabledFlags: tlv.NewPrimitiveRecord[tlv.TlvType6, ChanUpdateDisableFlags]( //nolint:ll
100✔
527
                        disabledFlags,
100✔
528
                ),
100✔
529
                CLTVExpiryDelta: tlv.NewPrimitiveRecord[tlv.TlvType10, uint16](
100✔
530
                        cltvExpiryDelta,
100✔
531
                ),
100✔
532
                HTLCMinimumMsat: tlv.NewPrimitiveRecord[tlv.TlvType12, MilliSatoshi](
100✔
533
                        htlcMinMsat,
100✔
534
                ),
100✔
535
                HTLCMaximumMsat: tlv.NewPrimitiveRecord[tlv.TlvType14, MilliSatoshi](
100✔
536
                        htlcMaxMsat,
100✔
537
                ),
100✔
538
                FeeBaseMsat: tlv.NewPrimitiveRecord[tlv.TlvType16, uint32](
100✔
539
                        feeBaseMsat,
100✔
540
                ),
100✔
541
                FeeProportionalMillionths: tlv.NewPrimitiveRecord[tlv.TlvType18, uint32](
100✔
542
                        feeProportionalMillionths,
100✔
543
                ),
100✔
544
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
545
        }
100✔
546

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

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

555
        return msg
100✔
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 {
100✔
567
        msg := &ClosingComplete{
100✔
568
                ChannelID: RandChannelID(t),
100✔
569
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
100✔
570
                        t, "feeSatoshis"),
100✔
571
                ),
100✔
572
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
100✔
573
                        t, "lockTime",
100✔
574
                ),
100✔
575
                CloseeScript: RandDeliveryAddress(t),
100✔
576
                CloserScript: RandDeliveryAddress(t),
100✔
577
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
578
        }
100✔
579

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

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

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

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

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

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

621
        return msg
100✔
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 {
100✔
633
        msg := &ClosingSig{
100✔
634
                ChannelID:    RandChannelID(t),
100✔
635
                CloseeScript: RandDeliveryAddress(t),
100✔
636
                CloserScript: RandDeliveryAddress(t),
100✔
637
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
638
        }
100✔
639

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

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

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

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

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

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

681
        return msg
100✔
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 {
100✔
693
        // Generate a random boolean to decide whether to include CommitSig or
100✔
694
        // PartialSig Since they're mutually exclusive, when one is populated,
100✔
695
        // the other must be blank.
100✔
696
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
697

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

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

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

719
        return msg
100✔
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 {
100✔
731
        cr, _ := RandCustomRecords(t, nil, true)
100✔
732
        sig := &CommitSig{
100✔
733
                ChanID:        RandChannelID(t),
100✔
734
                CommitSig:     RandSignature(t),
100✔
735
                CustomRecords: cr,
100✔
736
        }
100✔
737

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

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

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

754
        return sig
100✔
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 {
11✔
766
        msgType := MessageType(
11✔
767
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
11✔
768
                        t, "customMsgType",
11✔
769
                ),
11✔
770
        )
11✔
771

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

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

782
        return msg
11✔
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 {
100✔
794
        msg := &DynAck{
100✔
795
                ChanID:    RandChannelID(t),
100✔
796
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
797
        }
100✔
798

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

100✔
801
        if includeLocalNonce {
152✔
802
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
52✔
803
        }
52✔
804

805
        return msg
100✔
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 {
100✔
817
        msg := &DynPropose{
100✔
818
                ChanID:    RandChannelID(t),
100✔
819
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
820
        }
100✔
821

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

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

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

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

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

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

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

875
        return msg
100✔
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 {
100✔
887
        featureVec := NewRawFeatureVector()
100✔
888

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

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

905
        return &DynReject{
100✔
906
                ChanID:           RandChannelID(t),
100✔
907
                UpdateRejections: *featureVec,
100✔
908
                ExtraData:        extraData,
100✔
909
        }
100✔
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 {
100✔
921
        chanID := RandChannelID(t)
100✔
922

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

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

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

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

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

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

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

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

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

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

990
        return &DynCommit{
100✔
991
                DynPropose: *dp,
100✔
992
                DynAck:     *da,
100✔
993
                ExtraData:  extraData,
100✔
994
        }
100✔
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 {
100✔
1006
        var pendingChanID [32]byte
100✔
1007
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1008
                t, "pendingChanID",
100✔
1009
        )
100✔
1010
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1011

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

100✔
1016
        if includePartialSig {
144✔
1017
                sigWithNonce := RandPartialSigWithNonce(t)
44✔
1018
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
44✔
1019

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

1026
        return &FundingCreated{
100✔
1027
                PendingChannelID: pendingChanID,
100✔
1028
                FundingPoint:     RandOutPoint(t),
100✔
1029
                CommitSig:        commitSig,
100✔
1030
                PartialSig:       partialSig,
100✔
1031
                ExtraData:        RandExtraOpaqueData(t, nil),
100✔
1032
        }
100✔
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 {
100✔
1044
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
1045

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

100✔
1051
        if usePartialSig {
149✔
1052
                sigWithNonce := RandPartialSigWithNonce(t)
49✔
1053
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
49✔
1054

49✔
1055
                msg.CommitSig = Sig{}
49✔
1056
        } else {
100✔
1057
                msg.CommitSig = RandSignature(t)
51✔
1058
        }
51✔
1059

1060
        return msg
100✔
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 {
100✔
1072
        var chainHash chainhash.Hash
100✔
1073
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1074
        copy(chainHash[:], hashBytes)
100✔
1075

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

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

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

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

1102
        return msg
100✔
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 {
100✔
1110
        global := NewRawFeatureVector()
100✔
1111
        local := NewRawFeatureVector()
100✔
1112

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

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

1133
        return NewInitMessage(global, local)
100✔
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 {
100✔
1145
        return &KickoffSig{
100✔
1146
                ChanID:    RandChannelID(t),
100✔
1147
                Signature: RandSignature(t),
100✔
1148
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1149
        }
100✔
1150
}
100✔
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 {
100✔
1161
        // Generate random compressed public key for node ID
100✔
1162
        pubKey := RandPubKey(t)
100✔
1163
        var nodeID [33]byte
100✔
1164
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1165

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

100✔
1173
        return &NodeAnnouncement{
100✔
1174
                Signature: RandSignature(t),
100✔
1175
                Features:  RandFeatureVector(t),
100✔
1176
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
1177
                        t, "timestamp"),
100✔
1178
                ),
100✔
1179
                NodeID:          nodeID,
100✔
1180
                RGBColor:        rgbColor,
100✔
1181
                Alias:           RandNodeAlias(t),
100✔
1182
                Addresses:       RandNetAddrs(t),
100✔
1183
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
1184
        }
100✔
1185
}
100✔
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 {
100✔
1196
        chainHash := RandChainHash(t)
100✔
1197
        var hash chainhash.Hash
100✔
1198
        copy(hash[:], chainHash[:])
100✔
1199

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

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

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

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

1223
        var channelType *ChannelType
100✔
1224
        if includeChannelType {
140✔
1225
                channelType = RandChannelType(t)
40✔
1226
        }
40✔
1227

1228
        var leaseExpiry *LeaseExpiry
100✔
1229
        if includeLeaseExpiry {
153✔
1230
                leaseExpiry = RandLeaseExpiry(t)
53✔
1231
        }
53✔
1232

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

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

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

1308
        return &Ping{
100✔
1309
                NumPongBytes: numPongBytes,
100✔
1310
                PaddingBytes: padding,
100✔
1311
        }
100✔
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 {
100✔
1323
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
100✔
1324
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
100✔
1325
                t, "pongPayload",
100✔
1326
        )
100✔
1327

100✔
1328
        return &Pong{
100✔
1329
                PongBytes: payload,
100✔
1330
        }
100✔
1331
}
100✔
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 {
100✔
1342
        msg := &QueryChannelRange{
100✔
1343
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1344
                        t, "firstBlockHeight"),
100✔
1345
                ),
100✔
1346
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1347
                        t, "numBlocks"),
100✔
1348
                ),
100✔
1349
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1350
        }
100✔
1351

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

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

1365
        return msg
100✔
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 {
100✔
1377
        var chainHash chainhash.Hash
100✔
1378
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1379
        copy(chainHash[:], hashBytes)
100✔
1380

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

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

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

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

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

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

1411
        msg.ShortChanIDs = shortChanIDs
100✔
1412

100✔
1413
        return msg
100✔
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 {
100✔
1425
        msg := &ReplyChannelRange{
100✔
1426
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1427
                        t, "firstBlockHeight"),
100✔
1428
                ),
100✔
1429
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1430
                        t, "numBlocks"),
100✔
1431
                ),
100✔
1432
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
100✔
1433
                EncodingType: QueryEncoding(
100✔
1434
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
100✔
1435
                ),
100✔
1436
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1437
        }
100✔
1438

100✔
1439
        msg.ChainHash = RandChainHash(t)
100✔
1440

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

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

1454
                scids[i] = scid
822✔
1455

822✔
1456
                scidSet.Add(scid)
822✔
1457
        }
1458

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

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

1472
        return msg
90✔
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 {
100✔
1484
        var chainHash chainhash.Hash
100✔
1485
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1486
        copy(chainHash[:], hashBytes)
100✔
1487

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

100✔
1490
        return &ReplyShortChanIDsEnd{
100✔
1491
                ChainHash: chainHash,
100✔
1492
                Complete:  complete,
100✔
1493
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1494
        }
100✔
1495
}
100✔
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 {
100✔
1501
        msg := NewRevokeAndAck()
100✔
1502

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

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

100✔
1511
        msg.NextRevocationKey = RandPubKey(t)
100✔
1512

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

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

1525
        return msg
100✔
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 {
101✔
1537
        // Generate random delivery address
101✔
1538
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
101✔
1539
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
101✔
1540

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

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

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

101✔
1569
        if includeNonce {
154✔
1570
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
53✔
1571
        }
53✔
1572

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

101✔
1575
        return &Shutdown{
101✔
1576
                ChannelID:     RandChannelID(t),
101✔
1577
                Address:       addr,
101✔
1578
                ShutdownNonce: shutdownNonce,
101✔
1579
                CustomRecords: cr,
101✔
1580
        }
101✔
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 {
103✔
1592
        m := &Stfu{
103✔
1593
                ChanID:    RandChannelID(t),
103✔
1594
                Initiator: rapid.Bool().Draw(t, "initiator"),
103✔
1595
        }
103✔
1596

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

1602
        return m
103✔
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 {
100✔
1613
        msg := &UpdateAddHTLC{
100✔
1614
                ChanID: RandChannelID(t),
100✔
1615
                ID:     rapid.Uint64().Draw(t, "id"),
100✔
1616
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
100✔
1617
                Expiry: rapid.Uint32().Draw(t, "expiry"),
100✔
1618
        }
100✔
1619

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

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

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

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

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

1642
        return msg
100✔
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 {
100✔
1654
        return &UpdateFailHTLC{
100✔
1655
                ChanID:    RandChannelID(t),
100✔
1656
                ID:        rapid.Uint64().Draw(t, "id"),
100✔
1657
                Reason:    RandOpaqueReason(t),
100✔
1658
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1659
        }
100✔
1660
}
100✔
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 {
100✔
1671
        return &UpdateFailMalformedHTLC{
100✔
1672
                ChanID:       RandChannelID(t),
100✔
1673
                ID:           rapid.Uint64().Draw(t, "id"),
100✔
1674
                ShaOnionBlob: RandSHA256Hash(t),
100✔
1675
                FailureCode:  RandFailCode(t),
100✔
1676
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1677
        }
100✔
1678
}
100✔
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 {
100✔
1689
        return &UpdateFee{
100✔
1690
                ChanID:    RandChannelID(t),
100✔
1691
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
100✔
1692
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1693
        }
100✔
1694
}
100✔
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 {
100✔
1705
        msg := &UpdateFulfillHTLC{
100✔
1706
                ChanID:          RandChannelID(t),
100✔
1707
                ID:              rapid.Uint64().Draw(t, "id"),
100✔
1708
                PaymentPreimage: RandPaymentPreimage(t),
100✔
1709
        }
100✔
1710

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

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

1719
        return msg
100✔
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 {
106✔
1731
        msg := &Warning{
106✔
1732
                ChanID: RandChannelID(t),
106✔
1733
        }
106✔
1734

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

1754
        return msg
106✔
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 {
101✔
1766
        msg := &Error{
101✔
1767
                ChanID: RandChannelID(t),
101✔
1768
        }
101✔
1769

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

1790
        return msg
101✔
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