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

lightningnetwork / lnd / 13999301927

21 Mar 2025 07:18PM UTC coverage: 68.989% (+9.9%) from 59.126%
13999301927

push

github

web-flow
Merge pull request #9623 from Roasbeef/size-msg-test-msg

Size msg test msg

1461 of 1572 new or added lines in 43 files covered. (92.94%)

28 existing lines in 6 files now uncovered.

132898 of 192637 relevant lines covered (68.99%)

22200.59 hits per line

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

99.91
/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/lnwallet/chainfee"
14
        "github.com/lightningnetwork/lnd/tlv"
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 {
101✔
38
        var pendingChanID [32]byte
101✔
39
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
101✔
40
                t, "pendingChanID",
101✔
41
        )
101✔
42
        copy(pendingChanID[:], pendingChanIDBytes)
101✔
43

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

101✔
49
        if includeChannelType {
156✔
50
                channelType = RandChannelType(t)
55✔
51
        }
55✔
52

53
        var leaseExpiry *LeaseExpiry
101✔
54
        if includeLeaseExpiry {
153✔
55
                leaseExpiry = RandLeaseExpiry(t)
52✔
56
        }
52✔
57

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

66
        return &AcceptChannel{
101✔
67
                PendingChannelID: pendingChanID,
101✔
68
                DustLimit: btcutil.Amount(
101✔
69
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
101✔
70
                ),
101✔
71
                MaxValueInFlight: MilliSatoshi(
101✔
72
                        rapid.IntRange(10000, 1000000).Draw(
101✔
73
                                t, "maxValueInFlight",
101✔
74
                        ),
101✔
75
                ),
101✔
76
                ChannelReserve: btcutil.Amount(
101✔
77
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
101✔
78
                ),
101✔
79
                HtlcMinimum: MilliSatoshi(
101✔
80
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
101✔
81
                ),
101✔
82
                MinAcceptDepth: uint32(
101✔
83
                        rapid.IntRange(1, 10).Draw(t, "minAcceptDepth"),
101✔
84
                ),
101✔
85
                CsvDelay: uint16(
101✔
86
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
101✔
87
                ),
101✔
88
                MaxAcceptedHTLCs: uint16(
101✔
89
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
101✔
90
                ),
101✔
91
                FundingKey:            RandPubKey(t),
101✔
92
                RevocationPoint:       RandPubKey(t),
101✔
93
                PaymentPoint:          RandPubKey(t),
101✔
94
                DelayedPaymentPoint:   RandPubKey(t),
101✔
95
                HtlcPoint:             RandPubKey(t),
101✔
96
                FirstCommitmentPoint:  RandPubKey(t),
101✔
97
                UpfrontShutdownScript: RandDeliveryAddress(t),
101✔
98
                ChannelType:           channelType,
101✔
99
                LeaseExpiry:           leaseExpiry,
101✔
100
                LocalNonce:            localNonce,
101✔
101
                ExtraData:             RandExtraOpaqueData(t, nil),
101✔
102
        }
101✔
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 {
142✔
208
                nodeID1, nodeID2 = nodeID2, nodeID1
42✔
209
        }
42✔
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") {
145✔
242
                var bitcoinKey1 [33]byte
45✔
243
                copy(bitcoinKey1[:], RandPubKey(t).SerializeCompressed())
45✔
244
                msg.BitcoinKey1 = tlv.SomeRecordT(
45✔
245
                        tlv.NewPrimitiveRecord[tlv.TlvType12, [33]byte](
45✔
246
                                bitcoinKey1,
45✔
247
                        ),
45✔
248
                )
45✔
249
        }
45✔
250

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

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

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

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

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

357
        if includeDynHeight {
142✔
358
                height := DynHeight(rapid.Uint64().Draw(t, "dynHeight"))
42✔
359
                msg.DynHeight = fn.Some(height)
42✔
360
        }
42✔
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 {
151✔
379
                msgFlags |= ChanUpdateRequiredMaxHtlc
51✔
380
        }
51✔
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 {
155✔
387
                chanFlags |= ChanUpdateDirection
55✔
388
        }
55✔
389

390
        // Randomly decide if channel is disabled
391
        isDisabled := rapid.Bool().Draw(t, "isDisabled")
100✔
392
        if isDisabled {
162✔
393
                chanFlags |= ChanUpdateDisabled
62✔
394
        }
62✔
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 {
149✔
406
                maxHtlc = 0
49✔
407
        }
49✔
408

409
        return &ChannelUpdate1{
100✔
410
                Signature:      RandSignature(t),
100✔
411
                ChainHash:      hash,
100✔
412
                ShortChannelID: RandShortChannelID(t),
100✔
413
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
414
                        t, "timestamp"),
100✔
415
                ),
100✔
416
                MessageFlags: msgFlags,
100✔
417
                ChannelFlags: chanFlags,
100✔
418
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
100✔
419
                        t, "timelockDelta"),
100✔
420
                ),
100✔
421
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
100✔
422
                        t, "htlcMinimum"),
100✔
423
                ),
100✔
424
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
425
                        t, "baseFee"),
100✔
426
                ),
100✔
427
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
428
                        t, "feeRate"),
100✔
429
                ),
100✔
430
                HtlcMaximumMsat: maxHtlc,
100✔
431
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
432
        }
100✔
433
}
434

435
// A compile time check to ensure ChannelUpdate2 implements the
436
// lnwire.TestMessage interface.
437
var _ TestMessage = (*ChannelUpdate2)(nil)
438

439
// RandTestMessage populates the message with random data suitable for testing.
440
// It uses the rapid testing framework to generate random values.
441
//
442
// This is part of the TestMessage interface.
443
func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
100✔
444
        shortChanID := RandShortChannelID(t)
100✔
445
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
100✔
446

100✔
447
        var disabledFlags ChanUpdateDisableFlags
100✔
448
        if rapid.Bool().Draw(t, "disableIncoming") {
148✔
449
                disabledFlags |= ChanUpdateDisableIncoming
48✔
450
        }
48✔
451
        if rapid.Bool().Draw(t, "disableOutgoing") {
154✔
452
                disabledFlags |= ChanUpdateDisableOutgoing
54✔
453
        }
54✔
454

455
        cltvExpiryDelta := uint16(rapid.IntRange(10, 200).Draw(
100✔
456
                t, "cltvExpiryDelta"),
100✔
457
        )
100✔
458

100✔
459
        htlcMinMsat := MilliSatoshi(rapid.IntRange(1, 10000).Draw(
100✔
460
                t, "htlcMinMsat"),
100✔
461
        )
100✔
462
        htlcMaxMsat := MilliSatoshi(rapid.IntRange(10000, 100000000).Draw(
100✔
463
                t, "htlcMaxMsat"),
100✔
464
        )
100✔
465
        feeBaseMsat := uint32(rapid.IntRange(0, 10000).Draw(t, "feeBaseMsat"))
100✔
466
        feeProportionalMillionths := uint32(rapid.IntRange(0, 10000).Draw(
100✔
467
                t, "feeProportionalMillionths"),
100✔
468
        )
100✔
469

100✔
470
        chainHash := RandChainHash(t)
100✔
471
        var chainHashObj chainhash.Hash
100✔
472
        copy(chainHashObj[:], chainHash[:])
100✔
473

100✔
474
        //nolint:ll
100✔
475
        msg := &ChannelUpdate2{
100✔
476
                Signature: RandSignature(t),
100✔
477
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
100✔
478
                        chainHashObj,
100✔
479
                ),
100✔
480
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2, ShortChannelID](
100✔
481
                        shortChanID,
100✔
482
                ),
100✔
483
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType4, uint32](
100✔
484
                        blockHeight,
100✔
485
                ),
100✔
486
                DisabledFlags: tlv.NewPrimitiveRecord[tlv.TlvType6, ChanUpdateDisableFlags]( //nolint:ll
100✔
487
                        disabledFlags,
100✔
488
                ),
100✔
489
                CLTVExpiryDelta: tlv.NewPrimitiveRecord[tlv.TlvType10, uint16](
100✔
490
                        cltvExpiryDelta,
100✔
491
                ),
100✔
492
                HTLCMinimumMsat: tlv.NewPrimitiveRecord[tlv.TlvType12, MilliSatoshi](
100✔
493
                        htlcMinMsat,
100✔
494
                ),
100✔
495
                HTLCMaximumMsat: tlv.NewPrimitiveRecord[tlv.TlvType14, MilliSatoshi](
100✔
496
                        htlcMaxMsat,
100✔
497
                ),
100✔
498
                FeeBaseMsat: tlv.NewPrimitiveRecord[tlv.TlvType16, uint32](
100✔
499
                        feeBaseMsat,
100✔
500
                ),
100✔
501
                FeeProportionalMillionths: tlv.NewPrimitiveRecord[tlv.TlvType18, uint32](
100✔
502
                        feeProportionalMillionths,
100✔
503
                ),
100✔
504
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
505
        }
100✔
506

100✔
507
        msg.Signature.ForceSchnorr()
100✔
508

100✔
509
        if rapid.Bool().Draw(t, "isSecondPeer") {
154✔
510
                msg.SecondPeer = tlv.SomeRecordT(
54✔
511
                        tlv.RecordT[tlv.TlvType8, TrueBoolean]{},
54✔
512
                )
54✔
513
        }
54✔
514

515
        return msg
100✔
516
}
517

518
// A compile time check to ensure ClosingComplete implements the
519
// lnwire.TestMessage interface.
520
var _ TestMessage = (*ClosingComplete)(nil)
521

522
// RandTestMessage populates the message with random data suitable for testing.
523
// It uses the rapid testing framework to generate random values.
524
//
525
// This is part of the TestMessage interface.
526
func (c *ClosingComplete) RandTestMessage(t *rapid.T) Message {
100✔
527
        msg := &ClosingComplete{
100✔
528
                ChannelID: RandChannelID(t),
100✔
529
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
100✔
530
                        t, "feeSatoshis"),
100✔
531
                ),
100✔
532
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
100✔
533
                        t, "lockTime",
100✔
534
                ),
100✔
535
                CloseeScript: RandDeliveryAddress(t),
100✔
536
                CloserScript: RandDeliveryAddress(t),
100✔
537
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
538
        }
100✔
539

100✔
540
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
100✔
541
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
100✔
542
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
100✔
543

100✔
544
        // Ensure at least one signature is present.
100✔
545
        if !includeCloserNoClosee && !includeNoCloserClosee &&
100✔
546
                !includeCloserAndClosee {
108✔
547

8✔
548
                // If all are false, enable at least one randomly.
8✔
549
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
8✔
550
                switch choice {
8✔
551
                case 0:
3✔
552
                        includeCloserNoClosee = true
3✔
553
                case 1:
3✔
554
                        includeNoCloserClosee = true
3✔
555
                case 2:
2✔
556
                        includeCloserAndClosee = true
2✔
557
                }
558
        }
559

560
        if includeCloserNoClosee {
164✔
561
                sig := RandSignature(t)
64✔
562
                msg.CloserNoClosee = tlv.SomeRecordT(
64✔
563
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
64✔
564
                )
64✔
565
        }
64✔
566

567
        if includeNoCloserClosee {
161✔
568
                sig := RandSignature(t)
61✔
569
                msg.NoCloserClosee = tlv.SomeRecordT(
61✔
570
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
61✔
571
                )
61✔
572
        }
61✔
573

574
        if includeCloserAndClosee {
154✔
575
                sig := RandSignature(t)
54✔
576
                msg.CloserAndClosee = tlv.SomeRecordT(
54✔
577
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
54✔
578
                )
54✔
579
        }
54✔
580

581
        return msg
100✔
582
}
583

584
// A compile time check to ensure ClosingSig implements the lnwire.TestMessage
585
// interface.
586
var _ TestMessage = (*ClosingSig)(nil)
587

588
// RandTestMessage populates the message with random data suitable for testing.
589
// It uses the rapid testing framework to generate random values.
590
//
591
// This is part of the TestMessage interface.
592
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
100✔
593
        msg := &ClosingSig{
100✔
594
                ChannelID:    RandChannelID(t),
100✔
595
                CloseeScript: RandDeliveryAddress(t),
100✔
596
                CloserScript: RandDeliveryAddress(t),
100✔
597
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
598
        }
100✔
599

100✔
600
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
100✔
601
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
100✔
602
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
100✔
603

100✔
604
        // Ensure at least one signature is present.
100✔
605
        if !includeCloserNoClosee && !includeNoCloserClosee &&
100✔
606
                !includeCloserAndClosee {
116✔
607

16✔
608
                // If all are false, enable at least one randomly.
16✔
609
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
16✔
610
                switch choice {
16✔
611
                case 0:
4✔
612
                        includeCloserNoClosee = true
4✔
613
                case 1:
6✔
614
                        includeNoCloserClosee = true
6✔
615
                case 2:
6✔
616
                        includeCloserAndClosee = true
6✔
617
                }
618
        }
619

620
        if includeCloserNoClosee {
156✔
621
                sig := RandSignature(t)
56✔
622
                msg.CloserNoClosee = tlv.SomeRecordT(
56✔
623
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
56✔
624
                )
56✔
625
        }
56✔
626

627
        if includeNoCloserClosee {
153✔
628
                sig := RandSignature(t)
53✔
629
                msg.NoCloserClosee = tlv.SomeRecordT(
53✔
630
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
53✔
631
                )
53✔
632
        }
53✔
633

634
        if includeCloserAndClosee {
153✔
635
                sig := RandSignature(t)
53✔
636
                msg.CloserAndClosee = tlv.SomeRecordT(
53✔
637
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
53✔
638
                )
53✔
639
        }
53✔
640

641
        return msg
100✔
642
}
643

644
// A compile time check to ensure ClosingSigned implements the
645
// lnwire.TestMessage interface.
646
var _ TestMessage = (*ClosingSigned)(nil)
647

648
// RandTestMessage populates the message with random data suitable for testing.
649
// It uses the rapid testing framework to generate random values.
650
//
651
// This is part of the TestMessage interface.
652
func (c *ClosingSigned) RandTestMessage(t *rapid.T) Message {
101✔
653
        // Generate a random boolean to decide whether to include CommitSig or
101✔
654
        // PartialSig Since they're mutually exclusive, when one is populated,
101✔
655
        // the other must be blank.
101✔
656
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
101✔
657

101✔
658
        msg := &ClosingSigned{
101✔
659
                ChannelID: RandChannelID(t),
101✔
660
                FeeSatoshis: btcutil.Amount(
101✔
661
                        rapid.Int64Range(0, 1000000).Draw(t, "feeSatoshis"),
101✔
662
                ),
101✔
663
                ExtraData: RandExtraOpaqueData(t, nil),
101✔
664
        }
101✔
665

101✔
666
        if usePartialSig {
150✔
667
                sigBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
49✔
668
                        t, "sigScalar",
49✔
669
                )
49✔
670
                var s btcec.ModNScalar
49✔
671
                _ = s.SetByteSlice(sigBytes)
49✔
672

49✔
673
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
49✔
674
                msg.Signature = Sig{}
49✔
675
        } else {
101✔
676
                msg.Signature = RandSignature(t)
52✔
677
        }
52✔
678

679
        return msg
101✔
680
}
681

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

686
// RandTestMessage populates the message with random data suitable for testing.
687
// It uses the rapid testing framework to generate random values.
688
//
689
// This is part of the TestMessage interface.
690
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
100✔
691
        cr, _ := RandCustomRecords(t, nil, true)
100✔
692
        sig := &CommitSig{
100✔
693
                ChanID:        RandChannelID(t),
100✔
694
                CommitSig:     RandSignature(t),
100✔
695
                CustomRecords: cr,
100✔
696
        }
100✔
697

100✔
698
        numHtlcSigs := rapid.IntRange(0, 20).Draw(t, "numHtlcSigs")
100✔
699
        htlcSigs := make([]Sig, numHtlcSigs)
100✔
700
        for i := 0; i < numHtlcSigs; i++ {
874✔
701
                htlcSigs[i] = RandSignature(t)
774✔
702
        }
774✔
703

704
        if len(htlcSigs) > 0 {
192✔
705
                sig.HtlcSigs = htlcSigs
92✔
706
        }
92✔
707

708
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
709
        if includePartialSig {
149✔
710
                sigWithNonce := RandPartialSigWithNonce(t)
49✔
711
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
49✔
712
        }
49✔
713

714
        return sig
100✔
715
}
716

717
// A compile time check to ensure Custom implements the lnwire.TestMessage
718
// interface.
719
var _ TestMessage = (*Custom)(nil)
720

721
// RandTestMessage populates the message with random data suitable for testing.
722
// It uses the rapid testing framework to generate random values.
723
//
724
// This is part of the TestMessage interface.
725
func (c *Custom) RandTestMessage(t *rapid.T) Message {
16✔
726
        msgType := MessageType(
16✔
727
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
16✔
728
                        t, "customMsgType",
16✔
729
                ),
16✔
730
        )
16✔
731

16✔
732
        dataLen := rapid.IntRange(0, 1000).Draw(t, "customDataLength")
16✔
733
        data := rapid.SliceOfN(rapid.Byte(), dataLen, dataLen).Draw(
16✔
734
                t, "customData",
16✔
735
        )
16✔
736

16✔
737
        msg, err := NewCustom(msgType, data)
16✔
738
        if err != nil {
16✔
NEW
739
                panic(fmt.Sprintf("Error creating custom message: %v", err))
×
740
        }
741

742
        return msg
16✔
743
}
744

745
// A compile time check to ensure DynAck implements the lnwire.TestMessage
746
// interface.
747
var _ TestMessage = (*DynAck)(nil)
748

749
// RandTestMessage populates the message with random data suitable for testing.
750
// It uses the rapid testing framework to generate random values.
751
//
752
// This is part of the TestMessage interface.
753
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
100✔
754
        msg := &DynAck{
100✔
755
                ChanID:    RandChannelID(t),
100✔
756
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
757
        }
100✔
758

100✔
759
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
760

100✔
761
        if includeLocalNonce {
161✔
762
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
61✔
763
        }
61✔
764

765
        return msg
100✔
766
}
767

768
// A compile time check to ensure DynPropose implements the lnwire.TestMessage
769
// interface.
770
var _ TestMessage = (*DynPropose)(nil)
771

772
// RandTestMessage populates the message with random data suitable for testing.
773
// It uses the rapid testing framework to generate random values.
774
//
775
// This is part of the TestMessage interface.
776
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
100✔
777
        msg := &DynPropose{
100✔
778
                ChanID:    RandChannelID(t),
100✔
779
                Initiator: rapid.Bool().Draw(t, "initiator"),
100✔
780
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
781
        }
100✔
782

100✔
783
        // Randomly decide which optional fields to include
100✔
784
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
100✔
785
        includeMaxValueInFlight := rapid.Bool().Draw(
100✔
786
                t, "includeMaxValueInFlight",
100✔
787
        )
100✔
788
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
100✔
789
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
100✔
790
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
100✔
791
                t, "includeMaxAcceptedHTLCs",
100✔
792
        )
100✔
793
        includeFundingKey := rapid.Bool().Draw(t, "includeFundingKey")
100✔
794
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
795
        includeKickoffFeerate := rapid.Bool().Draw(t, "includeKickoffFeerate")
100✔
796

100✔
797
        // Generate random values for each included field
100✔
798
        if includeDustLimit {
154✔
799
                dl := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
54✔
800
                msg.DustLimit = fn.Some(dl)
54✔
801
        }
54✔
802

803
        if includeMaxValueInFlight {
149✔
804
                mvif := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
49✔
805
                msg.MaxValueInFlight = fn.Some(mvif)
49✔
806
        }
49✔
807

808
        if includeChannelReserve {
155✔
809
                cr := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
55✔
810
                msg.ChannelReserve = fn.Some(cr)
55✔
811
        }
55✔
812

813
        if includeCsvDelay {
148✔
814
                cd := rapid.Uint16().Draw(t, "csvDelay")
48✔
815
                msg.CsvDelay = fn.Some(cd)
48✔
816
        }
48✔
817

818
        if includeMaxAcceptedHTLCs {
152✔
819
                mah := rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
52✔
820
                msg.MaxAcceptedHTLCs = fn.Some(mah)
52✔
821
        }
52✔
822

823
        if includeFundingKey {
143✔
824
                msg.FundingKey = fn.Some(*RandPubKey(t))
43✔
825
        }
43✔
826

827
        if includeChannelType {
158✔
828
                msg.ChannelType = fn.Some(*RandChannelType(t))
58✔
829
        }
58✔
830

831
        if includeKickoffFeerate {
152✔
832
                kf := chainfee.SatPerKWeight(rapid.Uint32().Draw(
52✔
833
                        t, "kickoffFeerate"),
52✔
834
                )
52✔
835
                msg.KickoffFeerate = fn.Some(kf)
52✔
836
        }
52✔
837

838
        return msg
100✔
839
}
840

841
// A compile time check to ensure DynReject implements the lnwire.TestMessage
842
// interface.
843
var _ TestMessage = (*DynReject)(nil)
844

845
// RandTestMessage populates the message with random data suitable for testing.
846
// It uses the rapid testing framework to generate random values.
847
//
848
// This is part of the TestMessage interface.
849
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
100✔
850
        featureVec := NewRawFeatureVector()
100✔
851

100✔
852
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
100✔
853
        for i := 0; i < numFeatures; i++ {
409✔
854
                bit := FeatureBit(
309✔
855
                        rapid.IntRange(0, 31).Draw(
309✔
856
                                t, fmt.Sprintf("rejectionBit-%d", i),
309✔
857
                        ),
309✔
858
                )
309✔
859
                featureVec.Set(bit)
309✔
860
        }
309✔
861

862
        var extraData ExtraOpaqueData
100✔
863
        randData := RandExtraOpaqueData(t, nil)
100✔
864
        if len(randData) > 0 {
182✔
865
                extraData = randData
82✔
866
        }
82✔
867

868
        return &DynReject{
100✔
869
                ChanID:           RandChannelID(t),
100✔
870
                UpdateRejections: *featureVec,
100✔
871
                ExtraData:        extraData,
100✔
872
        }
100✔
873
}
874

875
// A compile time check to ensure FundingCreated implements the TestMessage
876
// interface.
877
var _ TestMessage = (*FundingCreated)(nil)
878

879
// RandTestMessage populates the message with random data suitable for testing.
880
// It uses the rapid testing framework to generate random values.
881
//
882
// This is part of the TestMessage interface.
883
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
100✔
884
        var pendingChanID [32]byte
100✔
885
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
886
                t, "pendingChanID",
100✔
887
        )
100✔
888
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
889

100✔
890
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
100✔
891
        var partialSig OptPartialSigWithNonceTLV
100✔
892
        var commitSig Sig
100✔
893

100✔
894
        if includePartialSig {
153✔
895
                sigWithNonce := RandPartialSigWithNonce(t)
53✔
896
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
53✔
897

53✔
898
                // When using partial sig, CommitSig should be empty/blank.
53✔
899
                commitSig = Sig{}
53✔
900
        } else {
100✔
901
                commitSig = RandSignature(t)
47✔
902
        }
47✔
903

904
        return &FundingCreated{
100✔
905
                PendingChannelID: pendingChanID,
100✔
906
                FundingPoint:     RandOutPoint(t),
100✔
907
                CommitSig:        commitSig,
100✔
908
                PartialSig:       partialSig,
100✔
909
                ExtraData:        RandExtraOpaqueData(t, nil),
100✔
910
        }
100✔
911
}
912

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

917
// RandTestMessage populates the message with random data suitable for testing.
918
// It uses the rapid testing framework to generate random values.
919
//
920
// This is part of the TestMessage interface.
921
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
100✔
922
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
923

100✔
924
        msg := &FundingSigned{
100✔
925
                ChanID:    RandChannelID(t),
100✔
926
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
927
        }
100✔
928

100✔
929
        if usePartialSig {
149✔
930
                sigWithNonce := RandPartialSigWithNonce(t)
49✔
931
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
49✔
932

49✔
933
                msg.CommitSig = Sig{}
49✔
934
        } else {
100✔
935
                msg.CommitSig = RandSignature(t)
51✔
936
        }
51✔
937

938
        return msg
100✔
939
}
940

941
// A compile time check to ensure GossipTimestampRange implements the
942
// lnwire.TestMessage interface.
943
var _ TestMessage = (*GossipTimestampRange)(nil)
944

945
// RandTestMessage populates the message with random data suitable for testing.
946
// It uses the rapid testing framework to generate random values.
947
//
948
// This is part of the TestMessage interface.
949
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
100✔
950
        var chainHash chainhash.Hash
100✔
951
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
952
        copy(chainHash[:], hashBytes)
100✔
953

100✔
954
        msg := &GossipTimestampRange{
100✔
955
                ChainHash:      chainHash,
100✔
956
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
100✔
957
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
100✔
958
                ExtraData:      RandExtraOpaqueData(t, nil),
100✔
959
        }
100✔
960

100✔
961
        includeFirstBlockHeight := rapid.Bool().Draw(
100✔
962
                t, "includeFirstBlockHeight",
100✔
963
        )
100✔
964
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
100✔
965

100✔
966
        if includeFirstBlockHeight {
148✔
967
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
48✔
968
                msg.FirstBlockHeight = tlv.SomeRecordT(
48✔
969
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
48✔
970
                )
48✔
971
        }
48✔
972

973
        if includeBlockRange {
143✔
974
                blockRange := rapid.Uint32().Draw(t, "blockRange")
43✔
975
                msg.BlockRange = tlv.SomeRecordT(
43✔
976
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
43✔
977
                )
43✔
978
        }
43✔
979

980
        return msg
100✔
981
}
982

983
// RandTestMessage populates the message with random data suitable for testing.
984
// It uses the rapid testing framework to generate random values.
985
//
986
// This is part of the TestMessage interface.
987
func (msg *Init) RandTestMessage(t *rapid.T) Message {
100✔
988
        global := NewRawFeatureVector()
100✔
989
        local := NewRawFeatureVector()
100✔
990

100✔
991
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
100✔
992
        for i := 0; i < numGlobalFeatures; i++ {
902✔
993
                bit := FeatureBit(
802✔
994
                        rapid.IntRange(0, 100).Draw(
802✔
995
                                t, fmt.Sprintf("globalFeatureBit%d", i),
802✔
996
                        ),
802✔
997
                )
802✔
998
                global.Set(bit)
802✔
999
        }
802✔
1000

1001
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
100✔
1002
        for i := 0; i < numLocalFeatures; i++ {
1,088✔
1003
                bit := FeatureBit(
988✔
1004
                        rapid.IntRange(0, 100).Draw(
988✔
1005
                                t, fmt.Sprintf("localFeatureBit%d", i),
988✔
1006
                        ),
988✔
1007
                )
988✔
1008
                local.Set(bit)
988✔
1009
        }
988✔
1010

1011
        return NewInitMessage(global, local)
100✔
1012
}
1013

1014
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1015
// interface.
1016
var _ TestMessage = (*KickoffSig)(nil)
1017

1018
// RandTestMessage populates the message with random data suitable for testing.
1019
// It uses the rapid testing framework to generate random values.
1020
//
1021
// This is part of the TestMessage interface.
1022
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
100✔
1023
        return &KickoffSig{
100✔
1024
                ChanID:    RandChannelID(t),
100✔
1025
                Signature: RandSignature(t),
100✔
1026
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1027
        }
100✔
1028
}
100✔
1029

1030
// A compile time check to ensure NodeAnnouncement implements the
1031
// lnwire.TestMessage interface.
1032
var _ TestMessage = (*NodeAnnouncement)(nil)
1033

1034
// RandTestMessage populates the message with random data suitable for testing.
1035
// It uses the rapid testing framework to generate random values.
1036
//
1037
// This is part of the TestMessage interface.
1038
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
100✔
1039
        // Generate random compressed public key for node ID
100✔
1040
        pubKey := RandPubKey(t)
100✔
1041
        var nodeID [33]byte
100✔
1042
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1043

100✔
1044
        // Generate random RGB color
100✔
1045
        rgbColor := color.RGBA{
100✔
1046
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
100✔
1047
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
100✔
1048
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
100✔
1049
        }
100✔
1050

100✔
1051
        return &NodeAnnouncement{
100✔
1052
                Signature: RandSignature(t),
100✔
1053
                Features:  RandFeatureVector(t),
100✔
1054
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
1055
                        t, "timestamp"),
100✔
1056
                ),
100✔
1057
                NodeID:          nodeID,
100✔
1058
                RGBColor:        rgbColor,
100✔
1059
                Alias:           RandNodeAlias(t),
100✔
1060
                Addresses:       RandNetAddrs(t),
100✔
1061
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
1062
        }
100✔
1063
}
100✔
1064

1065
// A compile time check to ensure OpenChannel implements the TestMessage
1066
// interface.
1067
var _ TestMessage = (*OpenChannel)(nil)
1068

1069
// RandTestMessage populates the message with random data suitable for testing.
1070
// It uses the rapid testing framework to generate random values.
1071
//
1072
// This is part of the TestMessage interface.
1073
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
100✔
1074
        chainHash := RandChainHash(t)
100✔
1075
        var hash chainhash.Hash
100✔
1076
        copy(hash[:], chainHash[:])
100✔
1077

100✔
1078
        var pendingChanID [32]byte
100✔
1079
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1080
                t, "pendingChanID",
100✔
1081
        )
100✔
1082
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1083

100✔
1084
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
1085
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
100✔
1086
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
1087

100✔
1088
        var channelFlags FundingFlag
100✔
1089
        if rapid.Bool().Draw(t, "announceChannel") {
147✔
1090
                channelFlags |= FFAnnounceChannel
47✔
1091
        }
47✔
1092

1093
        var localNonce OptMusig2NonceTLV
100✔
1094
        if includeLocalNonce {
139✔
1095
                nonce := RandMusig2Nonce(t)
39✔
1096
                localNonce = tlv.SomeRecordT(
39✔
1097
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
39✔
1098
                )
39✔
1099
        }
39✔
1100

1101
        var channelType *ChannelType
100✔
1102
        if includeChannelType {
146✔
1103
                channelType = RandChannelType(t)
46✔
1104
        }
46✔
1105

1106
        var leaseExpiry *LeaseExpiry
100✔
1107
        if includeLeaseExpiry {
151✔
1108
                leaseExpiry = RandLeaseExpiry(t)
51✔
1109
        }
51✔
1110

1111
        return &OpenChannel{
100✔
1112
                ChainHash:        hash,
100✔
1113
                PendingChannelID: pendingChanID,
100✔
1114
                FundingAmount: btcutil.Amount(
100✔
1115
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
100✔
1116
                ),
100✔
1117
                PushAmount: MilliSatoshi(
100✔
1118
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
100✔
1119
                ),
100✔
1120
                DustLimit: btcutil.Amount(
100✔
1121
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
100✔
1122
                ),
100✔
1123
                MaxValueInFlight: MilliSatoshi(
100✔
1124
                        rapid.IntRange(10000, 1000000).Draw(
100✔
1125
                                t, "maxValueInFlight",
100✔
1126
                        ),
100✔
1127
                ),
100✔
1128
                ChannelReserve: btcutil.Amount(
100✔
1129
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
100✔
1130
                ),
100✔
1131
                HtlcMinimum: MilliSatoshi(
100✔
1132
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
100✔
1133
                ),
100✔
1134
                FeePerKiloWeight: uint32(
100✔
1135
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
100✔
1136
                ),
100✔
1137
                CsvDelay: uint16(
100✔
1138
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
100✔
1139
                ),
100✔
1140
                MaxAcceptedHTLCs: uint16(
100✔
1141
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
100✔
1142
                ),
100✔
1143
                FundingKey:            RandPubKey(t),
100✔
1144
                RevocationPoint:       RandPubKey(t),
100✔
1145
                PaymentPoint:          RandPubKey(t),
100✔
1146
                DelayedPaymentPoint:   RandPubKey(t),
100✔
1147
                HtlcPoint:             RandPubKey(t),
100✔
1148
                FirstCommitmentPoint:  RandPubKey(t),
100✔
1149
                ChannelFlags:          channelFlags,
100✔
1150
                UpfrontShutdownScript: RandDeliveryAddress(t),
100✔
1151
                ChannelType:           channelType,
100✔
1152
                LeaseExpiry:           leaseExpiry,
100✔
1153
                LocalNonce:            localNonce,
100✔
1154
                ExtraData:             RandExtraOpaqueData(t, nil),
100✔
1155
        }
100✔
1156
}
1157

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

1162
// RandTestMessage populates the message with random data suitable for testing.
1163
// It uses the rapid testing framework to generate random values.
1164
//
1165
// This is part of the TestMessage interface.
1166
func (p *Ping) RandTestMessage(t *rapid.T) Message {
100✔
1167
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
100✔
1168
                t, "numPongBytes"),
100✔
1169
        )
100✔
1170

100✔
1171
        // Generate padding bytes (but keeping within allowed message size)
100✔
1172
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
100✔
1173
        maxPaddingLen := MaxMsgBody - 4
100✔
1174
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
100✔
1175
                t, "paddingLen",
100✔
1176
        )
100✔
1177
        padding := make(PingPayload, paddingLen)
100✔
1178

100✔
1179
        // Fill padding with random bytes
100✔
1180
        for i := 0; i < paddingLen; i++ {
970,334✔
1181
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
970,234✔
1182
                        t, fmt.Sprintf("paddingByte%d", i)),
970,234✔
1183
                )
970,234✔
1184
        }
970,234✔
1185

1186
        return &Ping{
100✔
1187
                NumPongBytes: numPongBytes,
100✔
1188
                PaddingBytes: padding,
100✔
1189
        }
100✔
1190
}
1191

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

1196
// RandTestMessage populates the message with random data suitable for testing.
1197
// It uses the rapid testing framework to generate random values.
1198
//
1199
// This is part of the TestMessage interface.
1200
func (p *Pong) RandTestMessage(t *rapid.T) Message {
101✔
1201
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
101✔
1202
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
101✔
1203
                t, "pongPayload",
101✔
1204
        )
101✔
1205

101✔
1206
        return &Pong{
101✔
1207
                PongBytes: payload,
101✔
1208
        }
101✔
1209
}
101✔
1210

1211
// A compile time check to ensure QueryChannelRange implements the
1212
// lnwire.TestMessage interface.
1213
var _ TestMessage = (*QueryChannelRange)(nil)
1214

1215
// RandTestMessage populates the message with random data suitable for testing.
1216
// It uses the rapid testing framework to generate random values.
1217
//
1218
// This is part of the TestMessage interface.
1219
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
100✔
1220
        msg := &QueryChannelRange{
100✔
1221
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1222
                        t, "firstBlockHeight"),
100✔
1223
                ),
100✔
1224
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1225
                        t, "numBlocks"),
100✔
1226
                ),
100✔
1227
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1228
        }
100✔
1229

100✔
1230
        // Generate chain hash
100✔
1231
        chainHash := RandChainHash(t)
100✔
1232
        var chainHashObj chainhash.Hash
100✔
1233
        copy(chainHashObj[:], chainHash[:])
100✔
1234
        msg.ChainHash = chainHashObj
100✔
1235

100✔
1236
        // Randomly include QueryOptions
100✔
1237
        if rapid.Bool().Draw(t, "includeQueryOptions") {
153✔
1238
                queryOptions := &QueryOptions{}
53✔
1239
                *queryOptions = QueryOptions(*RandFeatureVector(t))
53✔
1240
                msg.QueryOptions = queryOptions
53✔
1241
        }
53✔
1242

1243
        return msg
100✔
1244
}
1245

1246
// A compile time check to ensure QueryShortChanIDs implements the
1247
// lnwire.TestMessage interface.
1248
var _ TestMessage = (*QueryShortChanIDs)(nil)
1249

1250
// RandTestMessage populates the message with random data suitable for testing.
1251
// It uses the rapid testing framework to generate random values.
1252
//
1253
// This is part of the TestMessage interface.
1254
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
100✔
1255
        var chainHash chainhash.Hash
100✔
1256
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1257
        copy(chainHash[:], hashBytes)
100✔
1258

100✔
1259
        encodingType := EncodingSortedPlain
100✔
1260
        if rapid.Bool().Draw(t, "useZlibEncoding") {
148✔
1261
                encodingType = EncodingSortedZlib
48✔
1262
        }
48✔
1263

1264
        msg := &QueryShortChanIDs{
100✔
1265
                ChainHash:    chainHash,
100✔
1266
                EncodingType: encodingType,
100✔
1267
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1268
                noSort:       false,
100✔
1269
        }
100✔
1270

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

100✔
1273
        // Generate sorted short channel IDs.
100✔
1274
        shortChanIDs := make([]ShortChannelID, numIDs)
100✔
1275
        for i := 0; i < numIDs; i++ {
912✔
1276
                shortChanIDs[i] = RandShortChannelID(t)
812✔
1277

812✔
1278
                // Ensure they're properly sorted.
812✔
1279
                if i > 0 && shortChanIDs[i].ToUint64() <=
812✔
1280
                        shortChanIDs[i-1].ToUint64() {
1,381✔
1281

569✔
1282
                        // Ensure this ID is larger than the previous one.
569✔
1283
                        shortChanIDs[i] = NewShortChanIDFromInt(
569✔
1284
                                shortChanIDs[i-1].ToUint64() + 1,
569✔
1285
                        )
569✔
1286
                }
569✔
1287
        }
1288

1289
        msg.ShortChanIDs = shortChanIDs
100✔
1290

100✔
1291
        return msg
100✔
1292
}
1293

1294
// A compile time check to ensure ReplyChannelRange implements the
1295
// lnwire.TestMessage interface.
1296
var _ TestMessage = (*ReplyChannelRange)(nil)
1297

1298
// RandTestMessage populates the message with random data suitable for testing.
1299
// It uses the rapid testing framework to generate random values.
1300
//
1301
// This is part of the TestMessage interface.
1302
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
100✔
1303
        msg := &ReplyChannelRange{
100✔
1304
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1305
                        t, "firstBlockHeight"),
100✔
1306
                ),
100✔
1307
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1308
                        t, "numBlocks"),
100✔
1309
                ),
100✔
1310
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
100✔
1311
                EncodingType: QueryEncoding(
100✔
1312
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
100✔
1313
                ),
100✔
1314
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1315
        }
100✔
1316

100✔
1317
        msg.ChainHash = RandChainHash(t)
100✔
1318

100✔
1319
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
100✔
1320
        if numShortChanIDs == 0 {
113✔
1321
                return msg
13✔
1322
        }
13✔
1323

1324
        scidSet := fn.NewSet[ShortChannelID]()
87✔
1325
        scids := make([]ShortChannelID, numShortChanIDs)
87✔
1326
        for i := 0; i < numShortChanIDs; i++ {
809✔
1327
                scid := RandShortChannelID(t)
722✔
1328
                for scidSet.Contains(scid) {
810✔
1329
                        scid = RandShortChannelID(t)
88✔
1330
                }
88✔
1331

1332
                scids[i] = scid
722✔
1333

722✔
1334
                scidSet.Add(scid)
722✔
1335
        }
1336

1337
        // Make sure there're no duplicates.
1338
        msg.ShortChanIDs = scids
87✔
1339

87✔
1340
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
120✔
1341
                msg.Timestamps = make(Timestamps, numShortChanIDs)
33✔
1342
                for i := 0; i < numShortChanIDs; i++ {
335✔
1343
                        msg.Timestamps[i] = ChanUpdateTimestamps{
302✔
1344
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
302✔
1345
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
302✔
1346
                        }
302✔
1347
                }
302✔
1348
        }
1349

1350
        return msg
87✔
1351
}
1352

1353
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1354
// lnwire.TestMessage interface.
1355
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1356

1357
// RandTestMessage populates the message with random data suitable for testing.
1358
// It uses the rapid testing framework to generate random values.
1359
//
1360
// This is part of the TestMessage interface.
1361
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
100✔
1362
        var chainHash chainhash.Hash
100✔
1363
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1364
        copy(chainHash[:], hashBytes)
100✔
1365

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

100✔
1368
        return &ReplyShortChanIDsEnd{
100✔
1369
                ChainHash: chainHash,
100✔
1370
                Complete:  complete,
100✔
1371
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1372
        }
100✔
1373
}
100✔
1374

1375
// RandTestMessage returns a RevokeAndAck message populated with random data.
1376
//
1377
// This is part of the TestMessage interface.
1378
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
100✔
1379
        msg := NewRevokeAndAck()
100✔
1380

100✔
1381
        var chanID ChannelID
100✔
1382
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
100✔
1383
        copy(chanID[:], bytes)
100✔
1384
        msg.ChanID = chanID
100✔
1385

100✔
1386
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
100✔
1387
        copy(msg.Revocation[:], revBytes)
100✔
1388

100✔
1389
        msg.NextRevocationKey = RandPubKey(t)
100✔
1390

100✔
1391
        if rapid.Bool().Draw(t, "includeLocalNonce") {
149✔
1392
                var nonce Musig2Nonce
49✔
1393
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
49✔
1394
                        t, "nonce",
49✔
1395
                )
49✔
1396
                copy(nonce[:], nonceBytes)
49✔
1397

49✔
1398
                msg.LocalNonce = tlv.SomeRecordT(
49✔
1399
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
49✔
1400
                )
49✔
1401
        }
49✔
1402

1403
        return msg
100✔
1404
}
1405

1406
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1407
// interface.
1408
var _ TestMessage = (*Shutdown)(nil)
1409

1410
// RandTestMessage populates the message with random data suitable for testing.
1411
// It uses the rapid testing framework to generate random values.
1412
//
1413
// This is part of the TestMessage interface.
1414
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
100✔
1415
        // Generate random delivery address
100✔
1416
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
100✔
1417
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
100✔
1418

100✔
1419
        // Generate random address length based on type
100✔
1420
        var addrLen int
100✔
1421
        switch addrType {
100✔
1422
        // P2PKH
1423
        case 0:
30✔
1424
                addrLen = 25
30✔
1425
        // P2SH
1426
        case 1:
16✔
1427
                addrLen = 23
16✔
1428
        // P2WPKH
1429
        case 2:
18✔
1430
                addrLen = 22
18✔
1431
        // P2WSH
1432
        case 3:
17✔
1433
                addrLen = 34
17✔
1434
        // P2TR
1435
        case 4:
19✔
1436
                addrLen = 34
19✔
1437
        }
1438

1439
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
100✔
1440
                t, "address",
100✔
1441
        )
100✔
1442

100✔
1443
        // Randomly decide whether to include a shutdown nonce
100✔
1444
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
100✔
1445
        var shutdownNonce ShutdownNonceTLV
100✔
1446

100✔
1447
        if includeNonce {
143✔
1448
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
43✔
1449
        }
43✔
1450

1451
        cr, _ := RandCustomRecords(t, nil, true)
100✔
1452

100✔
1453
        return &Shutdown{
100✔
1454
                ChannelID:     RandChannelID(t),
100✔
1455
                Address:       addr,
100✔
1456
                ShutdownNonce: shutdownNonce,
100✔
1457
                CustomRecords: cr,
100✔
1458
        }
100✔
1459
}
1460

1461
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1462
// interface.
1463
var _ TestMessage = (*Stfu)(nil)
1464

1465
// RandTestMessage populates the message with random data suitable for testing.
1466
// It uses the rapid testing framework to generate random values.
1467
//
1468
// This is part of the TestMessage interface.
1469
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
102✔
1470
        m := &Stfu{
102✔
1471
                ChanID:    RandChannelID(t),
102✔
1472
                Initiator: rapid.Bool().Draw(t, "initiator"),
102✔
1473
        }
102✔
1474

102✔
1475
        extraData := RandExtraOpaqueData(t, nil)
102✔
1476
        if len(extraData) > 0 {
181✔
1477
                m.ExtraData = extraData
79✔
1478
        }
79✔
1479

1480
        return m
102✔
1481
}
1482

1483
// A compile time check to ensure UpdateAddHTLC implements the
1484
// lnwire.TestMessage interface.
1485
var _ TestMessage = (*UpdateAddHTLC)(nil)
1486

1487
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1488
//
1489
// This is part of the TestMessage interface.
1490
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1491
        msg := &UpdateAddHTLC{
100✔
1492
                ChanID: RandChannelID(t),
100✔
1493
                ID:     rapid.Uint64().Draw(t, "id"),
100✔
1494
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
100✔
1495
                Expiry: rapid.Uint32().Draw(t, "expiry"),
100✔
1496
        }
100✔
1497

100✔
1498
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
100✔
1499
        copy(msg.PaymentHash[:], hashBytes)
100✔
1500

100✔
1501
        onionBytes := rapid.SliceOfN(
100✔
1502
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
100✔
1503
        ).Draw(t, "onionBlob")
100✔
1504
        copy(msg.OnionBlob[:], onionBytes)
100✔
1505

100✔
1506
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
100✔
1507
        if numRecords > 0 {
185✔
1508
                msg.CustomRecords, _ = RandCustomRecords(t, nil, true)
85✔
1509
        }
85✔
1510

1511
        // 50/50 chance to add a blinding point
1512
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
151✔
1513
                pubKey := RandPubKey(t)
51✔
1514

51✔
1515
                msg.BlindingPoint = tlv.SomeRecordT(
51✔
1516
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
51✔
1517
                )
51✔
1518
        }
51✔
1519

1520
        return msg
100✔
1521
}
1522

1523
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1524
// interface.
1525
var _ TestMessage = (*UpdateFailHTLC)(nil)
1526

1527
// RandTestMessage populates the message with random data suitable for testing.
1528
// It uses the rapid testing framework to generate random values.
1529
//
1530
// This is part of the TestMessage interface.
1531
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1532
        return &UpdateFailHTLC{
100✔
1533
                ChanID:    RandChannelID(t),
100✔
1534
                ID:        rapid.Uint64().Draw(t, "id"),
100✔
1535
                Reason:    RandOpaqueReason(t),
100✔
1536
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1537
        }
100✔
1538
}
100✔
1539

1540
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1541
// TestMessage interface.
1542
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1543

1544
// RandTestMessage populates the message with random data suitable for testing.
1545
// It uses the rapid testing framework to generate random values.
1546
//
1547
// This is part of the TestMessage interface.
1548
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1549
        return &UpdateFailMalformedHTLC{
100✔
1550
                ChanID:       RandChannelID(t),
100✔
1551
                ID:           rapid.Uint64().Draw(t, "id"),
100✔
1552
                ShaOnionBlob: RandSHA256Hash(t),
100✔
1553
                FailureCode:  RandFailCode(t),
100✔
1554
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1555
        }
100✔
1556
}
100✔
1557

1558
// A compile time check to ensure UpdateFee implements the TestMessage
1559
// interface.
1560
var _ TestMessage = (*UpdateFee)(nil)
1561

1562
// RandTestMessage populates the message with random data suitable for testing.
1563
// It uses the rapid testing framework to generate random values.
1564
//
1565
// This is part of the TestMessage interface.
1566
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
100✔
1567
        return &UpdateFee{
100✔
1568
                ChanID:    RandChannelID(t),
100✔
1569
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
100✔
1570
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1571
        }
100✔
1572
}
100✔
1573

1574
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1575
// interface.
1576
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1577

1578
// RandTestMessage populates the message with random data suitable for testing.
1579
// It uses the rapid testing framework to generate random values.
1580
//
1581
// This is part of the TestMessage interface.
1582
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1583
        msg := &UpdateFulfillHTLC{
100✔
1584
                ChanID:          RandChannelID(t),
100✔
1585
                ID:              rapid.Uint64().Draw(t, "id"),
100✔
1586
                PaymentPreimage: RandPaymentPreimage(t),
100✔
1587
        }
100✔
1588

100✔
1589
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
100✔
1590
        msg.CustomRecords = cr
100✔
1591

100✔
1592
        randData := RandExtraOpaqueData(t, ignoreRecords)
100✔
1593
        if len(randData) > 0 {
173✔
1594
                msg.ExtraData = randData
73✔
1595
        }
73✔
1596

1597
        return msg
100✔
1598
}
1599

1600
// A compile time check to ensure Warning implements the lnwire.TestMessage
1601
// interface.
1602
var _ TestMessage = (*Warning)(nil)
1603

1604
// RandTestMessage populates the message with random data suitable for testing.
1605
// It uses the rapid testing framework to generate random values.
1606
//
1607
// This is part of the TestMessage interface.
1608
func (c *Warning) RandTestMessage(t *rapid.T) Message {
109✔
1609
        msg := &Warning{
109✔
1610
                ChanID: RandChannelID(t),
109✔
1611
        }
109✔
1612

109✔
1613
        useASCII := rapid.Bool().Draw(t, "useASCII")
109✔
1614
        if useASCII {
149✔
1615
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
40✔
1616
                data := make([]byte, length)
40✔
1617
                for i := 0; i < length; i++ {
1,367✔
1618
                        data[i] = byte(
1,327✔
1619
                                rapid.IntRange(32, 126).Draw(
1,327✔
1620
                                        t, fmt.Sprintf("warningDataByte-%d", i),
1,327✔
1621
                                ),
1,327✔
1622
                        )
1,327✔
1623
                }
1,327✔
1624
                msg.Data = data
40✔
1625
        } else {
69✔
1626
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
69✔
1627
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
69✔
1628
                        t, "warningData",
69✔
1629
                )
69✔
1630
        }
69✔
1631

1632
        return msg
109✔
1633
}
1634

1635
// A compile time check to ensure Error implements the lnwire.TestMessage
1636
// interface.
1637
var _ TestMessage = (*Error)(nil)
1638

1639
// RandTestMessage populates the message with random data suitable for testing.
1640
// It uses the rapid testing framework to generate random values.
1641
//
1642
// This is part of the TestMessage interface.
1643
func (c *Error) RandTestMessage(t *rapid.T) Message {
101✔
1644
        msg := &Error{
101✔
1645
                ChanID: RandChannelID(t),
101✔
1646
        }
101✔
1647

101✔
1648
        useASCII := rapid.Bool().Draw(t, "useASCII")
101✔
1649
        if useASCII {
149✔
1650
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
48✔
1651
                data := make([]byte, length)
48✔
1652
                for i := 0; i < length; i++ {
1,351✔
1653
                        data[i] = byte(
1,303✔
1654
                                rapid.IntRange(32, 126).Draw(
1,303✔
1655
                                        t, fmt.Sprintf("errorDataByte-%d", i),
1,303✔
1656
                                ),
1,303✔
1657
                        )
1,303✔
1658
                }
1,303✔
1659
                msg.Data = data
48✔
1660
        } else {
53✔
1661
                // Generate random binary data
53✔
1662
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
53✔
1663
                msg.Data = rapid.SliceOfN(
53✔
1664
                        rapid.Byte(), length, length,
53✔
1665
                ).Draw(t, "errorData")
53✔
1666
        }
53✔
1667

1668
        return msg
101✔
1669
}
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