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

lightningnetwork / lnd / 15760549439

19 Jun 2025 02:42PM UTC coverage: 68.141% (-0.02%) from 68.161%
15760549439

push

github

web-flow
Merge pull request #9959 from ellemouton/chanGraphContext2

multi: add context.Context param to more graphdb.V1Store methods

49 of 72 new or added lines in 13 files covered. (68.06%)

118 existing lines in 28 files now uncovered.

134468 of 197337 relevant lines covered (68.14%)

22222.73 hits per line

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

99.75
/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
        "github.com/stretchr/testify/require"
16
        "pgregory.net/rapid"
17
)
18

19
// TestMessage is an interface that extends the base Message interface with a
20
// method to populate the message with random testing data.
21
type TestMessage interface {
22
        Message
23

24
        // RandTestMessage populates the message with random data suitable for
25
        // testing. It uses the rapid testing framework to generate random
26
        // values.
27
        RandTestMessage(t *rapid.T) Message
28
}
29

30
// A compile time check to ensure AcceptChannel implements the TestMessage
31
// interface.
32
var _ TestMessage = (*AcceptChannel)(nil)
33

34
// RandTestMessage populates the message with random data suitable for testing.
35
// It uses the rapid testing framework to generate random values.
36
//
37
// This is part of the TestMessage interface.
38
func (a *AcceptChannel) RandTestMessage(t *rapid.T) Message {
100✔
39
        var pendingChanID [32]byte
100✔
40
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
41
                t, "pendingChanID",
100✔
42
        )
100✔
43
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
44

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

100✔
50
        if includeChannelType {
150✔
51
                channelType = RandChannelType(t)
50✔
52
        }
50✔
53

54
        var leaseExpiry *LeaseExpiry
100✔
55
        if includeLeaseExpiry {
151✔
56
                leaseExpiry = RandLeaseExpiry(t)
51✔
57
        }
51✔
58

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

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

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

110
// RandTestMessage populates the message with random data suitable for testing.
111
// It uses the rapid testing framework to generate random values.
112
//
113
// This is part of the TestMessage interface.
114
func (a *AnnounceSignatures1) RandTestMessage(t *rapid.T) Message {
100✔
115
        return &AnnounceSignatures1{
100✔
116
                ChannelID:        RandChannelID(t),
100✔
117
                ShortChannelID:   RandShortChannelID(t),
100✔
118
                NodeSignature:    RandSignature(t),
100✔
119
                BitcoinSignature: RandSignature(t),
100✔
120
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
100✔
121
        }
100✔
122
}
100✔
123

124
// A compile time check to ensure AnnounceSignatures2 implements the
125
// lnwire.TestMessage interface.
126
var _ TestMessage = (*AnnounceSignatures2)(nil)
127

128
// RandTestMessage populates the message with random data suitable for testing.
129
// It uses the rapid testing framework to generate random values.
130
//
131
// This is part of the TestMessage interface.
132
func (a *AnnounceSignatures2) RandTestMessage(t *rapid.T) Message {
100✔
133
        return &AnnounceSignatures2{
100✔
134
                ChannelID:        RandChannelID(t),
100✔
135
                ShortChannelID:   RandShortChannelID(t),
100✔
136
                PartialSignature: *RandPartialSig(t),
100✔
137
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
100✔
138
        }
100✔
139
}
100✔
140

141
// A compile time check to ensure ChannelAnnouncement1 implements the
142
// TestMessage interface.
143
var _ TestMessage = (*ChannelAnnouncement1)(nil)
144

145
// RandTestMessage populates the message with random data suitable for testing.
146
// It uses the rapid testing framework to generate random values.
147
//
148
// This is part of the TestMessage interface.
149
func (a *ChannelAnnouncement1) RandTestMessage(t *rapid.T) Message {
100✔
150
        // Generate Node IDs and Bitcoin keys (compressed public keys)
100✔
151
        node1PubKey := RandPubKey(t)
100✔
152
        node2PubKey := RandPubKey(t)
100✔
153
        bitcoin1PubKey := RandPubKey(t)
100✔
154
        bitcoin2PubKey := RandPubKey(t)
100✔
155

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

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

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

100✔
174
        return &ChannelAnnouncement1{
100✔
175
                NodeSig1:        RandSignature(t),
100✔
176
                NodeSig2:        RandSignature(t),
100✔
177
                BitcoinSig1:     RandSignature(t),
100✔
178
                BitcoinSig2:     RandSignature(t),
100✔
179
                Features:        RandFeatureVector(t),
100✔
180
                ChainHash:       hash,
100✔
181
                ShortChannelID:  RandShortChannelID(t),
100✔
182
                NodeID1:         nodeID1,
100✔
183
                NodeID2:         nodeID2,
100✔
184
                BitcoinKey1:     bitcoinKey1,
100✔
185
                BitcoinKey2:     bitcoinKey2,
100✔
186
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
187
        }
100✔
188
}
189

190
// A compile time check to ensure ChannelAnnouncement2 implements the
191
// lnwire.TestMessage interface.
192
var _ TestMessage = (*ChannelAnnouncement2)(nil)
193

194
// RandTestMessage populates the message with random data suitable for testing.
195
// It uses the rapid testing framework to generate random values.
196
//
197
// This is part of the TestMessage interface.
198
func (c *ChannelAnnouncement2) RandTestMessage(t *rapid.T) Message {
100✔
199
        features := RandFeatureVector(t)
100✔
200
        shortChanID := RandShortChannelID(t)
100✔
201
        capacity := uint64(rapid.IntRange(1, 16777215).Draw(t, "capacity"))
100✔
202

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

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

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

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

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

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

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

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

273
        return msg
100✔
274
}
275

276
// A compile time check to ensure ChannelReady implements the lnwire.TestMessage
277
// interface.
278
var _ TestMessage = (*ChannelReady)(nil)
279

280
// RandTestMessage populates the message with random data suitable for testing.
281
// It uses the rapid testing framework to generate random values.
282
//
283
// This is part of the TestMessage interface.
284
func (c *ChannelReady) RandTestMessage(t *rapid.T) Message {
100✔
285
        msg := &ChannelReady{
100✔
286
                ChanID:                 RandChannelID(t),
100✔
287
                NextPerCommitmentPoint: RandPubKey(t),
100✔
288
                ExtraData:              RandExtraOpaqueData(t, nil),
100✔
289
        }
100✔
290

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

100✔
300
        if includeAliasScid {
147✔
301
                scid := RandShortChannelID(t)
47✔
302
                msg.AliasScid = &scid
47✔
303
        }
47✔
304

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

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

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

324
        return msg
100✔
325
}
326

327
// A compile time check to ensure ChannelReestablish implements the
328
// lnwire.TestMessage interface.
329
var _ TestMessage = (*ChannelReestablish)(nil)
330

331
// RandTestMessage populates the message with random data suitable for testing.
332
// It uses the rapid testing framework to generate random values.
333
//
334
// This is part of the TestMessage interface.
335
func (a *ChannelReestablish) RandTestMessage(t *rapid.T) Message {
100✔
336
        msg := &ChannelReestablish{
100✔
337
                ChanID: RandChannelID(t),
100✔
338
                NextLocalCommitHeight: rapid.Uint64().Draw(
100✔
339
                        t, "nextLocalCommitHeight",
100✔
340
                ),
100✔
341
                RemoteCommitTailHeight: rapid.Uint64().Draw(
100✔
342
                        t, "remoteCommitTailHeight",
100✔
343
                ),
100✔
344
                LastRemoteCommitSecret:    RandPaymentPreimage(t),
100✔
345
                LocalUnrevokedCommitPoint: RandPubKey(t),
100✔
346
                ExtraData:                 RandExtraOpaqueData(t, nil),
100✔
347
        }
100✔
348

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

100✔
353
        if includeLocalNonce {
153✔
354
                nonce := RandMusig2Nonce(t)
53✔
355
                msg.LocalNonce = SomeMusig2Nonce(nonce)
53✔
356
        }
53✔
357

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

363
        return msg
100✔
364
}
365

366
// A compile time check to ensure ChannelUpdate1 implements the TestMessage
367
// interface.
368
var _ TestMessage = (*ChannelUpdate1)(nil)
369

370
// RandTestMessage populates the message with random data suitable for testing.
371
// It uses the rapid testing framework to generate random values.
372
//
373
// This is part of the TestMessage interface.
374
func (a *ChannelUpdate1) RandTestMessage(t *rapid.T) Message {
100✔
375
        // Generate random message flags
100✔
376
        // Randomly decide whether to include max HTLC field
100✔
377
        includeMaxHtlc := rapid.Bool().Draw(t, "includeMaxHtlc")
100✔
378
        var msgFlags ChanUpdateMsgFlags
100✔
379
        if includeMaxHtlc {
156✔
380
                msgFlags |= ChanUpdateRequiredMaxHtlc
56✔
381
        }
56✔
382

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

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

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

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

100✔
405
        // If max HTLC flag is not set, we need to zero the value
100✔
406
        if !includeMaxHtlc {
144✔
407
                maxHtlc = 0
44✔
408
        }
44✔
409

410
        // Randomly decide if an inbound fee should be included.
411
        // By default, our extra opaque data will just be random TLV but if we
412
        // include an inbound fee, then we will also set the record in the
413
        // extra opaque data.
414
        var (
100✔
415
                customRecords, _ = RandCustomRecords(t, nil, false)
100✔
416
                inboundFee       tlv.OptionalRecordT[tlv.TlvType55555, Fee]
100✔
417
        )
100✔
418
        includeInboundFee := rapid.Bool().Draw(t, "includeInboundFee")
100✔
419
        if includeInboundFee {
155✔
420
                if customRecords == nil {
66✔
421
                        customRecords = make(CustomRecords)
11✔
422
                }
11✔
423

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

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

55✔
443
                customRecords[uint64(FeeRecordType)] = b.Bytes()
55✔
444
        }
445

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

100✔
449
        return &ChannelUpdate1{
100✔
450
                Signature:      RandSignature(t),
100✔
451
                ChainHash:      hash,
100✔
452
                ShortChannelID: RandShortChannelID(t),
100✔
453
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
454
                        t, "timestamp"),
100✔
455
                ),
100✔
456
                MessageFlags: msgFlags,
100✔
457
                ChannelFlags: chanFlags,
100✔
458
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
100✔
459
                        t, "timelockDelta"),
100✔
460
                ),
100✔
461
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
100✔
462
                        t, "htlcMinimum"),
100✔
463
                ),
100✔
464
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
465
                        t, "baseFee"),
100✔
466
                ),
100✔
467
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
468
                        t, "feeRate"),
100✔
469
                ),
100✔
470
                HtlcMaximumMsat: maxHtlc,
100✔
471
                InboundFee:      inboundFee,
100✔
472
                ExtraOpaqueData: extraBytes,
100✔
473
        }
100✔
474
}
475

476
// A compile time check to ensure ChannelUpdate2 implements the
477
// lnwire.TestMessage interface.
478
var _ TestMessage = (*ChannelUpdate2)(nil)
479

480
// RandTestMessage populates the message with random data suitable for testing.
481
// It uses the rapid testing framework to generate random values.
482
//
483
// This is part of the TestMessage interface.
484
func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
100✔
485
        shortChanID := RandShortChannelID(t)
100✔
486
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
100✔
487

100✔
488
        var disabledFlags ChanUpdateDisableFlags
100✔
489
        if rapid.Bool().Draw(t, "disableIncoming") {
146✔
490
                disabledFlags |= ChanUpdateDisableIncoming
46✔
491
        }
46✔
492
        if rapid.Bool().Draw(t, "disableOutgoing") {
143✔
493
                disabledFlags |= ChanUpdateDisableOutgoing
43✔
494
        }
43✔
495

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

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

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

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

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

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

556
        return msg
100✔
557
}
558

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

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

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

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

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

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

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

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

622
        return msg
100✔
623
}
624

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

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

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

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

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

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

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

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

682
        return msg
100✔
683
}
684

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

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

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

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

49✔
714
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
49✔
715
                msg.Signature = Sig{}
49✔
716
        } else {
100✔
717
                msg.Signature = RandSignature(t)
51✔
718
        }
51✔
719

720
        return msg
100✔
721
}
722

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

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

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

745
        if len(htlcSigs) > 0 {
188✔
746
                sig.HtlcSigs = htlcSigs
88✔
747
        }
88✔
748

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

755
        return sig
100✔
756
}
757

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

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

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

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

783
        return msg
11✔
784
}
785

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

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

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

100✔
802
        if includeLocalNonce {
150✔
803
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
50✔
804
        }
50✔
805

806
        return msg
100✔
807
}
808

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

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

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

101✔
838
        // Generate random values for each included field
101✔
839
        if includeDustLimit {
151✔
840
                dl := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
50✔
841
                msg.DustLimit = fn.Some(dl)
50✔
842
        }
50✔
843

844
        if includeMaxValueInFlight {
151✔
845
                mvif := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
50✔
846
                msg.MaxValueInFlight = fn.Some(mvif)
50✔
847
        }
50✔
848

849
        if includeChannelReserve {
153✔
850
                cr := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
52✔
851
                msg.ChannelReserve = fn.Some(cr)
52✔
852
        }
52✔
853

854
        if includeCsvDelay {
147✔
855
                cd := rapid.Uint16().Draw(t, "csvDelay")
46✔
856
                msg.CsvDelay = fn.Some(cd)
46✔
857
        }
46✔
858

859
        if includeMaxAcceptedHTLCs {
163✔
860
                mah := rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
62✔
861
                msg.MaxAcceptedHTLCs = fn.Some(mah)
62✔
862
        }
62✔
863

864
        if includeFundingKey {
153✔
865
                msg.FundingKey = fn.Some(*RandPubKey(t))
52✔
866
        }
52✔
867

868
        if includeChannelType {
157✔
869
                msg.ChannelType = fn.Some(*RandChannelType(t))
56✔
870
        }
56✔
871

872
        if includeKickoffFeerate {
152✔
873
                kf := chainfee.SatPerKWeight(rapid.Uint32().Draw(
51✔
874
                        t, "kickoffFeerate"),
51✔
875
                )
51✔
876
                msg.KickoffFeerate = fn.Some(kf)
51✔
877
        }
51✔
878

879
        return msg
101✔
880
}
881

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

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

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

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

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

916
// A compile time check to ensure FundingCreated implements the TestMessage
917
// interface.
918
var _ TestMessage = (*FundingCreated)(nil)
919

920
// RandTestMessage populates the message with random data suitable for testing.
921
// It uses the rapid testing framework to generate random values.
922
//
923
// This is part of the TestMessage interface.
924
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
101✔
925
        var pendingChanID [32]byte
101✔
926
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
101✔
927
                t, "pendingChanID",
101✔
928
        )
101✔
929
        copy(pendingChanID[:], pendingChanIDBytes)
101✔
930

101✔
931
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
101✔
932
        var partialSig OptPartialSigWithNonceTLV
101✔
933
        var commitSig Sig
101✔
934

101✔
935
        if includePartialSig {
153✔
936
                sigWithNonce := RandPartialSigWithNonce(t)
52✔
937
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
52✔
938

52✔
939
                // When using partial sig, CommitSig should be empty/blank.
52✔
940
                commitSig = Sig{}
52✔
941
        } else {
101✔
942
                commitSig = RandSignature(t)
49✔
943
        }
49✔
944

945
        return &FundingCreated{
101✔
946
                PendingChannelID: pendingChanID,
101✔
947
                FundingPoint:     RandOutPoint(t),
101✔
948
                CommitSig:        commitSig,
101✔
949
                PartialSig:       partialSig,
101✔
950
                ExtraData:        RandExtraOpaqueData(t, nil),
101✔
951
        }
101✔
952
}
953

954
// A compile time check to ensure FundingSigned implements the
955
// lnwire.TestMessage interface.
956
var _ TestMessage = (*FundingSigned)(nil)
957

958
// RandTestMessage populates the message with random data suitable for testing.
959
// It uses the rapid testing framework to generate random values.
960
//
961
// This is part of the TestMessage interface.
962
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
100✔
963
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
100✔
964

100✔
965
        msg := &FundingSigned{
100✔
966
                ChanID:    RandChannelID(t),
100✔
967
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
968
        }
100✔
969

100✔
970
        if usePartialSig {
146✔
971
                sigWithNonce := RandPartialSigWithNonce(t)
46✔
972
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
46✔
973

46✔
974
                msg.CommitSig = Sig{}
46✔
975
        } else {
100✔
976
                msg.CommitSig = RandSignature(t)
54✔
977
        }
54✔
978

979
        return msg
100✔
980
}
981

982
// A compile time check to ensure GossipTimestampRange implements the
983
// lnwire.TestMessage interface.
984
var _ TestMessage = (*GossipTimestampRange)(nil)
985

986
// RandTestMessage populates the message with random data suitable for testing.
987
// It uses the rapid testing framework to generate random values.
988
//
989
// This is part of the TestMessage interface.
990
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
100✔
991
        var chainHash chainhash.Hash
100✔
992
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
993
        copy(chainHash[:], hashBytes)
100✔
994

100✔
995
        msg := &GossipTimestampRange{
100✔
996
                ChainHash:      chainHash,
100✔
997
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
100✔
998
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
100✔
999
                ExtraData:      RandExtraOpaqueData(t, nil),
100✔
1000
        }
100✔
1001

100✔
1002
        includeFirstBlockHeight := rapid.Bool().Draw(
100✔
1003
                t, "includeFirstBlockHeight",
100✔
1004
        )
100✔
1005
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
100✔
1006

100✔
1007
        if includeFirstBlockHeight {
144✔
1008
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
44✔
1009
                msg.FirstBlockHeight = tlv.SomeRecordT(
44✔
1010
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
44✔
1011
                )
44✔
1012
        }
44✔
1013

1014
        if includeBlockRange {
150✔
1015
                blockRange := rapid.Uint32().Draw(t, "blockRange")
50✔
1016
                msg.BlockRange = tlv.SomeRecordT(
50✔
1017
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
50✔
1018
                )
50✔
1019
        }
50✔
1020

1021
        return msg
100✔
1022
}
1023

1024
// RandTestMessage populates the message with random data suitable for testing.
1025
// It uses the rapid testing framework to generate random values.
1026
//
1027
// This is part of the TestMessage interface.
1028
func (msg *Init) RandTestMessage(t *rapid.T) Message {
100✔
1029
        global := NewRawFeatureVector()
100✔
1030
        local := NewRawFeatureVector()
100✔
1031

100✔
1032
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
100✔
1033
        for i := 0; i < numGlobalFeatures; i++ {
996✔
1034
                bit := FeatureBit(
896✔
1035
                        rapid.IntRange(0, 100).Draw(
896✔
1036
                                t, fmt.Sprintf("globalFeatureBit%d", i),
896✔
1037
                        ),
896✔
1038
                )
896✔
1039
                global.Set(bit)
896✔
1040
        }
896✔
1041

1042
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
100✔
1043
        for i := 0; i < numLocalFeatures; i++ {
818✔
1044
                bit := FeatureBit(
718✔
1045
                        rapid.IntRange(0, 100).Draw(
718✔
1046
                                t, fmt.Sprintf("localFeatureBit%d", i),
718✔
1047
                        ),
718✔
1048
                )
718✔
1049
                local.Set(bit)
718✔
1050
        }
718✔
1051

1052
        return NewInitMessage(global, local)
100✔
1053
}
1054

1055
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1056
// interface.
1057
var _ TestMessage = (*KickoffSig)(nil)
1058

1059
// RandTestMessage populates the message with random data suitable for testing.
1060
// It uses the rapid testing framework to generate random values.
1061
//
1062
// This is part of the TestMessage interface.
1063
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
100✔
1064
        return &KickoffSig{
100✔
1065
                ChanID:    RandChannelID(t),
100✔
1066
                Signature: RandSignature(t),
100✔
1067
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1068
        }
100✔
1069
}
100✔
1070

1071
// A compile time check to ensure NodeAnnouncement implements the
1072
// lnwire.TestMessage interface.
1073
var _ TestMessage = (*NodeAnnouncement)(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 (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
100✔
1080
        // Generate random compressed public key for node ID
100✔
1081
        pubKey := RandPubKey(t)
100✔
1082
        var nodeID [33]byte
100✔
1083
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1084

100✔
1085
        // Generate random RGB color
100✔
1086
        rgbColor := color.RGBA{
100✔
1087
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
100✔
1088
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
100✔
1089
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
100✔
1090
        }
100✔
1091

100✔
1092
        return &NodeAnnouncement{
100✔
1093
                Signature: RandSignature(t),
100✔
1094
                Features:  RandFeatureVector(t),
100✔
1095
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
100✔
1096
                        t, "timestamp"),
100✔
1097
                ),
100✔
1098
                NodeID:          nodeID,
100✔
1099
                RGBColor:        rgbColor,
100✔
1100
                Alias:           RandNodeAlias(t),
100✔
1101
                Addresses:       RandNetAddrs(t),
100✔
1102
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
100✔
1103
        }
100✔
1104
}
100✔
1105

1106
// A compile time check to ensure OpenChannel implements the TestMessage
1107
// interface.
1108
var _ TestMessage = (*OpenChannel)(nil)
1109

1110
// RandTestMessage populates the message with random data suitable for testing.
1111
// It uses the rapid testing framework to generate random values.
1112
//
1113
// This is part of the TestMessage interface.
1114
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
100✔
1115
        chainHash := RandChainHash(t)
100✔
1116
        var hash chainhash.Hash
100✔
1117
        copy(hash[:], chainHash[:])
100✔
1118

100✔
1119
        var pendingChanID [32]byte
100✔
1120
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
100✔
1121
                t, "pendingChanID",
100✔
1122
        )
100✔
1123
        copy(pendingChanID[:], pendingChanIDBytes)
100✔
1124

100✔
1125
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
100✔
1126
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
100✔
1127
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
100✔
1128

100✔
1129
        var channelFlags FundingFlag
100✔
1130
        if rapid.Bool().Draw(t, "announceChannel") {
151✔
1131
                channelFlags |= FFAnnounceChannel
51✔
1132
        }
51✔
1133

1134
        var localNonce OptMusig2NonceTLV
100✔
1135
        if includeLocalNonce {
146✔
1136
                nonce := RandMusig2Nonce(t)
46✔
1137
                localNonce = tlv.SomeRecordT(
46✔
1138
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
46✔
1139
                )
46✔
1140
        }
46✔
1141

1142
        var channelType *ChannelType
100✔
1143
        if includeChannelType {
148✔
1144
                channelType = RandChannelType(t)
48✔
1145
        }
48✔
1146

1147
        var leaseExpiry *LeaseExpiry
100✔
1148
        if includeLeaseExpiry {
149✔
1149
                leaseExpiry = RandLeaseExpiry(t)
49✔
1150
        }
49✔
1151

1152
        return &OpenChannel{
100✔
1153
                ChainHash:        hash,
100✔
1154
                PendingChannelID: pendingChanID,
100✔
1155
                FundingAmount: btcutil.Amount(
100✔
1156
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
100✔
1157
                ),
100✔
1158
                PushAmount: MilliSatoshi(
100✔
1159
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
100✔
1160
                ),
100✔
1161
                DustLimit: btcutil.Amount(
100✔
1162
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
100✔
1163
                ),
100✔
1164
                MaxValueInFlight: MilliSatoshi(
100✔
1165
                        rapid.IntRange(10000, 1000000).Draw(
100✔
1166
                                t, "maxValueInFlight",
100✔
1167
                        ),
100✔
1168
                ),
100✔
1169
                ChannelReserve: btcutil.Amount(
100✔
1170
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
100✔
1171
                ),
100✔
1172
                HtlcMinimum: MilliSatoshi(
100✔
1173
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
100✔
1174
                ),
100✔
1175
                FeePerKiloWeight: uint32(
100✔
1176
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
100✔
1177
                ),
100✔
1178
                CsvDelay: uint16(
100✔
1179
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
100✔
1180
                ),
100✔
1181
                MaxAcceptedHTLCs: uint16(
100✔
1182
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
100✔
1183
                ),
100✔
1184
                FundingKey:            RandPubKey(t),
100✔
1185
                RevocationPoint:       RandPubKey(t),
100✔
1186
                PaymentPoint:          RandPubKey(t),
100✔
1187
                DelayedPaymentPoint:   RandPubKey(t),
100✔
1188
                HtlcPoint:             RandPubKey(t),
100✔
1189
                FirstCommitmentPoint:  RandPubKey(t),
100✔
1190
                ChannelFlags:          channelFlags,
100✔
1191
                UpfrontShutdownScript: RandDeliveryAddress(t),
100✔
1192
                ChannelType:           channelType,
100✔
1193
                LeaseExpiry:           leaseExpiry,
100✔
1194
                LocalNonce:            localNonce,
100✔
1195
                ExtraData:             RandExtraOpaqueData(t, nil),
100✔
1196
        }
100✔
1197
}
1198

1199
// A compile time check to ensure Ping implements the lnwire.TestMessage
1200
// interface.
1201
var _ TestMessage = (*Ping)(nil)
1202

1203
// RandTestMessage populates the message with random data suitable for testing.
1204
// It uses the rapid testing framework to generate random values.
1205
//
1206
// This is part of the TestMessage interface.
1207
func (p *Ping) RandTestMessage(t *rapid.T) Message {
100✔
1208
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
100✔
1209
                t, "numPongBytes"),
100✔
1210
        )
100✔
1211

100✔
1212
        // Generate padding bytes (but keeping within allowed message size)
100✔
1213
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
100✔
1214
        maxPaddingLen := MaxMsgBody - 4
100✔
1215
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
100✔
1216
                t, "paddingLen",
100✔
1217
        )
100✔
1218
        padding := make(PingPayload, paddingLen)
100✔
1219

100✔
1220
        // Fill padding with random bytes
100✔
1221
        for i := 0; i < paddingLen; i++ {
1,223,696✔
1222
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
1,223,596✔
1223
                        t, fmt.Sprintf("paddingByte%d", i)),
1,223,596✔
1224
                )
1,223,596✔
1225
        }
1,223,596✔
1226

1227
        return &Ping{
100✔
1228
                NumPongBytes: numPongBytes,
100✔
1229
                PaddingBytes: padding,
100✔
1230
        }
100✔
1231
}
1232

1233
// A compile time check to ensure Pong implements the lnwire.TestMessage
1234
// interface.
1235
var _ TestMessage = (*Pong)(nil)
1236

1237
// RandTestMessage populates the message with random data suitable for testing.
1238
// It uses the rapid testing framework to generate random values.
1239
//
1240
// This is part of the TestMessage interface.
1241
func (p *Pong) RandTestMessage(t *rapid.T) Message {
100✔
1242
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
100✔
1243
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
100✔
1244
                t, "pongPayload",
100✔
1245
        )
100✔
1246

100✔
1247
        return &Pong{
100✔
1248
                PongBytes: payload,
100✔
1249
        }
100✔
1250
}
100✔
1251

1252
// A compile time check to ensure QueryChannelRange implements the
1253
// lnwire.TestMessage interface.
1254
var _ TestMessage = (*QueryChannelRange)(nil)
1255

1256
// RandTestMessage populates the message with random data suitable for testing.
1257
// It uses the rapid testing framework to generate random values.
1258
//
1259
// This is part of the TestMessage interface.
1260
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
100✔
1261
        msg := &QueryChannelRange{
100✔
1262
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
100✔
1263
                        t, "firstBlockHeight"),
100✔
1264
                ),
100✔
1265
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
100✔
1266
                        t, "numBlocks"),
100✔
1267
                ),
100✔
1268
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1269
        }
100✔
1270

100✔
1271
        // Generate chain hash
100✔
1272
        chainHash := RandChainHash(t)
100✔
1273
        var chainHashObj chainhash.Hash
100✔
1274
        copy(chainHashObj[:], chainHash[:])
100✔
1275
        msg.ChainHash = chainHashObj
100✔
1276

100✔
1277
        // Randomly include QueryOptions
100✔
1278
        if rapid.Bool().Draw(t, "includeQueryOptions") {
145✔
1279
                queryOptions := &QueryOptions{}
45✔
1280
                *queryOptions = QueryOptions(*RandFeatureVector(t))
45✔
1281
                msg.QueryOptions = queryOptions
45✔
1282
        }
45✔
1283

1284
        return msg
100✔
1285
}
1286

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

1291
// RandTestMessage populates the message with random data suitable for testing.
1292
// It uses the rapid testing framework to generate random values.
1293
//
1294
// This is part of the TestMessage interface.
1295
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
101✔
1296
        var chainHash chainhash.Hash
101✔
1297
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
101✔
1298
        copy(chainHash[:], hashBytes)
101✔
1299

101✔
1300
        encodingType := EncodingSortedPlain
101✔
1301
        if rapid.Bool().Draw(t, "useZlibEncoding") {
140✔
1302
                encodingType = EncodingSortedZlib
39✔
1303
        }
39✔
1304

1305
        msg := &QueryShortChanIDs{
101✔
1306
                ChainHash:    chainHash,
101✔
1307
                EncodingType: encodingType,
101✔
1308
                ExtraData:    RandExtraOpaqueData(t, nil),
101✔
1309
                noSort:       false,
101✔
1310
        }
101✔
1311

101✔
1312
        numIDs := rapid.IntRange(2, 20).Draw(t, "numShortChanIDs")
101✔
1313

101✔
1314
        // Generate sorted short channel IDs.
101✔
1315
        shortChanIDs := make([]ShortChannelID, numIDs)
101✔
1316
        for i := 0; i < numIDs; i++ {
1,098✔
1317
                shortChanIDs[i] = RandShortChannelID(t)
997✔
1318

997✔
1319
                // Ensure they're properly sorted.
997✔
1320
                if i > 0 && shortChanIDs[i].ToUint64() <=
997✔
1321
                        shortChanIDs[i-1].ToUint64() {
1,727✔
1322

730✔
1323
                        // Ensure this ID is larger than the previous one.
730✔
1324
                        shortChanIDs[i] = NewShortChanIDFromInt(
730✔
1325
                                shortChanIDs[i-1].ToUint64() + 1,
730✔
1326
                        )
730✔
1327
                }
730✔
1328
        }
1329

1330
        msg.ShortChanIDs = shortChanIDs
101✔
1331

101✔
1332
        return msg
101✔
1333
}
1334

1335
// A compile time check to ensure ReplyChannelRange implements the
1336
// lnwire.TestMessage interface.
1337
var _ TestMessage = (*ReplyChannelRange)(nil)
1338

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

100✔
1358
        msg.ChainHash = RandChainHash(t)
100✔
1359

100✔
1360
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
100✔
1361
        if numShortChanIDs == 0 {
114✔
1362
                return msg
14✔
1363
        }
14✔
1364

1365
        scidSet := fn.NewSet[ShortChannelID]()
86✔
1366
        scids := make([]ShortChannelID, numShortChanIDs)
86✔
1367
        for i := 0; i < numShortChanIDs; i++ {
836✔
1368
                scid := RandShortChannelID(t)
750✔
1369
                for scidSet.Contains(scid) {
849✔
1370
                        scid = RandShortChannelID(t)
99✔
1371
                }
99✔
1372

1373
                scids[i] = scid
750✔
1374

750✔
1375
                scidSet.Add(scid)
750✔
1376
        }
1377

1378
        // Make sure there're no duplicates.
1379
        msg.ShortChanIDs = scids
86✔
1380

86✔
1381
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
132✔
1382
                msg.Timestamps = make(Timestamps, numShortChanIDs)
46✔
1383
                for i := 0; i < numShortChanIDs; i++ {
476✔
1384
                        msg.Timestamps[i] = ChanUpdateTimestamps{
430✔
1385
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
430✔
1386
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
430✔
1387
                        }
430✔
1388
                }
430✔
1389
        }
1390

1391
        return msg
86✔
1392
}
1393

1394
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1395
// lnwire.TestMessage interface.
1396
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1397

1398
// RandTestMessage populates the message with random data suitable for testing.
1399
// It uses the rapid testing framework to generate random values.
1400
//
1401
// This is part of the TestMessage interface.
1402
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
100✔
1403
        var chainHash chainhash.Hash
100✔
1404
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
100✔
1405
        copy(chainHash[:], hashBytes)
100✔
1406

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

100✔
1409
        return &ReplyShortChanIDsEnd{
100✔
1410
                ChainHash: chainHash,
100✔
1411
                Complete:  complete,
100✔
1412
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1413
        }
100✔
1414
}
100✔
1415

1416
// RandTestMessage returns a RevokeAndAck message populated with random data.
1417
//
1418
// This is part of the TestMessage interface.
1419
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
100✔
1420
        msg := NewRevokeAndAck()
100✔
1421

100✔
1422
        var chanID ChannelID
100✔
1423
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
100✔
1424
        copy(chanID[:], bytes)
100✔
1425
        msg.ChanID = chanID
100✔
1426

100✔
1427
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
100✔
1428
        copy(msg.Revocation[:], revBytes)
100✔
1429

100✔
1430
        msg.NextRevocationKey = RandPubKey(t)
100✔
1431

100✔
1432
        if rapid.Bool().Draw(t, "includeLocalNonce") {
157✔
1433
                var nonce Musig2Nonce
57✔
1434
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
57✔
1435
                        t, "nonce",
57✔
1436
                )
57✔
1437
                copy(nonce[:], nonceBytes)
57✔
1438

57✔
1439
                msg.LocalNonce = tlv.SomeRecordT(
57✔
1440
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
57✔
1441
                )
57✔
1442
        }
57✔
1443

1444
        return msg
100✔
1445
}
1446

1447
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1448
// interface.
1449
var _ TestMessage = (*Shutdown)(nil)
1450

1451
// RandTestMessage populates the message with random data suitable for testing.
1452
// It uses the rapid testing framework to generate random values.
1453
//
1454
// This is part of the TestMessage interface.
1455
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
100✔
1456
        // Generate random delivery address
100✔
1457
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
100✔
1458
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
100✔
1459

100✔
1460
        // Generate random address length based on type
100✔
1461
        var addrLen int
100✔
1462
        switch addrType {
100✔
1463
        // P2PKH
1464
        case 0:
35✔
1465
                addrLen = 25
35✔
1466
        // P2SH
1467
        case 1:
32✔
1468
                addrLen = 23
32✔
1469
        // P2WPKH
1470
        case 2:
12✔
1471
                addrLen = 22
12✔
1472
        // P2WSH
1473
        case 3:
13✔
1474
                addrLen = 34
13✔
1475
        // P2TR
1476
        case 4:
8✔
1477
                addrLen = 34
8✔
1478
        }
1479

1480
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
100✔
1481
                t, "address",
100✔
1482
        )
100✔
1483

100✔
1484
        // Randomly decide whether to include a shutdown nonce
100✔
1485
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
100✔
1486
        var shutdownNonce ShutdownNonceTLV
100✔
1487

100✔
1488
        if includeNonce {
149✔
1489
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
49✔
1490
        }
49✔
1491

1492
        cr, _ := RandCustomRecords(t, nil, true)
100✔
1493

100✔
1494
        return &Shutdown{
100✔
1495
                ChannelID:     RandChannelID(t),
100✔
1496
                Address:       addr,
100✔
1497
                ShutdownNonce: shutdownNonce,
100✔
1498
                CustomRecords: cr,
100✔
1499
        }
100✔
1500
}
1501

1502
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1503
// interface.
1504
var _ TestMessage = (*Stfu)(nil)
1505

1506
// RandTestMessage populates the message with random data suitable for testing.
1507
// It uses the rapid testing framework to generate random values.
1508
//
1509
// This is part of the TestMessage interface.
1510
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
105✔
1511
        m := &Stfu{
105✔
1512
                ChanID:    RandChannelID(t),
105✔
1513
                Initiator: rapid.Bool().Draw(t, "initiator"),
105✔
1514
        }
105✔
1515

105✔
1516
        extraData := RandExtraOpaqueData(t, nil)
105✔
1517
        if len(extraData) > 0 {
190✔
1518
                m.ExtraData = extraData
85✔
1519
        }
85✔
1520

1521
        return m
105✔
1522
}
1523

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

1528
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1529
//
1530
// This is part of the TestMessage interface.
1531
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1532
        msg := &UpdateAddHTLC{
100✔
1533
                ChanID: RandChannelID(t),
100✔
1534
                ID:     rapid.Uint64().Draw(t, "id"),
100✔
1535
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
100✔
1536
                Expiry: rapid.Uint32().Draw(t, "expiry"),
100✔
1537
        }
100✔
1538

100✔
1539
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
100✔
1540
        copy(msg.PaymentHash[:], hashBytes)
100✔
1541

100✔
1542
        onionBytes := rapid.SliceOfN(
100✔
1543
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
100✔
1544
        ).Draw(t, "onionBlob")
100✔
1545
        copy(msg.OnionBlob[:], onionBytes)
100✔
1546

100✔
1547
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
100✔
1548
        if numRecords > 0 {
177✔
1549
                msg.CustomRecords, _ = RandCustomRecords(t, nil, true)
77✔
1550
        }
77✔
1551

1552
        // 50/50 chance to add a blinding point
1553
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
146✔
1554
                pubKey := RandPubKey(t)
46✔
1555

46✔
1556
                msg.BlindingPoint = tlv.SomeRecordT(
46✔
1557
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
46✔
1558
                )
46✔
1559
        }
46✔
1560

1561
        return msg
100✔
1562
}
1563

1564
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1565
// interface.
1566
var _ TestMessage = (*UpdateFailHTLC)(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 (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1573
        return &UpdateFailHTLC{
100✔
1574
                ChanID:    RandChannelID(t),
100✔
1575
                ID:        rapid.Uint64().Draw(t, "id"),
100✔
1576
                Reason:    RandOpaqueReason(t),
100✔
1577
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1578
        }
100✔
1579
}
100✔
1580

1581
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1582
// TestMessage interface.
1583
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1584

1585
// RandTestMessage populates the message with random data suitable for testing.
1586
// It uses the rapid testing framework to generate random values.
1587
//
1588
// This is part of the TestMessage interface.
1589
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1590
        return &UpdateFailMalformedHTLC{
100✔
1591
                ChanID:       RandChannelID(t),
100✔
1592
                ID:           rapid.Uint64().Draw(t, "id"),
100✔
1593
                ShaOnionBlob: RandSHA256Hash(t),
100✔
1594
                FailureCode:  RandFailCode(t),
100✔
1595
                ExtraData:    RandExtraOpaqueData(t, nil),
100✔
1596
        }
100✔
1597
}
100✔
1598

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

1603
// RandTestMessage populates the message with random data suitable for testing.
1604
// It uses the rapid testing framework to generate random values.
1605
//
1606
// This is part of the TestMessage interface.
1607
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
100✔
1608
        return &UpdateFee{
100✔
1609
                ChanID:    RandChannelID(t),
100✔
1610
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
100✔
1611
                ExtraData: RandExtraOpaqueData(t, nil),
100✔
1612
        }
100✔
1613
}
100✔
1614

1615
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1616
// interface.
1617
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1618

1619
// RandTestMessage populates the message with random data suitable for testing.
1620
// It uses the rapid testing framework to generate random values.
1621
//
1622
// This is part of the TestMessage interface.
1623
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
100✔
1624
        msg := &UpdateFulfillHTLC{
100✔
1625
                ChanID:          RandChannelID(t),
100✔
1626
                ID:              rapid.Uint64().Draw(t, "id"),
100✔
1627
                PaymentPreimage: RandPaymentPreimage(t),
100✔
1628
        }
100✔
1629

100✔
1630
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
100✔
1631
        msg.CustomRecords = cr
100✔
1632

100✔
1633
        randData := RandExtraOpaqueData(t, ignoreRecords)
100✔
1634
        if len(randData) > 0 {
180✔
1635
                msg.ExtraData = randData
80✔
1636
        }
80✔
1637

1638
        return msg
100✔
1639
}
1640

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

1645
// RandTestMessage populates the message with random data suitable for testing.
1646
// It uses the rapid testing framework to generate random values.
1647
//
1648
// This is part of the TestMessage interface.
1649
func (c *Warning) RandTestMessage(t *rapid.T) Message {
110✔
1650
        msg := &Warning{
110✔
1651
                ChanID: RandChannelID(t),
110✔
1652
        }
110✔
1653

110✔
1654
        useASCII := rapid.Bool().Draw(t, "useASCII")
110✔
1655
        if useASCII {
154✔
1656
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
44✔
1657
                data := make([]byte, length)
44✔
1658
                for i := 0; i < length; i++ {
1,788✔
1659
                        data[i] = byte(
1,744✔
1660
                                rapid.IntRange(32, 126).Draw(
1,744✔
1661
                                        t, fmt.Sprintf("warningDataByte-%d", i),
1,744✔
1662
                                ),
1,744✔
1663
                        )
1,744✔
1664
                }
1,744✔
1665
                msg.Data = data
44✔
1666
        } else {
66✔
1667
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
66✔
1668
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
66✔
1669
                        t, "warningData",
66✔
1670
                )
66✔
1671
        }
66✔
1672

1673
        return msg
110✔
1674
}
1675

1676
// A compile time check to ensure Error implements the lnwire.TestMessage
1677
// interface.
1678
var _ TestMessage = (*Error)(nil)
1679

1680
// RandTestMessage populates the message with random data suitable for testing.
1681
// It uses the rapid testing framework to generate random values.
1682
//
1683
// This is part of the TestMessage interface.
1684
func (c *Error) RandTestMessage(t *rapid.T) Message {
100✔
1685
        msg := &Error{
100✔
1686
                ChanID: RandChannelID(t),
100✔
1687
        }
100✔
1688

100✔
1689
        useASCII := rapid.Bool().Draw(t, "useASCII")
100✔
1690
        if useASCII {
156✔
1691
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
56✔
1692
                data := make([]byte, length)
56✔
1693
                for i := 0; i < length; i++ {
1,514✔
1694
                        data[i] = byte(
1,458✔
1695
                                rapid.IntRange(32, 126).Draw(
1,458✔
1696
                                        t, fmt.Sprintf("errorDataByte-%d", i),
1,458✔
1697
                                ),
1,458✔
1698
                        )
1,458✔
1699
                }
1,458✔
1700
                msg.Data = data
56✔
1701
        } else {
44✔
1702
                // Generate random binary data
44✔
1703
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
44✔
1704
                msg.Data = rapid.SliceOfN(
44✔
1705
                        rapid.Byte(), length, length,
44✔
1706
                ).Draw(t, "errorData")
44✔
1707
        }
44✔
1708

1709
        return msg
100✔
1710
}
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