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

lightningnetwork / lnd / 13982721865

21 Mar 2025 01:30AM UTC coverage: 58.587% (-0.5%) from 59.126%
13982721865

Pull #9623

github

web-flow
Merge 05a6b6838 into 5d921723b
Pull Request #9623: Size msg test msg

0 of 1572 new or added lines in 43 files covered. (0.0%)

17 existing lines in 5 files now uncovered.

96767 of 165169 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.
NEW
37
func (a *AcceptChannel) RandTestMessage(t *rapid.T) Message {
×
NEW
38
        var pendingChanID [32]byte
×
NEW
39
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
NEW
40
                t, "pendingChanID",
×
NEW
41
        )
×
NEW
42
        copy(pendingChanID[:], pendingChanIDBytes)
×
NEW
43

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

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

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

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

NEW
66
        return &AcceptChannel{
×
NEW
67
                PendingChannelID: pendingChanID,
×
NEW
68
                DustLimit: btcutil.Amount(
×
NEW
69
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
×
NEW
70
                ),
×
NEW
71
                MaxValueInFlight: MilliSatoshi(
×
NEW
72
                        rapid.IntRange(10000, 1000000).Draw(
×
NEW
73
                                t, "maxValueInFlight",
×
NEW
74
                        ),
×
NEW
75
                ),
×
NEW
76
                ChannelReserve: btcutil.Amount(
×
NEW
77
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
×
NEW
78
                ),
×
NEW
79
                HtlcMinimum: MilliSatoshi(
×
NEW
80
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
×
NEW
81
                ),
×
NEW
82
                MinAcceptDepth: uint32(
×
NEW
83
                        rapid.IntRange(1, 10).Draw(t, "minAcceptDepth"),
×
NEW
84
                ),
×
NEW
85
                CsvDelay: uint16(
×
NEW
86
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
×
NEW
87
                ),
×
NEW
88
                MaxAcceptedHTLCs: uint16(
×
NEW
89
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
×
NEW
90
                ),
×
NEW
91
                FundingKey:            RandPubKey(t),
×
NEW
92
                RevocationPoint:       RandPubKey(t),
×
NEW
93
                PaymentPoint:          RandPubKey(t),
×
NEW
94
                DelayedPaymentPoint:   RandPubKey(t),
×
NEW
95
                HtlcPoint:             RandPubKey(t),
×
NEW
96
                FirstCommitmentPoint:  RandPubKey(t),
×
NEW
97
                UpfrontShutdownScript: RandDeliveryAddress(t),
×
NEW
98
                ChannelType:           channelType,
×
NEW
99
                LeaseExpiry:           leaseExpiry,
×
NEW
100
                LocalNonce:            localNonce,
×
NEW
101
                ExtraData:             RandExtraOpaqueData(t, nil),
×
NEW
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.
NEW
113
func (a *AnnounceSignatures1) RandTestMessage(t *rapid.T) Message {
×
NEW
114
        return &AnnounceSignatures1{
×
NEW
115
                ChannelID:        RandChannelID(t),
×
NEW
116
                ShortChannelID:   RandShortChannelID(t),
×
NEW
117
                NodeSignature:    RandSignature(t),
×
NEW
118
                BitcoinSignature: RandSignature(t),
×
NEW
119
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
×
NEW
120
        }
×
NEW
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.
NEW
131
func (a *AnnounceSignatures2) RandTestMessage(t *rapid.T) Message {
×
NEW
132
        return &AnnounceSignatures2{
×
NEW
133
                ChannelID:        RandChannelID(t),
×
NEW
134
                ShortChannelID:   RandShortChannelID(t),
×
NEW
135
                PartialSignature: *RandPartialSig(t),
×
NEW
136
                ExtraOpaqueData:  RandExtraOpaqueData(t, nil),
×
NEW
137
        }
×
NEW
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.
NEW
148
func (a *ChannelAnnouncement1) RandTestMessage(t *rapid.T) Message {
×
NEW
149
        // Generate Node IDs and Bitcoin keys (compressed public keys)
×
NEW
150
        node1PubKey := RandPubKey(t)
×
NEW
151
        node2PubKey := RandPubKey(t)
×
NEW
152
        bitcoin1PubKey := RandPubKey(t)
×
NEW
153
        bitcoin2PubKey := RandPubKey(t)
×
NEW
154

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

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

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

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

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

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

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

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

×
NEW
238
        msg.Signature.ForceSchnorr()
×
NEW
239

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

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

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

NEW
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.
NEW
283
func (c *ChannelReady) RandTestMessage(t *rapid.T) Message {
×
NEW
284
        msg := &ChannelReady{
×
NEW
285
                ChanID:                 RandChannelID(t),
×
NEW
286
                NextPerCommitmentPoint: RandPubKey(t),
×
NEW
287
                ExtraData:              RandExtraOpaqueData(t, nil),
×
NEW
288
        }
×
NEW
289

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
NEW
507
        msg.Signature.ForceSchnorr()
×
NEW
508

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

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

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

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

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

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

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

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

NEW
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.
NEW
592
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
×
NEW
593
        msg := &ClosingSig{
×
NEW
594
                ChannelID:    RandChannelID(t),
×
NEW
595
                CloseeScript: RandDeliveryAddress(t),
×
NEW
596
                CloserScript: RandDeliveryAddress(t),
×
NEW
597
                ExtraData:    RandExtraOpaqueData(t, nil),
×
NEW
598
        }
×
NEW
599

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

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

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

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

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

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

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

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

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

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

NEW
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.
NEW
690
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
×
NEW
691
        cr, _ := RandCustomRecords(t, nil, true)
×
NEW
692
        sig := &CommitSig{
×
NEW
693
                ChanID:        RandChannelID(t),
×
NEW
694
                CommitSig:     RandSignature(t),
×
NEW
695
                CustomRecords: cr,
×
NEW
696
        }
×
NEW
697

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

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

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

NEW
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.
NEW
725
func (c *Custom) RandTestMessage(t *rapid.T) Message {
×
NEW
726
        msgType := MessageType(
×
NEW
727
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
×
NEW
728
                        t, "customMsgType",
×
NEW
729
                ),
×
NEW
730
        )
×
NEW
731

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

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

NEW
742
        return msg
×
743
}
744

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

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

×
NEW
759
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
NEW
760

×
NEW
761
        if includeLocalNonce {
×
NEW
762
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
×
NEW
763
        }
×
764

NEW
765
        return msg
×
766
}
767

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

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

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

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

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

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

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

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

NEW
823
        if includeFundingKey {
×
NEW
824
                msg.FundingKey = fn.Some(*RandPubKey(t))
×
NEW
825
        }
×
826

NEW
827
        if includeChannelType {
×
NEW
828
                msg.ChannelType = fn.Some(*RandChannelType(t))
×
NEW
829
        }
×
830

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

NEW
838
        return msg
×
839
}
840

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

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

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

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

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

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

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

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

×
NEW
894
        if includePartialSig {
×
NEW
895
                sigWithNonce := RandPartialSigWithNonce(t)
×
NEW
896
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
NEW
897

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

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

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

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

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

×
NEW
929
        if usePartialSig {
×
NEW
930
                sigWithNonce := RandPartialSigWithNonce(t)
×
NEW
931
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
NEW
932

×
NEW
933
                msg.CommitSig = Sig{}
×
NEW
934
        } else {
×
NEW
935
                msg.CommitSig = RandSignature(t)
×
NEW
936
        }
×
937

NEW
938
        return msg
×
939
}
940

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

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

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

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

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

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

NEW
980
        return msg
×
981
}
982

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

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

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

NEW
1011
        return NewInitMessage(global, local)
×
1012
}
1013

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

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

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

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

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

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

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

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

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

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

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

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

NEW
1101
        var channelType *ChannelType
×
NEW
1102
        if includeChannelType {
×
NEW
1103
                channelType = RandChannelType(t)
×
NEW
1104
        }
×
1105

NEW
1106
        var leaseExpiry *LeaseExpiry
×
NEW
1107
        if includeLeaseExpiry {
×
NEW
1108
                leaseExpiry = RandLeaseExpiry(t)
×
NEW
1109
        }
×
1110

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

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

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

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

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

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

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

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

×
NEW
1206
        return &Pong{
×
NEW
1207
                PongBytes: payload,
×
NEW
1208
        }
×
NEW
1209
}
×
1210

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

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

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

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

NEW
1243
        return msg
×
1244
}
1245

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

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

×
NEW
1259
        encodingType := EncodingSortedPlain
×
NEW
1260
        if rapid.Bool().Draw(t, "useZlibEncoding") {
×
NEW
1261
                encodingType = EncodingSortedZlib
×
NEW
1262
        }
×
1263

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

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

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

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

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

NEW
1289
        msg.ShortChanIDs = shortChanIDs
×
NEW
1290

×
NEW
1291
        return msg
×
1292
}
1293

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

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

×
NEW
1317
        msg.ChainHash = RandChainHash(t)
×
NEW
1318

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

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

NEW
1332
                scids[i] = scid
×
NEW
1333

×
NEW
1334
                scidSet.Add(scid)
×
1335
        }
1336

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

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

NEW
1350
        return msg
×
1351
}
1352

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

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

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

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

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

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

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

×
NEW
1389
        msg.NextRevocationKey = RandPubKey(t)
×
NEW
1390

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

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

NEW
1403
        return msg
×
1404
}
1405

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

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

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

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

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

×
NEW
1447
        if includeNonce {
×
NEW
1448
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
×
NEW
1449
        }
×
1450

NEW
1451
        cr, _ := RandCustomRecords(t, nil, true)
×
NEW
1452

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

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

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

×
NEW
1475
        extraData := RandExtraOpaqueData(t, nil)
×
NEW
1476
        if len(extraData) > 0 {
×
NEW
1477
                m.ExtraData = extraData
×
NEW
1478
        }
×
1479

NEW
1480
        return m
×
1481
}
1482

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

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

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

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

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

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

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

NEW
1520
        return msg
×
1521
}
1522

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

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

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

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

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

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

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

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

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

×
NEW
1592
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
NEW
1593
        if len(randData) > 0 {
×
NEW
1594
                msg.ExtraData = randData
×
NEW
1595
        }
×
1596

NEW
1597
        return msg
×
1598
}
1599

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

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

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

NEW
1632
        return msg
×
1633
}
1634

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

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

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

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

© 2025 Coveralls, Inc