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

lightningnetwork / lnd / 15260961044

26 May 2025 07:40PM UTC coverage: 58.586% (+0.6%) from 57.977%
15260961044

Pull #9868

github

web-flow
Merge 68fbe502c into 93a6ab875
Pull Request #9868: PoC Onion messaging using `msgmux`

138 of 202 new or added lines in 7 files covered. (68.32%)

49 existing lines in 9 files now uncovered.

97608 of 166605 relevant lines covered (58.59%)

1.82 hits per line

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

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

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

×
49
        if includeChannelType {
×
50
                channelType = RandChannelType(t)
×
51
        }
×
52

53
        var leaseExpiry *LeaseExpiry
×
54
        if includeLeaseExpiry {
×
55
                leaseExpiry = RandLeaseExpiry(t)
×
56
        }
×
57

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

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

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

109
// RandTestMessage populates the message with random data suitable for testing.
110
// It uses the rapid testing framework to generate random values.
111
//
112
// This is part of the TestMessage interface.
113
func (a *AnnounceSignatures1) RandTestMessage(t *rapid.T) Message {
×
114
        return &AnnounceSignatures1{
×
115
                ChannelID:        RandChannelID(t),
×
116
                ShortChannelID:   RandShortChannelID(t),
×
117
                NodeSignature:    RandSignature(t),
×
118
                BitcoinSignature: RandSignature(t),
×
119
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
×
120
        }
×
121
}
×
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 {
×
132
        return &AnnounceSignatures2{
×
133
                ChannelID:        RandChannelID(t),
×
134
                ShortChannelID:   RandShortChannelID(t),
×
135
                PartialSignature: *RandPartialSig(t),
×
136
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
×
137
        }
×
138
}
×
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 {
×
149
        // Generate Node IDs and Bitcoin keys (compressed public keys)
×
150
        node1PubKey := RandPubKey(t)
×
151
        node2PubKey := RandPubKey(t)
×
152
        bitcoin1PubKey := RandPubKey(t)
×
153
        bitcoin2PubKey := RandPubKey(t)
×
154

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

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

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

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

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

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

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

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

×
238
        msg.Signature.ForceSchnorr()
×
239

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
404
        // If max HTLC flag is not set, we need to zero the value
×
405
        if !includeMaxHtlc {
×
406
                maxHtlc = 0
×
407
        }
×
408

409
        return &ChannelUpdate1{
×
410
                Signature:      RandSignature(t),
×
411
                ChainHash:      hash,
×
412
                ShortChannelID: RandShortChannelID(t),
×
413
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
414
                        t, "timestamp"),
×
415
                ),
×
416
                MessageFlags: msgFlags,
×
417
                ChannelFlags: chanFlags,
×
418
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
×
419
                        t, "timelockDelta"),
×
420
                ),
×
421
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
×
422
                        t, "htlcMinimum"),
×
423
                ),
×
424
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
425
                        t, "baseFee"),
×
426
                ),
×
427
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
428
                        t, "feeRate"),
×
429
                ),
×
430
                HtlcMaximumMsat: maxHtlc,
×
431
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
432
        }
×
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 {
×
444
        shortChanID := RandShortChannelID(t)
×
445
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
×
446

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

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

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

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

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

×
507
        msg.Signature.ForceSchnorr()
×
508

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

515
        return msg
×
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 {
×
527
        msg := &ClosingComplete{
×
528
                ChannelID: RandChannelID(t),
×
529
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
×
530
                        t, "feeSatoshis"),
×
531
                ),
×
532
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
×
533
                        t, "lockTime",
×
534
                ),
×
535
                CloseeScript: RandDeliveryAddress(t),
×
536
                CloserScript: RandDeliveryAddress(t),
×
537
                ExtraData:    RandExtraOpaqueData(t, nil),
×
538
        }
×
539

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

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

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

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

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

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

581
        return msg
×
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 {
×
593
        msg := &ClosingSig{
×
594
                ChannelID:    RandChannelID(t),
×
595
                CloseeScript: RandDeliveryAddress(t),
×
596
                CloserScript: RandDeliveryAddress(t),
×
597
                ExtraData:    RandExtraOpaqueData(t, nil),
×
598
        }
×
599

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

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

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

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

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

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

641
        return msg
×
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 {
×
653
        // Generate a random boolean to decide whether to include CommitSig or
×
654
        // PartialSig Since they're mutually exclusive, when one is populated,
×
655
        // the other must be blank.
×
656
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
657

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

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

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

679
        return msg
×
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 {
×
691
        cr, _ := RandCustomRecords(t, nil, true)
×
692
        sig := &CommitSig{
×
693
                ChanID:        RandChannelID(t),
×
694
                CommitSig:     RandSignature(t),
×
695
                CustomRecords: cr,
×
696
        }
×
697

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

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

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

714
        return sig
×
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 {
×
726
        msgType := MessageType(
×
727
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
×
728
                        t, "customMsgType",
×
729
                ),
×
730
        )
×
731

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

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

742
        return msg
×
743
}
744

745
// A compile time check to ensure OnionMessage implements the lnwire.TestMessage
746
// interface.
747
var _ TestMessage = (*OnionMessage)(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.
NEW
753
func (o *OnionMessage) RandTestMessage(t *rapid.T) Message {
×
NEW
754
        // Generate random compressed public key for node ID
×
NEW
755
        blindingPoint := RandPubKey(t)
×
NEW
756

×
NEW
757
        dataLen := rapid.IntRange(0, 1000).Draw(t, "onionMessageDataLength")
×
NEW
758
        data := rapid.SliceOfN(rapid.Byte(), dataLen, dataLen).Draw(
×
NEW
759
                t, "onionMssageData",
×
NEW
760
        )
×
NEW
761

×
NEW
762
        msg := NewOnionMessage(blindingPoint, data)
×
NEW
763

×
NEW
764
        return msg
×
NEW
765
}
×
766

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

771
// RandTestMessage populates the message with random data suitable for testing.
772
// It uses the rapid testing framework to generate random values.
773
//
774
// This is part of the TestMessage interface.
775
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
×
776
        msg := &DynAck{
×
777
                ChanID:    RandChannelID(t),
×
778
                ExtraData: RandExtraOpaqueData(t, nil),
×
779
        }
×
780

×
781
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
782

×
783
        if includeLocalNonce {
×
784
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
×
785
        }
×
786

787
        return msg
×
788
}
789

790
// A compile time check to ensure DynPropose implements the lnwire.TestMessage
791
// interface.
792
var _ TestMessage = (*DynPropose)(nil)
793

794
// RandTestMessage populates the message with random data suitable for testing.
795
// It uses the rapid testing framework to generate random values.
796
//
797
// This is part of the TestMessage interface.
798
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
×
799
        msg := &DynPropose{
×
800
                ChanID:    RandChannelID(t),
×
801
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
802
                ExtraData: RandExtraOpaqueData(t, nil),
×
803
        }
×
804

×
805
        // Randomly decide which optional fields to include
×
806
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
807
        includeMaxValueInFlight := rapid.Bool().Draw(
×
808
                t, "includeMaxValueInFlight",
×
809
        )
×
810
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
811
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
812
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
813
                t, "includeMaxAcceptedHTLCs",
×
814
        )
×
815
        includeFundingKey := rapid.Bool().Draw(t, "includeFundingKey")
×
816
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
817
        includeKickoffFeerate := rapid.Bool().Draw(t, "includeKickoffFeerate")
×
818

×
819
        // Generate random values for each included field
×
820
        if includeDustLimit {
×
821
                dl := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
822
                msg.DustLimit = fn.Some(dl)
×
823
        }
×
824

825
        if includeMaxValueInFlight {
×
826
                mvif := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
827
                msg.MaxValueInFlight = fn.Some(mvif)
×
828
        }
×
829

830
        if includeChannelReserve {
×
831
                cr := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
832
                msg.ChannelReserve = fn.Some(cr)
×
833
        }
×
834

835
        if includeCsvDelay {
×
836
                cd := rapid.Uint16().Draw(t, "csvDelay")
×
837
                msg.CsvDelay = fn.Some(cd)
×
838
        }
×
839

840
        if includeMaxAcceptedHTLCs {
×
841
                mah := rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
842
                msg.MaxAcceptedHTLCs = fn.Some(mah)
×
843
        }
×
844

845
        if includeFundingKey {
×
846
                msg.FundingKey = fn.Some(*RandPubKey(t))
×
847
        }
×
848

849
        if includeChannelType {
×
850
                msg.ChannelType = fn.Some(*RandChannelType(t))
×
851
        }
×
852

853
        if includeKickoffFeerate {
×
854
                kf := chainfee.SatPerKWeight(rapid.Uint32().Draw(
×
855
                        t, "kickoffFeerate"),
×
856
                )
×
857
                msg.KickoffFeerate = fn.Some(kf)
×
858
        }
×
859

860
        return msg
×
861
}
862

863
// A compile time check to ensure DynReject implements the lnwire.TestMessage
864
// interface.
865
var _ TestMessage = (*DynReject)(nil)
866

867
// RandTestMessage populates the message with random data suitable for testing.
868
// It uses the rapid testing framework to generate random values.
869
//
870
// This is part of the TestMessage interface.
871
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
×
872
        featureVec := NewRawFeatureVector()
×
873

×
874
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
×
875
        for i := 0; i < numFeatures; i++ {
×
876
                bit := FeatureBit(
×
877
                        rapid.IntRange(0, 31).Draw(
×
878
                                t, fmt.Sprintf("rejectionBit-%d", i),
×
879
                        ),
×
880
                )
×
881
                featureVec.Set(bit)
×
882
        }
×
883

884
        var extraData ExtraOpaqueData
×
885
        randData := RandExtraOpaqueData(t, nil)
×
886
        if len(randData) > 0 {
×
887
                extraData = randData
×
888
        }
×
889

890
        return &DynReject{
×
891
                ChanID:           RandChannelID(t),
×
892
                UpdateRejections: *featureVec,
×
893
                ExtraData:        extraData,
×
894
        }
×
895
}
896

897
// A compile time check to ensure FundingCreated implements the TestMessage
898
// interface.
899
var _ TestMessage = (*FundingCreated)(nil)
900

901
// RandTestMessage populates the message with random data suitable for testing.
902
// It uses the rapid testing framework to generate random values.
903
//
904
// This is part of the TestMessage interface.
905
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
×
906
        var pendingChanID [32]byte
×
907
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
908
                t, "pendingChanID",
×
909
        )
×
910
        copy(pendingChanID[:], pendingChanIDBytes)
×
911

×
912
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
913
        var partialSig OptPartialSigWithNonceTLV
×
914
        var commitSig Sig
×
915

×
916
        if includePartialSig {
×
917
                sigWithNonce := RandPartialSigWithNonce(t)
×
918
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
919

×
920
                // When using partial sig, CommitSig should be empty/blank.
×
921
                commitSig = Sig{}
×
922
        } else {
×
923
                commitSig = RandSignature(t)
×
924
        }
×
925

926
        return &FundingCreated{
×
927
                PendingChannelID: pendingChanID,
×
928
                FundingPoint:     RandOutPoint(t),
×
929
                CommitSig:        commitSig,
×
930
                PartialSig:       partialSig,
×
931
                ExtraData:        RandExtraOpaqueData(t, nil),
×
932
        }
×
933
}
934

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

939
// RandTestMessage populates the message with random data suitable for testing.
940
// It uses the rapid testing framework to generate random values.
941
//
942
// This is part of the TestMessage interface.
943
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
×
944
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
945

×
946
        msg := &FundingSigned{
×
947
                ChanID:    RandChannelID(t),
×
948
                ExtraData: RandExtraOpaqueData(t, nil),
×
949
        }
×
950

×
951
        if usePartialSig {
×
952
                sigWithNonce := RandPartialSigWithNonce(t)
×
953
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
954

×
955
                msg.CommitSig = Sig{}
×
956
        } else {
×
957
                msg.CommitSig = RandSignature(t)
×
958
        }
×
959

960
        return msg
×
961
}
962

963
// A compile time check to ensure GossipTimestampRange implements the
964
// lnwire.TestMessage interface.
965
var _ TestMessage = (*GossipTimestampRange)(nil)
966

967
// RandTestMessage populates the message with random data suitable for testing.
968
// It uses the rapid testing framework to generate random values.
969
//
970
// This is part of the TestMessage interface.
971
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
×
972
        var chainHash chainhash.Hash
×
973
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
974
        copy(chainHash[:], hashBytes)
×
975

×
976
        msg := &GossipTimestampRange{
×
977
                ChainHash:      chainHash,
×
978
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
×
979
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
×
980
                ExtraData:      RandExtraOpaqueData(t, nil),
×
981
        }
×
982

×
983
        includeFirstBlockHeight := rapid.Bool().Draw(
×
984
                t, "includeFirstBlockHeight",
×
985
        )
×
986
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
×
987

×
988
        if includeFirstBlockHeight {
×
989
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
×
990
                msg.FirstBlockHeight = tlv.SomeRecordT(
×
991
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
×
992
                )
×
993
        }
×
994

995
        if includeBlockRange {
×
996
                blockRange := rapid.Uint32().Draw(t, "blockRange")
×
997
                msg.BlockRange = tlv.SomeRecordT(
×
998
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
×
999
                )
×
1000
        }
×
1001

1002
        return msg
×
1003
}
1004

1005
// RandTestMessage populates the message with random data suitable for testing.
1006
// It uses the rapid testing framework to generate random values.
1007
//
1008
// This is part of the TestMessage interface.
1009
func (msg *Init) RandTestMessage(t *rapid.T) Message {
×
1010
        global := NewRawFeatureVector()
×
1011
        local := NewRawFeatureVector()
×
1012

×
1013
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
×
1014
        for i := 0; i < numGlobalFeatures; i++ {
×
1015
                bit := FeatureBit(
×
1016
                        rapid.IntRange(0, 100).Draw(
×
1017
                                t, fmt.Sprintf("globalFeatureBit%d", i),
×
1018
                        ),
×
1019
                )
×
1020
                global.Set(bit)
×
1021
        }
×
1022

1023
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
×
1024
        for i := 0; i < numLocalFeatures; i++ {
×
1025
                bit := FeatureBit(
×
1026
                        rapid.IntRange(0, 100).Draw(
×
1027
                                t, fmt.Sprintf("localFeatureBit%d", i),
×
1028
                        ),
×
1029
                )
×
1030
                local.Set(bit)
×
1031
        }
×
1032

1033
        return NewInitMessage(global, local)
×
1034
}
1035

1036
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1037
// interface.
1038
var _ TestMessage = (*KickoffSig)(nil)
1039

1040
// RandTestMessage populates the message with random data suitable for testing.
1041
// It uses the rapid testing framework to generate random values.
1042
//
1043
// This is part of the TestMessage interface.
1044
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
×
1045
        return &KickoffSig{
×
1046
                ChanID:    RandChannelID(t),
×
1047
                Signature: RandSignature(t),
×
1048
                ExtraData: RandExtraOpaqueData(t, nil),
×
1049
        }
×
1050
}
×
1051

1052
// A compile time check to ensure NodeAnnouncement implements the
1053
// lnwire.TestMessage interface.
1054
var _ TestMessage = (*NodeAnnouncement)(nil)
1055

1056
// RandTestMessage populates the message with random data suitable for testing.
1057
// It uses the rapid testing framework to generate random values.
1058
//
1059
// This is part of the TestMessage interface.
1060
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
×
1061
        // Generate random compressed public key for node ID
×
1062
        pubKey := RandPubKey(t)
×
1063
        var nodeID [33]byte
×
1064
        copy(nodeID[:], pubKey.SerializeCompressed())
×
1065

×
1066
        // Generate random RGB color
×
1067
        rgbColor := color.RGBA{
×
1068
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
×
1069
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
×
1070
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
×
1071
        }
×
1072

×
1073
        return &NodeAnnouncement{
×
1074
                Signature: RandSignature(t),
×
1075
                Features:  RandFeatureVector(t),
×
1076
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
1077
                        t, "timestamp"),
×
1078
                ),
×
1079
                NodeID:          nodeID,
×
1080
                RGBColor:        rgbColor,
×
1081
                Alias:           RandNodeAlias(t),
×
1082
                Addresses:       RandNetAddrs(t),
×
1083
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
1084
        }
×
1085
}
×
1086

1087
// A compile time check to ensure OpenChannel implements the TestMessage
1088
// interface.
1089
var _ TestMessage = (*OpenChannel)(nil)
1090

1091
// RandTestMessage populates the message with random data suitable for testing.
1092
// It uses the rapid testing framework to generate random values.
1093
//
1094
// This is part of the TestMessage interface.
1095
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
×
1096
        chainHash := RandChainHash(t)
×
1097
        var hash chainhash.Hash
×
1098
        copy(hash[:], chainHash[:])
×
1099

×
1100
        var pendingChanID [32]byte
×
1101
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1102
                t, "pendingChanID",
×
1103
        )
×
1104
        copy(pendingChanID[:], pendingChanIDBytes)
×
1105

×
1106
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
1107
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
×
1108
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
1109

×
1110
        var channelFlags FundingFlag
×
1111
        if rapid.Bool().Draw(t, "announceChannel") {
×
1112
                channelFlags |= FFAnnounceChannel
×
1113
        }
×
1114

1115
        var localNonce OptMusig2NonceTLV
×
1116
        if includeLocalNonce {
×
1117
                nonce := RandMusig2Nonce(t)
×
1118
                localNonce = tlv.SomeRecordT(
×
1119
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
1120
                )
×
1121
        }
×
1122

1123
        var channelType *ChannelType
×
1124
        if includeChannelType {
×
1125
                channelType = RandChannelType(t)
×
1126
        }
×
1127

1128
        var leaseExpiry *LeaseExpiry
×
1129
        if includeLeaseExpiry {
×
1130
                leaseExpiry = RandLeaseExpiry(t)
×
1131
        }
×
1132

1133
        return &OpenChannel{
×
1134
                ChainHash:        hash,
×
1135
                PendingChannelID: pendingChanID,
×
1136
                FundingAmount: btcutil.Amount(
×
1137
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
×
1138
                ),
×
1139
                PushAmount: MilliSatoshi(
×
1140
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
×
1141
                ),
×
1142
                DustLimit: btcutil.Amount(
×
1143
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
×
1144
                ),
×
1145
                MaxValueInFlight: MilliSatoshi(
×
1146
                        rapid.IntRange(10000, 1000000).Draw(
×
1147
                                t, "maxValueInFlight",
×
1148
                        ),
×
1149
                ),
×
1150
                ChannelReserve: btcutil.Amount(
×
1151
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
×
1152
                ),
×
1153
                HtlcMinimum: MilliSatoshi(
×
1154
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
×
1155
                ),
×
1156
                FeePerKiloWeight: uint32(
×
1157
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
×
1158
                ),
×
1159
                CsvDelay: uint16(
×
1160
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
×
1161
                ),
×
1162
                MaxAcceptedHTLCs: uint16(
×
1163
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
×
1164
                ),
×
1165
                FundingKey:            RandPubKey(t),
×
1166
                RevocationPoint:       RandPubKey(t),
×
1167
                PaymentPoint:          RandPubKey(t),
×
1168
                DelayedPaymentPoint:   RandPubKey(t),
×
1169
                HtlcPoint:             RandPubKey(t),
×
1170
                FirstCommitmentPoint:  RandPubKey(t),
×
1171
                ChannelFlags:          channelFlags,
×
1172
                UpfrontShutdownScript: RandDeliveryAddress(t),
×
1173
                ChannelType:           channelType,
×
1174
                LeaseExpiry:           leaseExpiry,
×
1175
                LocalNonce:            localNonce,
×
1176
                ExtraData:             RandExtraOpaqueData(t, nil),
×
1177
        }
×
1178
}
1179

1180
// A compile time check to ensure Ping implements the lnwire.TestMessage
1181
// interface.
1182
var _ TestMessage = (*Ping)(nil)
1183

1184
// RandTestMessage populates the message with random data suitable for testing.
1185
// It uses the rapid testing framework to generate random values.
1186
//
1187
// This is part of the TestMessage interface.
1188
func (p *Ping) RandTestMessage(t *rapid.T) Message {
×
1189
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
×
1190
                t, "numPongBytes"),
×
1191
        )
×
1192

×
1193
        // Generate padding bytes (but keeping within allowed message size)
×
1194
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
×
1195
        maxPaddingLen := MaxMsgBody - 4
×
1196
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
×
1197
                t, "paddingLen",
×
1198
        )
×
1199
        padding := make(PingPayload, paddingLen)
×
1200

×
1201
        // Fill padding with random bytes
×
1202
        for i := 0; i < paddingLen; i++ {
×
1203
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
×
1204
                        t, fmt.Sprintf("paddingByte%d", i)),
×
1205
                )
×
1206
        }
×
1207

1208
        return &Ping{
×
1209
                NumPongBytes: numPongBytes,
×
1210
                PaddingBytes: padding,
×
1211
        }
×
1212
}
1213

1214
// A compile time check to ensure Pong implements the lnwire.TestMessage
1215
// interface.
1216
var _ TestMessage = (*Pong)(nil)
1217

1218
// RandTestMessage populates the message with random data suitable for testing.
1219
// It uses the rapid testing framework to generate random values.
1220
//
1221
// This is part of the TestMessage interface.
1222
func (p *Pong) RandTestMessage(t *rapid.T) Message {
×
1223
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
×
1224
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
×
1225
                t, "pongPayload",
×
1226
        )
×
1227

×
1228
        return &Pong{
×
1229
                PongBytes: payload,
×
1230
        }
×
1231
}
×
1232

1233
// A compile time check to ensure QueryChannelRange implements the
1234
// lnwire.TestMessage interface.
1235
var _ TestMessage = (*QueryChannelRange)(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 (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
×
1242
        msg := &QueryChannelRange{
×
1243
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
1244
                        t, "firstBlockHeight"),
×
1245
                ),
×
1246
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
1247
                        t, "numBlocks"),
×
1248
                ),
×
1249
                ExtraData: RandExtraOpaqueData(t, nil),
×
1250
        }
×
1251

×
1252
        // Generate chain hash
×
1253
        chainHash := RandChainHash(t)
×
1254
        var chainHashObj chainhash.Hash
×
1255
        copy(chainHashObj[:], chainHash[:])
×
1256
        msg.ChainHash = chainHashObj
×
1257

×
1258
        // Randomly include QueryOptions
×
1259
        if rapid.Bool().Draw(t, "includeQueryOptions") {
×
1260
                queryOptions := &QueryOptions{}
×
1261
                *queryOptions = QueryOptions(*RandFeatureVector(t))
×
1262
                msg.QueryOptions = queryOptions
×
1263
        }
×
1264

1265
        return msg
×
1266
}
1267

1268
// A compile time check to ensure QueryShortChanIDs implements the
1269
// lnwire.TestMessage interface.
1270
var _ TestMessage = (*QueryShortChanIDs)(nil)
1271

1272
// RandTestMessage populates the message with random data suitable for testing.
1273
// It uses the rapid testing framework to generate random values.
1274
//
1275
// This is part of the TestMessage interface.
1276
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
×
1277
        var chainHash chainhash.Hash
×
1278
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
1279
        copy(chainHash[:], hashBytes)
×
1280

×
1281
        encodingType := EncodingSortedPlain
×
1282
        if rapid.Bool().Draw(t, "useZlibEncoding") {
×
1283
                encodingType = EncodingSortedZlib
×
1284
        }
×
1285

1286
        msg := &QueryShortChanIDs{
×
1287
                ChainHash:    chainHash,
×
1288
                EncodingType: encodingType,
×
1289
                ExtraData:    RandExtraOpaqueData(t, nil),
×
1290
                noSort:       false,
×
1291
        }
×
1292

×
1293
        numIDs := rapid.IntRange(2, 20).Draw(t, "numShortChanIDs")
×
1294

×
1295
        // Generate sorted short channel IDs.
×
1296
        shortChanIDs := make([]ShortChannelID, numIDs)
×
1297
        for i := 0; i < numIDs; i++ {
×
1298
                shortChanIDs[i] = RandShortChannelID(t)
×
1299

×
1300
                // Ensure they're properly sorted.
×
1301
                if i > 0 && shortChanIDs[i].ToUint64() <=
×
1302
                        shortChanIDs[i-1].ToUint64() {
×
1303

×
1304
                        // Ensure this ID is larger than the previous one.
×
1305
                        shortChanIDs[i] = NewShortChanIDFromInt(
×
1306
                                shortChanIDs[i-1].ToUint64() + 1,
×
1307
                        )
×
1308
                }
×
1309
        }
1310

1311
        msg.ShortChanIDs = shortChanIDs
×
1312

×
1313
        return msg
×
1314
}
1315

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

1320
// RandTestMessage populates the message with random data suitable for testing.
1321
// It uses the rapid testing framework to generate random values.
1322
//
1323
// This is part of the TestMessage interface.
1324
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
×
1325
        msg := &ReplyChannelRange{
×
1326
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
1327
                        t, "firstBlockHeight"),
×
1328
                ),
×
1329
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
1330
                        t, "numBlocks"),
×
1331
                ),
×
1332
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
×
1333
                EncodingType: QueryEncoding(
×
1334
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
×
1335
                ),
×
1336
                ExtraData: RandExtraOpaqueData(t, nil),
×
1337
        }
×
1338

×
1339
        msg.ChainHash = RandChainHash(t)
×
1340

×
1341
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
×
1342
        if numShortChanIDs == 0 {
×
1343
                return msg
×
1344
        }
×
1345

1346
        scidSet := fn.NewSet[ShortChannelID]()
×
1347
        scids := make([]ShortChannelID, numShortChanIDs)
×
1348
        for i := 0; i < numShortChanIDs; i++ {
×
1349
                scid := RandShortChannelID(t)
×
1350
                for scidSet.Contains(scid) {
×
1351
                        scid = RandShortChannelID(t)
×
1352
                }
×
1353

1354
                scids[i] = scid
×
1355

×
1356
                scidSet.Add(scid)
×
1357
        }
1358

1359
        // Make sure there're no duplicates.
1360
        msg.ShortChanIDs = scids
×
1361

×
1362
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
×
1363
                msg.Timestamps = make(Timestamps, numShortChanIDs)
×
1364
                for i := 0; i < numShortChanIDs; i++ {
×
1365
                        msg.Timestamps[i] = ChanUpdateTimestamps{
×
1366
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
×
1367
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
×
1368
                        }
×
1369
                }
×
1370
        }
1371

1372
        return msg
×
1373
}
1374

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

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

×
1388
        complete := uint8(rapid.IntRange(0, 1).Draw(t, "complete"))
×
1389

×
1390
        return &ReplyShortChanIDsEnd{
×
1391
                ChainHash: chainHash,
×
1392
                Complete:  complete,
×
1393
                ExtraData: RandExtraOpaqueData(t, nil),
×
1394
        }
×
1395
}
×
1396

1397
// RandTestMessage returns a RevokeAndAck message populated with random data.
1398
//
1399
// This is part of the TestMessage interface.
1400
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
×
1401
        msg := NewRevokeAndAck()
×
1402

×
1403
        var chanID ChannelID
×
1404
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
×
1405
        copy(chanID[:], bytes)
×
1406
        msg.ChanID = chanID
×
1407

×
1408
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
×
1409
        copy(msg.Revocation[:], revBytes)
×
1410

×
1411
        msg.NextRevocationKey = RandPubKey(t)
×
1412

×
1413
        if rapid.Bool().Draw(t, "includeLocalNonce") {
×
1414
                var nonce Musig2Nonce
×
1415
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
1416
                        t, "nonce",
×
1417
                )
×
1418
                copy(nonce[:], nonceBytes)
×
1419

×
1420
                msg.LocalNonce = tlv.SomeRecordT(
×
1421
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
1422
                )
×
1423
        }
×
1424

1425
        return msg
×
1426
}
1427

1428
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1429
// interface.
1430
var _ TestMessage = (*Shutdown)(nil)
1431

1432
// RandTestMessage populates the message with random data suitable for testing.
1433
// It uses the rapid testing framework to generate random values.
1434
//
1435
// This is part of the TestMessage interface.
1436
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
×
1437
        // Generate random delivery address
×
1438
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
×
1439
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
×
1440

×
1441
        // Generate random address length based on type
×
1442
        var addrLen int
×
1443
        switch addrType {
×
1444
        // P2PKH
1445
        case 0:
×
1446
                addrLen = 25
×
1447
        // P2SH
1448
        case 1:
×
1449
                addrLen = 23
×
1450
        // P2WPKH
1451
        case 2:
×
1452
                addrLen = 22
×
1453
        // P2WSH
1454
        case 3:
×
1455
                addrLen = 34
×
1456
        // P2TR
1457
        case 4:
×
1458
                addrLen = 34
×
1459
        }
1460

1461
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
×
1462
                t, "address",
×
1463
        )
×
1464

×
1465
        // Randomly decide whether to include a shutdown nonce
×
1466
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
×
1467
        var shutdownNonce ShutdownNonceTLV
×
1468

×
1469
        if includeNonce {
×
1470
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
×
1471
        }
×
1472

1473
        cr, _ := RandCustomRecords(t, nil, true)
×
1474

×
1475
        return &Shutdown{
×
1476
                ChannelID:     RandChannelID(t),
×
1477
                Address:       addr,
×
1478
                ShutdownNonce: shutdownNonce,
×
1479
                CustomRecords: cr,
×
1480
        }
×
1481
}
1482

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

1487
// RandTestMessage populates the message with random data suitable for testing.
1488
// It uses the rapid testing framework to generate random values.
1489
//
1490
// This is part of the TestMessage interface.
1491
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
×
1492
        m := &Stfu{
×
1493
                ChanID:    RandChannelID(t),
×
1494
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
1495
        }
×
1496

×
1497
        extraData := RandExtraOpaqueData(t, nil)
×
1498
        if len(extraData) > 0 {
×
1499
                m.ExtraData = extraData
×
1500
        }
×
1501

1502
        return m
×
1503
}
1504

1505
// A compile time check to ensure UpdateAddHTLC implements the
1506
// lnwire.TestMessage interface.
1507
var _ TestMessage = (*UpdateAddHTLC)(nil)
1508

1509
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1510
//
1511
// This is part of the TestMessage interface.
1512
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
×
1513
        msg := &UpdateAddHTLC{
×
1514
                ChanID: RandChannelID(t),
×
1515
                ID:     rapid.Uint64().Draw(t, "id"),
×
1516
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
×
1517
                Expiry: rapid.Uint32().Draw(t, "expiry"),
×
1518
        }
×
1519

×
1520
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
×
1521
        copy(msg.PaymentHash[:], hashBytes)
×
1522

×
1523
        onionBytes := rapid.SliceOfN(
×
1524
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
×
1525
        ).Draw(t, "onionBlob")
×
1526
        copy(msg.OnionBlob[:], onionBytes)
×
1527

×
1528
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
×
1529
        if numRecords > 0 {
×
1530
                msg.CustomRecords, _ = RandCustomRecords(t, nil, true)
×
1531
        }
×
1532

1533
        // 50/50 chance to add a blinding point
1534
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
×
1535
                pubKey := RandPubKey(t)
×
1536

×
1537
                msg.BlindingPoint = tlv.SomeRecordT(
×
1538
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
×
1539
                )
×
1540
        }
×
1541

1542
        return msg
×
1543
}
1544

1545
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1546
// interface.
1547
var _ TestMessage = (*UpdateFailHTLC)(nil)
1548

1549
// RandTestMessage populates the message with random data suitable for testing.
1550
// It uses the rapid testing framework to generate random values.
1551
//
1552
// This is part of the TestMessage interface.
1553
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
×
1554
        return &UpdateFailHTLC{
×
1555
                ChanID:    RandChannelID(t),
×
1556
                ID:        rapid.Uint64().Draw(t, "id"),
×
1557
                Reason:    RandOpaqueReason(t),
×
1558
                ExtraData: RandExtraOpaqueData(t, nil),
×
1559
        }
×
1560
}
×
1561

1562
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1563
// TestMessage interface.
1564
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1565

1566
// RandTestMessage populates the message with random data suitable for testing.
1567
// It uses the rapid testing framework to generate random values.
1568
//
1569
// This is part of the TestMessage interface.
1570
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
×
1571
        return &UpdateFailMalformedHTLC{
×
1572
                ChanID:       RandChannelID(t),
×
1573
                ID:           rapid.Uint64().Draw(t, "id"),
×
1574
                ShaOnionBlob: RandSHA256Hash(t),
×
1575
                FailureCode:  RandFailCode(t),
×
1576
                ExtraData:    RandExtraOpaqueData(t, nil),
×
1577
        }
×
1578
}
×
1579

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

1584
// RandTestMessage populates the message with random data suitable for testing.
1585
// It uses the rapid testing framework to generate random values.
1586
//
1587
// This is part of the TestMessage interface.
1588
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
×
1589
        return &UpdateFee{
×
1590
                ChanID:    RandChannelID(t),
×
1591
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
×
1592
                ExtraData: RandExtraOpaqueData(t, nil),
×
1593
        }
×
1594
}
×
1595

1596
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1597
// interface.
1598
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1599

1600
// RandTestMessage populates the message with random data suitable for testing.
1601
// It uses the rapid testing framework to generate random values.
1602
//
1603
// This is part of the TestMessage interface.
1604
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
×
1605
        msg := &UpdateFulfillHTLC{
×
1606
                ChanID:          RandChannelID(t),
×
1607
                ID:              rapid.Uint64().Draw(t, "id"),
×
1608
                PaymentPreimage: RandPaymentPreimage(t),
×
1609
        }
×
1610

×
1611
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
×
1612
        msg.CustomRecords = cr
×
1613

×
1614
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
1615
        if len(randData) > 0 {
×
1616
                msg.ExtraData = randData
×
1617
        }
×
1618

1619
        return msg
×
1620
}
1621

1622
// A compile time check to ensure Warning implements the lnwire.TestMessage
1623
// interface.
1624
var _ TestMessage = (*Warning)(nil)
1625

1626
// RandTestMessage populates the message with random data suitable for testing.
1627
// It uses the rapid testing framework to generate random values.
1628
//
1629
// This is part of the TestMessage interface.
1630
func (c *Warning) RandTestMessage(t *rapid.T) Message {
×
1631
        msg := &Warning{
×
1632
                ChanID: RandChannelID(t),
×
1633
        }
×
1634

×
1635
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
1636
        if useASCII {
×
1637
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
1638
                data := make([]byte, length)
×
1639
                for i := 0; i < length; i++ {
×
1640
                        data[i] = byte(
×
1641
                                rapid.IntRange(32, 126).Draw(
×
1642
                                        t, fmt.Sprintf("warningDataByte-%d", i),
×
1643
                                ),
×
1644
                        )
×
1645
                }
×
1646
                msg.Data = data
×
1647
        } else {
×
1648
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
1649
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
×
1650
                        t, "warningData",
×
1651
                )
×
1652
        }
×
1653

1654
        return msg
×
1655
}
1656

1657
// A compile time check to ensure Error implements the lnwire.TestMessage
1658
// interface.
1659
var _ TestMessage = (*Error)(nil)
1660

1661
// RandTestMessage populates the message with random data suitable for testing.
1662
// It uses the rapid testing framework to generate random values.
1663
//
1664
// This is part of the TestMessage interface.
1665
func (c *Error) RandTestMessage(t *rapid.T) Message {
×
1666
        msg := &Error{
×
1667
                ChanID: RandChannelID(t),
×
1668
        }
×
1669

×
1670
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
1671
        if useASCII {
×
1672
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
1673
                data := make([]byte, length)
×
1674
                for i := 0; i < length; i++ {
×
1675
                        data[i] = byte(
×
1676
                                rapid.IntRange(32, 126).Draw(
×
1677
                                        t, fmt.Sprintf("errorDataByte-%d", i),
×
1678
                                ),
×
1679
                        )
×
1680
                }
×
1681
                msg.Data = data
×
1682
        } else {
×
1683
                // Generate random binary data
×
1684
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
1685
                msg.Data = rapid.SliceOfN(
×
1686
                        rapid.Byte(), length, length,
×
1687
                ).Draw(t, "errorData")
×
1688
        }
×
1689

1690
        return msg
×
1691
}
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