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

lightningnetwork / lnd / 15759452760

19 Jun 2025 01:48PM UTC coverage: 69.436% (+1.3%) from 68.161%
15759452760

Pull #9625

github

web-flow
Merge 469117657 into e0a9705d5
Pull Request #9625: Add DeleteInvoice gRPC call

88 of 164 new or added lines in 5 files covered. (53.66%)

65 existing lines in 22 files now uncovered.

137612 of 198185 relevant lines covered (69.44%)

22066.8 hits per line

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

99.75
/lnwire/test_message.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "image/color"
7
        "math"
8

9
        "github.com/btcsuite/btcd/btcec/v2"
10
        "github.com/btcsuite/btcd/btcutil"
11
        "github.com/btcsuite/btcd/chaincfg/chainhash"
12
        "github.com/lightningnetwork/lnd/fn/v2"
13
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
14
        "github.com/lightningnetwork/lnd/tlv"
15
        "github.com/stretchr/testify/require"
16
        "pgregory.net/rapid"
17
)
18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

273
        return msg
100✔
274
}
275

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

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

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

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

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

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

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

324
        return msg
100✔
325
}
326

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

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

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

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

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

363
        return msg
100✔
364
}
365

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

100✔
488
        var disabledFlags ChanUpdateDisableFlags
100✔
489
        if rapid.Bool().Draw(t, "disableIncoming") {
152✔
490
                disabledFlags |= ChanUpdateDisableIncoming
52✔
491
        }
52✔
492
        if rapid.Bool().Draw(t, "disableOutgoing") {
159✔
493
                disabledFlags |= ChanUpdateDisableOutgoing
59✔
494
        }
59✔
495

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

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

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

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

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

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

556
        return msg
100✔
557
}
558

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

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

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

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

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

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

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

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

622
        return msg
100✔
623
}
624

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

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

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

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

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

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

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

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

682
        return msg
100✔
683
}
684

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

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

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

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

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

720
        return msg
100✔
721
}
722

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

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

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

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

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

755
        return sig
100✔
756
}
757

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

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

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

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

783
        return msg
13✔
784
}
785

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

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

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

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

806
        return msg
100✔
807
}
808

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

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

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

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

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

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

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

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

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

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

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

879
        return msg
100✔
880
}
881

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

979
        return msg
100✔
980
}
981

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

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

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

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

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

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

1021
        return msg
100✔
1022
}
1023

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

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

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

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

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

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

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

1075
// RandTestMessage populates the message with random data suitable for testing.
1076
// It uses the rapid testing framework to generate random values.
1077
//
1078
// This is part of the TestMessage interface.
1079
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
100✔
1080
        // Generate random compressed public key for node ID
100✔
1081
        pubKey := RandPubKey(t)
100✔
1082
        var nodeID [33]byte
100✔
1083
        copy(nodeID[:], pubKey.SerializeCompressed())
100✔
1084

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

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

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

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

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

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

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

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

1142
        var channelType *ChannelType
101✔
1143
        if includeChannelType {
153✔
1144
                channelType = RandChannelType(t)
52✔
1145
        }
52✔
1146

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1284
        return msg
100✔
1285
}
1286

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

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

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

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

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

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

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

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

1330
        msg.ShortChanIDs = shortChanIDs
100✔
1331

100✔
1332
        return msg
100✔
1333
}
1334

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

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

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

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

1365
        scidSet := fn.NewSet[ShortChannelID]()
87✔
1366
        scids := make([]ShortChannelID, numShortChanIDs)
87✔
1367
        for i := 0; i < numShortChanIDs; i++ {
800✔
1368
                scid := RandShortChannelID(t)
713✔
1369
                for scidSet.Contains(scid) {
808✔
1370
                        scid = RandShortChannelID(t)
95✔
1371
                }
95✔
1372

1373
                scids[i] = scid
713✔
1374

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

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

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

1391
        return msg
87✔
1392
}
1393

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

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

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

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

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

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

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

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

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

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

1444
        return msg
100✔
1445
}
1446

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

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

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

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

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

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

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

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

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

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

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

1521
        return m
102✔
1522
}
1523

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

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

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

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

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

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

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

1561
        return msg
100✔
1562
}
1563

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

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

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

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

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

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

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

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

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

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

1638
        return msg
100✔
1639
}
1640

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

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

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

1673
        return msg
112✔
1674
}
1675

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

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

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

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

© 2025 Coveralls, Inc