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

lightningnetwork / lnd / 16598748676

29 Jul 2025 02:16PM UTC coverage: 67.22% (-0.02%) from 67.241%
16598748676

Pull #9625

github

web-flow
Merge 49204e2c6 into ce10a9d82
Pull Request #9625: Add deletecanceledinvoice RPC call

31 of 81 new or added lines in 4 files covered. (38.27%)

95 existing lines in 20 files now uncovered.

135535 of 201630 relevant lines covered (67.22%)

21730.13 hits per line

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

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

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

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

53
        var leaseExpiry *LeaseExpiry
102✔
54
        if includeLeaseExpiry {
140✔
55
                leaseExpiry = RandLeaseExpiry(t)
38✔
56
        }
38✔
57

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

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

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

109
// RandTestMessage populates the message with random data suitable for testing.
110
// It uses the rapid testing framework to generate random values.
111
//
112
// This is part of the TestMessage interface.
113
func (a *AnnounceSignatures1) RandTestMessage(t *rapid.T) Message {
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 {
153✔
165
                nodeID1, nodeID2 = nodeID2, nodeID1
53✔
166
        }
53✔
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 {
150✔
208
                nodeID1, nodeID2 = nodeID2, nodeID1
50✔
209
        }
50✔
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") {
153✔
242
                var bitcoinKey1 [33]byte
53✔
243
                copy(bitcoinKey1[:], RandPubKey(t).SerializeCompressed())
53✔
244
                msg.BitcoinKey1 = tlv.SomeRecordT(
53✔
245
                        tlv.NewPrimitiveRecord[tlv.TlvType12, [33]byte](
53✔
246
                                bitcoinKey1,
53✔
247
                        ),
53✔
248
                )
53✔
249
        }
53✔
250

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

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

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

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

316
        if includeAnnouncementBitcoinNonce {
145✔
317
                nonce := RandMusig2Nonce(t)
45✔
318
                msg.AnnouncementBitcoinNonce = tlv.SomeRecordT(
45✔
319
                        tlv.NewRecordT[tlv.TlvType2, Musig2Nonce](nonce),
45✔
320
                )
45✔
321
        }
45✔
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 {
144✔
358
                height := DynHeight(rapid.Uint64().Draw(t, "dynHeight"))
44✔
359
                msg.DynHeight = fn.Some(height)
44✔
360
        }
44✔
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 {
146✔
379
                msgFlags |= ChanUpdateRequiredMaxHtlc
46✔
380
        }
46✔
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 {
151✔
387
                chanFlags |= ChanUpdateDirection
51✔
388
        }
51✔
389

390
        // Randomly decide if channel is disabled
391
        isDisabled := rapid.Bool().Draw(t, "isDisabled")
100✔
392
        if isDisabled {
157✔
393
                chanFlags |= ChanUpdateDisabled
57✔
394
        }
57✔
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 {
154✔
406
                maxHtlc = 0
54✔
407
        }
54✔
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 {
161✔
419
                if customRecords == nil {
74✔
420
                        customRecords = make(CustomRecords)
13✔
421
                }
13✔
422

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

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

61✔
442
                customRecords[uint64(FeeRecordType)] = b.Bytes()
61✔
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") {
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") {
149✔
550
                msg.SecondPeer = tlv.SomeRecordT(
49✔
551
                        tlv.RecordT[tlv.TlvType8, TrueBoolean]{},
49✔
552
                )
49✔
553
        }
49✔
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 {
112✔
587

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

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

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

614
        if includeCloserAndClosee {
152✔
615
                sig := RandSignature(t)
52✔
616
                msg.CloserAndClosee = tlv.SomeRecordT(
52✔
617
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
52✔
618
                )
52✔
619
        }
52✔
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 {
101✔
633
        msg := &ClosingSig{
101✔
634
                ChannelID:    RandChannelID(t),
101✔
635
                CloseeScript: RandDeliveryAddress(t),
101✔
636
                CloserScript: RandDeliveryAddress(t),
101✔
637
                ExtraData:    RandExtraOpaqueData(t, nil),
101✔
638
        }
101✔
639

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

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

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

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

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

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

681
        return msg
101✔
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 {
151✔
707
                sigBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
51✔
708
                        t, "sigScalar",
51✔
709
                )
51✔
710
                var s btcec.ModNScalar
51✔
711
                _ = s.SetByteSlice(sigBytes)
51✔
712

51✔
713
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
51✔
714
                msg.Signature = Sig{}
51✔
715
        } else {
100✔
716
                msg.Signature = RandSignature(t)
49✔
717
        }
49✔
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++ {
739✔
741
                htlcSigs[i] = RandSignature(t)
639✔
742
        }
639✔
743

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

748
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
749
        if includePartialSig {
150✔
750
                sigWithNonce := RandPartialSigWithNonce(t)
50✔
751
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
50✔
752
        }
50✔
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 {
3✔
766
        msgType := MessageType(
3✔
767
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
3✔
768
                        t, "customMsgType",
3✔
769
                ),
3✔
770
        )
3✔
771

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

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

782
        return msg
3✔
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
        }
100✔
797

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

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

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

100✔
817
        return msg
100✔
818
}
819

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

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

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

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

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

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

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

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

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

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

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

101✔
898
        return msg
101✔
899
}
900

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

100✔
1030
        return msg
100✔
1031
}
1032

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

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

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

100✔
1052
        if includePartialSig {
151✔
1053
                sigWithNonce := RandPartialSigWithNonce(t)
51✔
1054
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
51✔
1055

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

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

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

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

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

100✔
1087
        if usePartialSig {
153✔
1088
                sigWithNonce := RandPartialSigWithNonce(t)
53✔
1089
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
53✔
1090

53✔
1091
                msg.CommitSig = Sig{}
53✔
1092
        } else {
100✔
1093
                msg.CommitSig = RandSignature(t)
47✔
1094
        }
47✔
1095

1096
        return msg
100✔
1097
}
1098

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

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

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

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

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

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

1138
        return msg
100✔
1139
}
1140

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

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

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

1169
        return NewInitMessage(global, local)
101✔
1170
}
1171

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

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

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

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

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

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

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

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

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

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

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

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

1259
        var channelType *ChannelType
100✔
1260
        if includeChannelType {
142✔
1261
                channelType = RandChannelType(t)
42✔
1262
        }
42✔
1263

1264
        var leaseExpiry *LeaseExpiry
100✔
1265
        if includeLeaseExpiry {
145✔
1266
                leaseExpiry = RandLeaseExpiry(t)
45✔
1267
        }
45✔
1268

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

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

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

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

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

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

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

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

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

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

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

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

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

1401
        return msg
100✔
1402
}
1403

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

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

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

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

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

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

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

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

1447
        msg.ShortChanIDs = shortChanIDs
100✔
1448

100✔
1449
        return msg
100✔
1450
}
1451

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

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

100✔
1475
        msg.ChainHash = RandChainHash(t)
100✔
1476

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

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

1490
                scids[i] = scid
689✔
1491

689✔
1492
                scidSet.Add(scid)
689✔
1493
        }
1494

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

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

1508
        return msg
88✔
1509
}
1510

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

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

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

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

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

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

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

100✔
1547
        msg.NextRevocationKey = RandPubKey(t)
100✔
1548

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

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

1561
        return msg
100✔
1562
}
1563

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

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

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

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

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

100✔
1605
        if includeNonce {
152✔
1606
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
52✔
1607
        }
52✔
1608

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

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

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

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

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

1638
        return m
105✔
1639
}
1640

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

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

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

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

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

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

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

1678
        return msg
100✔
1679
}
1680

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

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

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

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

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

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

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

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

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

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

1755
        return msg
100✔
1756
}
1757

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

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

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

1790
        return msg
110✔
1791
}
1792

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

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

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

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

© 2025 Coveralls, Inc