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

lightningnetwork / lnd / 17917482292

22 Sep 2025 01:50PM UTC coverage: 56.562% (-10.1%) from 66.668%
17917482292

Pull #10182

github

web-flow
Merge 9efe3bd8c into 055fb436e
Pull Request #10182: Aux feature bits

32 of 68 new or added lines in 5 files covered. (47.06%)

29734 existing lines in 467 files now uncovered.

98449 of 174056 relevant lines covered (56.56%)

1.18 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/tlv"
14
        "github.com/stretchr/testify/require"
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.
UNCOV
37
func (a *AcceptChannel) RandTestMessage(t *rapid.T) Message {
×
UNCOV
38
        var pendingChanID [32]byte
×
UNCOV
39
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
40
                t, "pendingChanID",
×
UNCOV
41
        )
×
UNCOV
42
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
43

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

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

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

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

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

×
UNCOV
138
        msg := &AnnounceSignatures2{
×
UNCOV
139
                ChannelID: tlv.NewRecordT[tlv.TlvType0, ChannelID](
×
UNCOV
140
                        chanID,
×
UNCOV
141
                ),
×
UNCOV
142
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2](scid),
×
UNCOV
143
                PartialSignature: tlv.NewRecordT[tlv.TlvType4, PartialSig](
×
UNCOV
144
                        *pSig,
×
UNCOV
145
                ),
×
UNCOV
146
                ExtraSignedFields: make(map[uint64][]byte),
×
UNCOV
147
        }
×
UNCOV
148

×
UNCOV
149
        randRecs, _ := RandSignedRangeRecords(t)
×
UNCOV
150
        if len(randRecs) > 0 {
×
UNCOV
151
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
×
UNCOV
152
        }
×
153

UNCOV
154
        return msg
×
155
}
156

157
// A compile time check to ensure ChannelAnnouncement1 implements the
158
// TestMessage interface.
159
var _ TestMessage = (*ChannelAnnouncement1)(nil)
160

161
// RandTestMessage populates the message with random data suitable for testing.
162
// It uses the rapid testing framework to generate random values.
163
//
164
// This is part of the TestMessage interface.
UNCOV
165
func (a *ChannelAnnouncement1) RandTestMessage(t *rapid.T) Message {
×
UNCOV
166
        // Generate Node IDs and Bitcoin keys (compressed public keys)
×
UNCOV
167
        node1PubKey := RandPubKey(t)
×
UNCOV
168
        node2PubKey := RandPubKey(t)
×
UNCOV
169
        bitcoin1PubKey := RandPubKey(t)
×
UNCOV
170
        bitcoin2PubKey := RandPubKey(t)
×
UNCOV
171

×
UNCOV
172
        // Convert to byte arrays
×
UNCOV
173
        var nodeID1, nodeID2, bitcoinKey1, bitcoinKey2 [33]byte
×
UNCOV
174
        copy(nodeID1[:], node1PubKey.SerializeCompressed())
×
UNCOV
175
        copy(nodeID2[:], node2PubKey.SerializeCompressed())
×
UNCOV
176
        copy(bitcoinKey1[:], bitcoin1PubKey.SerializeCompressed())
×
UNCOV
177
        copy(bitcoinKey2[:], bitcoin2PubKey.SerializeCompressed())
×
UNCOV
178

×
UNCOV
179
        // Ensure nodeID1 is numerically less than nodeID2
×
UNCOV
180
        // This is a requirement stated in the field description
×
UNCOV
181
        if bytes.Compare(nodeID1[:], nodeID2[:]) > 0 {
×
UNCOV
182
                nodeID1, nodeID2 = nodeID2, nodeID1
×
UNCOV
183
        }
×
184

185
        // Generate chain hash
UNCOV
186
        chainHash := RandChainHash(t)
×
UNCOV
187
        var hash chainhash.Hash
×
UNCOV
188
        copy(hash[:], chainHash[:])
×
UNCOV
189

×
UNCOV
190
        return &ChannelAnnouncement1{
×
UNCOV
191
                NodeSig1:        RandSignature(t),
×
UNCOV
192
                NodeSig2:        RandSignature(t),
×
UNCOV
193
                BitcoinSig1:     RandSignature(t),
×
UNCOV
194
                BitcoinSig2:     RandSignature(t),
×
UNCOV
195
                Features:        RandFeatureVector(t),
×
UNCOV
196
                ChainHash:       hash,
×
UNCOV
197
                ShortChannelID:  RandShortChannelID(t),
×
UNCOV
198
                NodeID1:         nodeID1,
×
UNCOV
199
                NodeID2:         nodeID2,
×
UNCOV
200
                BitcoinKey1:     bitcoinKey1,
×
UNCOV
201
                BitcoinKey2:     bitcoinKey2,
×
UNCOV
202
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
203
        }
×
204
}
205

206
// A compile time check to ensure ChannelAnnouncement2 implements the
207
// lnwire.TestMessage interface.
208
var _ TestMessage = (*ChannelAnnouncement2)(nil)
209

210
// RandTestMessage populates the message with random data suitable for testing.
211
// It uses the rapid testing framework to generate random values.
212
//
213
// This is part of the TestMessage interface.
UNCOV
214
func (c *ChannelAnnouncement2) RandTestMessage(t *rapid.T) Message {
×
UNCOV
215
        features := RandFeatureVector(t)
×
UNCOV
216
        shortChanID := RandShortChannelID(t)
×
UNCOV
217
        capacity := uint64(rapid.IntRange(1, 16777215).Draw(t, "capacity"))
×
UNCOV
218

×
UNCOV
219
        var nodeID1, nodeID2 [33]byte
×
UNCOV
220
        copy(nodeID1[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
221
        copy(nodeID2[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
222

×
UNCOV
223
        // Make sure nodeID1 is numerically less than nodeID2 (as per spec).
×
UNCOV
224
        if bytes.Compare(nodeID1[:], nodeID2[:]) > 0 {
×
UNCOV
225
                nodeID1, nodeID2 = nodeID2, nodeID1
×
UNCOV
226
        }
×
227

UNCOV
228
        chainHash := RandChainHash(t)
×
UNCOV
229
        var chainHashObj chainhash.Hash
×
UNCOV
230
        copy(chainHashObj[:], chainHash[:])
×
UNCOV
231

×
UNCOV
232
        msg := &ChannelAnnouncement2{
×
UNCOV
233
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
×
UNCOV
234
                        chainHashObj,
×
UNCOV
235
                ),
×
UNCOV
236
                Features: tlv.NewRecordT[tlv.TlvType2, RawFeatureVector](
×
UNCOV
237
                        *features,
×
UNCOV
238
                ),
×
UNCOV
239
                ShortChannelID: tlv.NewRecordT[tlv.TlvType4, ShortChannelID](
×
UNCOV
240
                        shortChanID,
×
UNCOV
241
                ),
×
UNCOV
242
                Capacity: tlv.NewPrimitiveRecord[tlv.TlvType6, uint64](
×
UNCOV
243
                        capacity,
×
UNCOV
244
                ),
×
UNCOV
245
                NodeID1: tlv.NewPrimitiveRecord[tlv.TlvType8, [33]byte](
×
UNCOV
246
                        nodeID1,
×
UNCOV
247
                ),
×
UNCOV
248
                NodeID2: tlv.NewPrimitiveRecord[tlv.TlvType10, [33]byte](
×
UNCOV
249
                        nodeID2,
×
UNCOV
250
                ),
×
UNCOV
251
                ExtraSignedFields: make(map[uint64][]byte),
×
UNCOV
252
        }
×
UNCOV
253

×
UNCOV
254
        msg.Signature.Val = RandSignature(t)
×
UNCOV
255
        msg.Signature.Val.ForceSchnorr()
×
UNCOV
256

×
UNCOV
257
        randRecs, _ := RandSignedRangeRecords(t)
×
UNCOV
258
        if len(randRecs) > 0 {
×
UNCOV
259
                msg.ExtraSignedFields = ExtraSignedFields(randRecs)
×
UNCOV
260
        }
×
261

262
        // Randomly include optional fields
UNCOV
263
        if rapid.Bool().Draw(t, "includeBitcoinKey1") {
×
UNCOV
264
                var bitcoinKey1 [33]byte
×
UNCOV
265
                copy(bitcoinKey1[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
266
                msg.BitcoinKey1 = tlv.SomeRecordT(
×
UNCOV
267
                        tlv.NewPrimitiveRecord[tlv.TlvType12, [33]byte](
×
UNCOV
268
                                bitcoinKey1,
×
UNCOV
269
                        ),
×
UNCOV
270
                )
×
UNCOV
271
        }
×
272

UNCOV
273
        if rapid.Bool().Draw(t, "includeBitcoinKey2") {
×
UNCOV
274
                var bitcoinKey2 [33]byte
×
UNCOV
275
                copy(bitcoinKey2[:], RandPubKey(t).SerializeCompressed())
×
UNCOV
276
                msg.BitcoinKey2 = tlv.SomeRecordT(
×
UNCOV
277
                        tlv.NewPrimitiveRecord[tlv.TlvType14, [33]byte](
×
UNCOV
278
                                bitcoinKey2,
×
UNCOV
279
                        ),
×
UNCOV
280
                )
×
UNCOV
281
        }
×
282

UNCOV
283
        if rapid.Bool().Draw(t, "includeMerkleRootHash") {
×
UNCOV
284
                hash := RandSHA256Hash(t)
×
UNCOV
285
                var merkleRootHash [32]byte
×
UNCOV
286
                copy(merkleRootHash[:], hash[:])
×
UNCOV
287
                msg.MerkleRootHash = tlv.SomeRecordT(
×
UNCOV
288
                        tlv.NewPrimitiveRecord[tlv.TlvType16, [32]byte](
×
UNCOV
289
                                merkleRootHash,
×
UNCOV
290
                        ),
×
UNCOV
291
                )
×
UNCOV
292
        }
×
293

UNCOV
294
        return msg
×
295
}
296

297
// A compile time check to ensure ChannelReady implements the lnwire.TestMessage
298
// interface.
299
var _ TestMessage = (*ChannelReady)(nil)
300

301
// RandTestMessage populates the message with random data suitable for testing.
302
// It uses the rapid testing framework to generate random values.
303
//
304
// This is part of the TestMessage interface.
UNCOV
305
func (c *ChannelReady) RandTestMessage(t *rapid.T) Message {
×
UNCOV
306
        msg := &ChannelReady{
×
UNCOV
307
                ChanID:                 RandChannelID(t),
×
UNCOV
308
                NextPerCommitmentPoint: RandPubKey(t),
×
UNCOV
309
                ExtraData:              RandExtraOpaqueData(t, nil),
×
UNCOV
310
        }
×
UNCOV
311

×
UNCOV
312
        includeAliasScid := rapid.Bool().Draw(t, "includeAliasScid")
×
UNCOV
313
        includeNextLocalNonce := rapid.Bool().Draw(t, "includeNextLocalNonce")
×
UNCOV
314
        includeAnnouncementNodeNonce := rapid.Bool().Draw(
×
UNCOV
315
                t, "includeAnnouncementNodeNonce",
×
UNCOV
316
        )
×
UNCOV
317
        includeAnnouncementBitcoinNonce := rapid.Bool().Draw(
×
UNCOV
318
                t, "includeAnnouncementBitcoinNonce",
×
UNCOV
319
        )
×
UNCOV
320

×
UNCOV
321
        if includeAliasScid {
×
UNCOV
322
                scid := RandShortChannelID(t)
×
UNCOV
323
                msg.AliasScid = &scid
×
UNCOV
324
        }
×
325

UNCOV
326
        if includeNextLocalNonce {
×
UNCOV
327
                nonce := RandMusig2Nonce(t)
×
UNCOV
328
                msg.NextLocalNonce = SomeMusig2Nonce(nonce)
×
UNCOV
329
        }
×
330

UNCOV
331
        if includeAnnouncementNodeNonce {
×
UNCOV
332
                nonce := RandMusig2Nonce(t)
×
UNCOV
333
                msg.AnnouncementNodeNonce = tlv.SomeRecordT(
×
UNCOV
334
                        tlv.NewRecordT[tlv.TlvType0, Musig2Nonce](nonce),
×
UNCOV
335
                )
×
UNCOV
336
        }
×
337

UNCOV
338
        if includeAnnouncementBitcoinNonce {
×
UNCOV
339
                nonce := RandMusig2Nonce(t)
×
UNCOV
340
                msg.AnnouncementBitcoinNonce = tlv.SomeRecordT(
×
UNCOV
341
                        tlv.NewRecordT[tlv.TlvType2, Musig2Nonce](nonce),
×
UNCOV
342
                )
×
UNCOV
343
        }
×
344

UNCOV
345
        return msg
×
346
}
347

348
// A compile time check to ensure ChannelReestablish implements the
349
// lnwire.TestMessage interface.
350
var _ TestMessage = (*ChannelReestablish)(nil)
351

352
// RandTestMessage populates the message with random data suitable for testing.
353
// It uses the rapid testing framework to generate random values.
354
//
355
// This is part of the TestMessage interface.
UNCOV
356
func (a *ChannelReestablish) RandTestMessage(t *rapid.T) Message {
×
UNCOV
357
        msg := &ChannelReestablish{
×
UNCOV
358
                ChanID: RandChannelID(t),
×
UNCOV
359
                NextLocalCommitHeight: rapid.Uint64().Draw(
×
UNCOV
360
                        t, "nextLocalCommitHeight",
×
UNCOV
361
                ),
×
UNCOV
362
                RemoteCommitTailHeight: rapid.Uint64().Draw(
×
UNCOV
363
                        t, "remoteCommitTailHeight",
×
UNCOV
364
                ),
×
UNCOV
365
                LastRemoteCommitSecret:    RandPaymentPreimage(t),
×
UNCOV
366
                LocalUnrevokedCommitPoint: RandPubKey(t),
×
UNCOV
367
                ExtraData:                 RandExtraOpaqueData(t, nil),
×
UNCOV
368
        }
×
UNCOV
369

×
UNCOV
370
        // Randomly decide whether to include optional fields
×
UNCOV
371
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
372
        includeDynHeight := rapid.Bool().Draw(t, "includeDynHeight")
×
UNCOV
373

×
UNCOV
374
        if includeLocalNonce {
×
UNCOV
375
                nonce := RandMusig2Nonce(t)
×
UNCOV
376
                msg.LocalNonce = SomeMusig2Nonce(nonce)
×
UNCOV
377
        }
×
378

UNCOV
379
        if includeDynHeight {
×
UNCOV
380
                height := DynHeight(rapid.Uint64().Draw(t, "dynHeight"))
×
UNCOV
381
                msg.DynHeight = fn.Some(height)
×
UNCOV
382
        }
×
383

UNCOV
384
        return msg
×
385
}
386

387
// A compile time check to ensure ChannelUpdate1 implements the TestMessage
388
// interface.
389
var _ TestMessage = (*ChannelUpdate1)(nil)
390

391
// RandTestMessage populates the message with random data suitable for testing.
392
// It uses the rapid testing framework to generate random values.
393
//
394
// This is part of the TestMessage interface.
UNCOV
395
func (a *ChannelUpdate1) RandTestMessage(t *rapid.T) Message {
×
UNCOV
396
        // Generate random message flags
×
UNCOV
397
        // Randomly decide whether to include max HTLC field
×
UNCOV
398
        includeMaxHtlc := rapid.Bool().Draw(t, "includeMaxHtlc")
×
UNCOV
399
        var msgFlags ChanUpdateMsgFlags
×
UNCOV
400
        if includeMaxHtlc {
×
UNCOV
401
                msgFlags |= ChanUpdateRequiredMaxHtlc
×
UNCOV
402
        }
×
403

404
        // Generate random channel flags
405
        // Randomly decide direction (node1 or node2)
UNCOV
406
        isNode2 := rapid.Bool().Draw(t, "isNode2")
×
UNCOV
407
        var chanFlags ChanUpdateChanFlags
×
UNCOV
408
        if isNode2 {
×
UNCOV
409
                chanFlags |= ChanUpdateDirection
×
UNCOV
410
        }
×
411

412
        // Randomly decide if channel is disabled
UNCOV
413
        isDisabled := rapid.Bool().Draw(t, "isDisabled")
×
UNCOV
414
        if isDisabled {
×
UNCOV
415
                chanFlags |= ChanUpdateDisabled
×
UNCOV
416
        }
×
417

418
        // Generate chain hash
UNCOV
419
        chainHash := RandChainHash(t)
×
UNCOV
420
        var hash chainhash.Hash
×
UNCOV
421
        copy(hash[:], chainHash[:])
×
UNCOV
422

×
UNCOV
423
        // Generate other random fields
×
UNCOV
424
        maxHtlc := MilliSatoshi(rapid.Uint64().Draw(t, "maxHtlc"))
×
UNCOV
425

×
UNCOV
426
        // If max HTLC flag is not set, we need to zero the value
×
UNCOV
427
        if !includeMaxHtlc {
×
UNCOV
428
                maxHtlc = 0
×
UNCOV
429
        }
×
430

431
        // Randomly decide if an inbound fee should be included.
432
        // By default, our extra opaque data will just be random TLV but if we
433
        // include an inbound fee, then we will also set the record in the
434
        // extra opaque data.
UNCOV
435
        var (
×
UNCOV
436
                customRecords, _ = RandCustomRecords(t, nil)
×
UNCOV
437
                inboundFee       tlv.OptionalRecordT[tlv.TlvType55555, Fee]
×
UNCOV
438
        )
×
UNCOV
439
        includeInboundFee := rapid.Bool().Draw(t, "includeInboundFee")
×
UNCOV
440
        if includeInboundFee {
×
UNCOV
441
                if customRecords == nil {
×
UNCOV
442
                        customRecords = make(CustomRecords)
×
UNCOV
443
                }
×
444

UNCOV
445
                inFeeBase := int32(
×
UNCOV
446
                        rapid.IntRange(-1000, 1000).Draw(t, "inFeeBase"),
×
UNCOV
447
                )
×
UNCOV
448
                inFeeProp := int32(
×
UNCOV
449
                        rapid.IntRange(-1000, 1000).Draw(t, "inFeeProp"),
×
UNCOV
450
                )
×
UNCOV
451
                fee := Fee{
×
UNCOV
452
                        BaseFee: inFeeBase,
×
UNCOV
453
                        FeeRate: inFeeProp,
×
UNCOV
454
                }
×
UNCOV
455
                inboundFee = tlv.SomeRecordT(
×
UNCOV
456
                        tlv.NewRecordT[tlv.TlvType55555, Fee](fee),
×
UNCOV
457
                )
×
UNCOV
458

×
UNCOV
459
                var b bytes.Buffer
×
UNCOV
460
                feeRecord := fee.Record()
×
UNCOV
461
                err := feeRecord.Encode(&b)
×
UNCOV
462
                require.NoError(t, err)
×
UNCOV
463

×
UNCOV
464
                customRecords[uint64(FeeRecordType)] = b.Bytes()
×
465
        }
466

UNCOV
467
        extraBytes, err := customRecords.Serialize()
×
UNCOV
468
        require.NoError(t, err)
×
UNCOV
469

×
UNCOV
470
        return &ChannelUpdate1{
×
UNCOV
471
                Signature:      RandSignature(t),
×
UNCOV
472
                ChainHash:      hash,
×
UNCOV
473
                ShortChannelID: RandShortChannelID(t),
×
UNCOV
474
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
475
                        t, "timestamp"),
×
UNCOV
476
                ),
×
UNCOV
477
                MessageFlags: msgFlags,
×
UNCOV
478
                ChannelFlags: chanFlags,
×
UNCOV
479
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
×
UNCOV
480
                        t, "timelockDelta"),
×
UNCOV
481
                ),
×
UNCOV
482
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
×
UNCOV
483
                        t, "htlcMinimum"),
×
UNCOV
484
                ),
×
UNCOV
485
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
486
                        t, "baseFee"),
×
UNCOV
487
                ),
×
UNCOV
488
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
489
                        t, "feeRate"),
×
UNCOV
490
                ),
×
UNCOV
491
                HtlcMaximumMsat: maxHtlc,
×
UNCOV
492
                InboundFee:      inboundFee,
×
UNCOV
493
                ExtraOpaqueData: extraBytes,
×
UNCOV
494
        }
×
495
}
496

497
// A compile time check to ensure ChannelUpdate2 implements the
498
// lnwire.TestMessage interface.
499
var _ TestMessage = (*ChannelUpdate2)(nil)
500

501
// RandTestMessage populates the message with random data suitable for testing.
502
// It uses the rapid testing framework to generate random values.
503
//
504
// This is part of the TestMessage interface.
UNCOV
505
func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
×
UNCOV
506
        shortChanID := RandShortChannelID(t)
×
UNCOV
507
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
×
UNCOV
508

×
UNCOV
509
        var disabledFlags ChanUpdateDisableFlags
×
UNCOV
510
        if rapid.Bool().Draw(t, "disableIncoming") {
×
UNCOV
511
                disabledFlags |= ChanUpdateDisableIncoming
×
UNCOV
512
        }
×
UNCOV
513
        if rapid.Bool().Draw(t, "disableOutgoing") {
×
UNCOV
514
                disabledFlags |= ChanUpdateDisableOutgoing
×
UNCOV
515
        }
×
516

UNCOV
517
        cltvExpiryDelta := uint16(rapid.IntRange(10, 200).Draw(
×
UNCOV
518
                t, "cltvExpiryDelta"),
×
UNCOV
519
        )
×
UNCOV
520

×
UNCOV
521
        htlcMinMsat := MilliSatoshi(rapid.IntRange(1, 10000).Draw(
×
UNCOV
522
                t, "htlcMinMsat"),
×
UNCOV
523
        )
×
UNCOV
524
        htlcMaxMsat := MilliSatoshi(rapid.IntRange(10000, 100000000).Draw(
×
UNCOV
525
                t, "htlcMaxMsat"),
×
UNCOV
526
        )
×
UNCOV
527
        feeBaseMsat := uint32(rapid.IntRange(0, 10000).Draw(t, "feeBaseMsat"))
×
UNCOV
528
        feeProportionalMillionths := uint32(rapid.IntRange(0, 10000).Draw(
×
UNCOV
529
                t, "feeProportionalMillionths"),
×
UNCOV
530
        )
×
UNCOV
531

×
UNCOV
532
        chainHash := RandChainHash(t)
×
UNCOV
533
        var chainHashObj chainhash.Hash
×
UNCOV
534
        copy(chainHashObj[:], chainHash[:])
×
UNCOV
535

×
UNCOV
536
        //nolint:ll
×
UNCOV
537
        msg := &ChannelUpdate2{
×
UNCOV
538
                ChainHash: tlv.NewPrimitiveRecord[tlv.TlvType0, chainhash.Hash](
×
UNCOV
539
                        chainHashObj,
×
UNCOV
540
                ),
×
UNCOV
541
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2, ShortChannelID](
×
UNCOV
542
                        shortChanID,
×
UNCOV
543
                ),
×
UNCOV
544
                BlockHeight: tlv.NewPrimitiveRecord[tlv.TlvType4, uint32](
×
UNCOV
545
                        blockHeight,
×
UNCOV
546
                ),
×
UNCOV
547
                DisabledFlags: tlv.NewPrimitiveRecord[tlv.TlvType6, ChanUpdateDisableFlags]( //nolint:ll
×
UNCOV
548
                        disabledFlags,
×
UNCOV
549
                ),
×
UNCOV
550
                CLTVExpiryDelta: tlv.NewPrimitiveRecord[tlv.TlvType10, uint16](
×
UNCOV
551
                        cltvExpiryDelta,
×
UNCOV
552
                ),
×
UNCOV
553
                HTLCMinimumMsat: tlv.NewPrimitiveRecord[tlv.TlvType12, MilliSatoshi](
×
UNCOV
554
                        htlcMinMsat,
×
UNCOV
555
                ),
×
UNCOV
556
                HTLCMaximumMsat: tlv.NewPrimitiveRecord[tlv.TlvType14, MilliSatoshi](
×
UNCOV
557
                        htlcMaxMsat,
×
UNCOV
558
                ),
×
UNCOV
559
                FeeBaseMsat: tlv.NewPrimitiveRecord[tlv.TlvType16, uint32](
×
UNCOV
560
                        feeBaseMsat,
×
UNCOV
561
                ),
×
UNCOV
562
                FeeProportionalMillionths: tlv.NewPrimitiveRecord[tlv.TlvType18, uint32](
×
UNCOV
563
                        feeProportionalMillionths,
×
UNCOV
564
                ),
×
UNCOV
565
                ExtraSignedFields: make(map[uint64][]byte),
×
UNCOV
566
        }
×
UNCOV
567

×
UNCOV
568
        msg.Signature.Val = RandSignature(t)
×
UNCOV
569
        msg.Signature.Val.ForceSchnorr()
×
UNCOV
570

×
UNCOV
571
        if rapid.Bool().Draw(t, "isSecondPeer") {
×
UNCOV
572
                msg.SecondPeer = tlv.SomeRecordT(
×
UNCOV
573
                        tlv.RecordT[tlv.TlvType8, TrueBoolean]{},
×
UNCOV
574
                )
×
UNCOV
575
        }
×
576

UNCOV
577
        return msg
×
578
}
579

580
// A compile time check to ensure ClosingComplete implements the
581
// lnwire.TestMessage interface.
582
var _ TestMessage = (*ClosingComplete)(nil)
583

584
// RandTestMessage populates the message with random data suitable for testing.
585
// It uses the rapid testing framework to generate random values.
586
//
587
// This is part of the TestMessage interface.
UNCOV
588
func (c *ClosingComplete) RandTestMessage(t *rapid.T) Message {
×
UNCOV
589
        msg := &ClosingComplete{
×
UNCOV
590
                ChannelID: RandChannelID(t),
×
UNCOV
591
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
×
UNCOV
592
                        t, "feeSatoshis"),
×
UNCOV
593
                ),
×
UNCOV
594
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
×
UNCOV
595
                        t, "lockTime",
×
UNCOV
596
                ),
×
UNCOV
597
                CloseeScript: RandDeliveryAddress(t),
×
UNCOV
598
                CloserScript: RandDeliveryAddress(t),
×
UNCOV
599
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
600
        }
×
UNCOV
601

×
UNCOV
602
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
×
UNCOV
603
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
×
UNCOV
604
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
×
UNCOV
605

×
UNCOV
606
        // Ensure at least one signature is present.
×
UNCOV
607
        if !includeCloserNoClosee && !includeNoCloserClosee &&
×
UNCOV
608
                !includeCloserAndClosee {
×
UNCOV
609

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

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

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

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

UNCOV
643
        return msg
×
644
}
645

646
// A compile time check to ensure ClosingSig implements the lnwire.TestMessage
647
// interface.
648
var _ TestMessage = (*ClosingSig)(nil)
649

650
// RandTestMessage populates the message with random data suitable for testing.
651
// It uses the rapid testing framework to generate random values.
652
//
653
// This is part of the TestMessage interface.
UNCOV
654
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
655
        msg := &ClosingSig{
×
UNCOV
656
                ChannelID:    RandChannelID(t),
×
UNCOV
657
                CloseeScript: RandDeliveryAddress(t),
×
UNCOV
658
                CloserScript: RandDeliveryAddress(t),
×
UNCOV
659
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
660
        }
×
UNCOV
661

×
UNCOV
662
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
×
UNCOV
663
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
×
UNCOV
664
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
×
UNCOV
665

×
UNCOV
666
        // Ensure at least one signature is present.
×
UNCOV
667
        if !includeCloserNoClosee && !includeNoCloserClosee &&
×
UNCOV
668
                !includeCloserAndClosee {
×
UNCOV
669

×
UNCOV
670
                // If all are false, enable at least one randomly.
×
UNCOV
671
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
×
UNCOV
672
                switch choice {
×
UNCOV
673
                case 0:
×
UNCOV
674
                        includeCloserNoClosee = true
×
UNCOV
675
                case 1:
×
UNCOV
676
                        includeNoCloserClosee = true
×
UNCOV
677
                case 2:
×
UNCOV
678
                        includeCloserAndClosee = true
×
679
                }
680
        }
681

UNCOV
682
        if includeCloserNoClosee {
×
UNCOV
683
                sig := RandSignature(t)
×
UNCOV
684
                msg.CloserNoClosee = tlv.SomeRecordT(
×
UNCOV
685
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
×
UNCOV
686
                )
×
UNCOV
687
        }
×
688

UNCOV
689
        if includeNoCloserClosee {
×
UNCOV
690
                sig := RandSignature(t)
×
UNCOV
691
                msg.NoCloserClosee = tlv.SomeRecordT(
×
UNCOV
692
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
×
UNCOV
693
                )
×
UNCOV
694
        }
×
695

UNCOV
696
        if includeCloserAndClosee {
×
UNCOV
697
                sig := RandSignature(t)
×
UNCOV
698
                msg.CloserAndClosee = tlv.SomeRecordT(
×
UNCOV
699
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
×
UNCOV
700
                )
×
UNCOV
701
        }
×
702

UNCOV
703
        return msg
×
704
}
705

706
// A compile time check to ensure ClosingSigned implements the
707
// lnwire.TestMessage interface.
708
var _ TestMessage = (*ClosingSigned)(nil)
709

710
// RandTestMessage populates the message with random data suitable for testing.
711
// It uses the rapid testing framework to generate random values.
712
//
713
// This is part of the TestMessage interface.
UNCOV
714
func (c *ClosingSigned) RandTestMessage(t *rapid.T) Message {
×
UNCOV
715
        // Generate a random boolean to decide whether to include CommitSig or
×
UNCOV
716
        // PartialSig Since they're mutually exclusive, when one is populated,
×
UNCOV
717
        // the other must be blank.
×
UNCOV
718
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
UNCOV
719

×
UNCOV
720
        msg := &ClosingSigned{
×
UNCOV
721
                ChannelID: RandChannelID(t),
×
UNCOV
722
                FeeSatoshis: btcutil.Amount(
×
UNCOV
723
                        rapid.Int64Range(0, 1000000).Draw(t, "feeSatoshis"),
×
UNCOV
724
                ),
×
UNCOV
725
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
726
        }
×
UNCOV
727

×
UNCOV
728
        if usePartialSig {
×
UNCOV
729
                sigBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
730
                        t, "sigScalar",
×
UNCOV
731
                )
×
UNCOV
732
                var s btcec.ModNScalar
×
UNCOV
733
                _ = s.SetByteSlice(sigBytes)
×
UNCOV
734

×
UNCOV
735
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
×
UNCOV
736
                msg.Signature = Sig{}
×
UNCOV
737
        } else {
×
UNCOV
738
                msg.Signature = RandSignature(t)
×
UNCOV
739
        }
×
740

UNCOV
741
        return msg
×
742
}
743

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

748
// RandTestMessage populates the message with random data suitable for testing.
749
// It uses the rapid testing framework to generate random values.
750
//
751
// This is part of the TestMessage interface.
UNCOV
752
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
753
        cr, _ := RandCustomRecords(t, nil)
×
UNCOV
754
        sig := &CommitSig{
×
UNCOV
755
                ChanID:        RandChannelID(t),
×
UNCOV
756
                CommitSig:     RandSignature(t),
×
UNCOV
757
                CustomRecords: cr,
×
UNCOV
758
        }
×
UNCOV
759

×
UNCOV
760
        numHtlcSigs := rapid.IntRange(0, 20).Draw(t, "numHtlcSigs")
×
UNCOV
761
        htlcSigs := make([]Sig, numHtlcSigs)
×
UNCOV
762
        for i := 0; i < numHtlcSigs; i++ {
×
UNCOV
763
                htlcSigs[i] = RandSignature(t)
×
UNCOV
764
        }
×
765

UNCOV
766
        if len(htlcSigs) > 0 {
×
UNCOV
767
                sig.HtlcSigs = htlcSigs
×
UNCOV
768
        }
×
769

UNCOV
770
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
UNCOV
771
        if includePartialSig {
×
UNCOV
772
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
773
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
774
        }
×
775

UNCOV
776
        return sig
×
777
}
778

779
// A compile time check to ensure Custom implements the lnwire.TestMessage
780
// interface.
781
var _ TestMessage = (*Custom)(nil)
782

783
// RandTestMessage populates the message with random data suitable for testing.
784
// It uses the rapid testing framework to generate random values.
785
//
786
// This is part of the TestMessage interface.
UNCOV
787
func (c *Custom) RandTestMessage(t *rapid.T) Message {
×
UNCOV
788
        msgType := MessageType(
×
UNCOV
789
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
×
UNCOV
790
                        t, "customMsgType",
×
UNCOV
791
                ),
×
UNCOV
792
        )
×
UNCOV
793

×
UNCOV
794
        dataLen := rapid.IntRange(0, 1000).Draw(t, "customDataLength")
×
UNCOV
795
        data := rapid.SliceOfN(rapid.Byte(), dataLen, dataLen).Draw(
×
UNCOV
796
                t, "customData",
×
UNCOV
797
        )
×
UNCOV
798

×
UNCOV
799
        msg, err := NewCustom(msgType, data)
×
UNCOV
800
        if err != nil {
×
801
                panic(fmt.Sprintf("Error creating custom message: %v", err))
×
802
        }
803

UNCOV
804
        return msg
×
805
}
806

807
// A compile time check to ensure DynAck implements the lnwire.TestMessage
808
// interface.
809
var _ TestMessage = (*DynAck)(nil)
810

811
// RandTestMessage populates the message with random data suitable for testing.
812
// It uses the rapid testing framework to generate random values.
813
//
814
// This is part of the TestMessage interface.
UNCOV
815
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
×
UNCOV
816
        msg := &DynAck{
×
UNCOV
817
                ChanID: RandChannelID(t),
×
UNCOV
818
        }
×
UNCOV
819

×
UNCOV
820
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
821
        if includeLocalNonce {
×
UNCOV
822
                nonce := RandMusig2Nonce(t)
×
UNCOV
823
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
×
UNCOV
824
                msg.LocalNonce = tlv.SomeRecordT(rec)
×
UNCOV
825
        }
×
826

827
        // Create a tlv type lists to hold all known records which will be
828
        // ignored when creating ExtraData records.
UNCOV
829
        ignoreRecords := fn.NewSet[uint64]()
×
UNCOV
830
        for i := range uint64(15) {
×
UNCOV
831
                // Ignore known records.
×
UNCOV
832
                if i%2 == 0 {
×
UNCOV
833
                        ignoreRecords.Add(i)
×
UNCOV
834
                }
×
835
        }
836

UNCOV
837
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
×
UNCOV
838

×
UNCOV
839
        return msg
×
840
}
841

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

846
// RandTestMessage populates the message with random data suitable for testing.
847
// It uses the rapid testing framework to generate random values.
848
//
849
// This is part of the TestMessage interface.
UNCOV
850
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
×
UNCOV
851
        msg := &DynPropose{
×
UNCOV
852
                ChanID: RandChannelID(t),
×
UNCOV
853
        }
×
UNCOV
854

×
UNCOV
855
        // Randomly decide which optional fields to include
×
UNCOV
856
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
UNCOV
857
        includeMaxValueInFlight := rapid.Bool().Draw(
×
UNCOV
858
                t, "includeMaxValueInFlight",
×
UNCOV
859
        )
×
UNCOV
860
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
UNCOV
861
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
UNCOV
862
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
UNCOV
863
                t, "includeMaxAcceptedHTLCs",
×
UNCOV
864
        )
×
UNCOV
865
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
UNCOV
866

×
UNCOV
867
        // Generate random values for each included field
×
UNCOV
868
        if includeDustLimit {
×
UNCOV
869
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
×
UNCOV
870
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
UNCOV
871
                rec.Val = tlv.NewBigSizeT(val)
×
UNCOV
872
                msg.DustLimit = tlv.SomeRecordT(rec)
×
UNCOV
873
        }
×
874

UNCOV
875
        if includeMaxValueInFlight {
×
UNCOV
876
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
×
UNCOV
877
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
UNCOV
878
                rec.Val = val
×
UNCOV
879
                msg.MaxValueInFlight = tlv.SomeRecordT(rec)
×
UNCOV
880
        }
×
881

UNCOV
882
        if includeChannelReserve {
×
UNCOV
883
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
×
UNCOV
884
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
UNCOV
885
                rec.Val = tlv.NewBigSizeT(val)
×
UNCOV
886
                msg.ChannelReserve = tlv.SomeRecordT(rec)
×
UNCOV
887
        }
×
888

UNCOV
889
        if includeCsvDelay {
×
UNCOV
890
                csvDelay := msg.CsvDelay.Zero()
×
UNCOV
891
                val := rapid.Uint16().Draw(t, "csvDelay")
×
UNCOV
892
                csvDelay.Val = val
×
UNCOV
893
                msg.CsvDelay = tlv.SomeRecordT(csvDelay)
×
UNCOV
894
        }
×
895

UNCOV
896
        if includeMaxAcceptedHTLCs {
×
UNCOV
897
                maxHtlcs := msg.MaxAcceptedHTLCs.Zero()
×
UNCOV
898
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
UNCOV
899
                msg.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
UNCOV
900
        }
×
901

UNCOV
902
        if includeChannelType {
×
UNCOV
903
                chanType := msg.ChannelType.Zero()
×
UNCOV
904
                chanType.Val = *RandChannelType(t)
×
UNCOV
905
                msg.ChannelType = tlv.SomeRecordT(chanType)
×
UNCOV
906
        }
×
907

908
        // Create a tlv type lists to hold all known records which will be
909
        // ignored when creating ExtraData records.
UNCOV
910
        ignoreRecords := fn.NewSet[uint64]()
×
UNCOV
911
        for i := range uint64(13) {
×
UNCOV
912
                // Ignore known records.
×
UNCOV
913
                if i%2 == 0 {
×
UNCOV
914
                        ignoreRecords.Add(i)
×
UNCOV
915
                }
×
916
        }
917

UNCOV
918
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
×
UNCOV
919

×
UNCOV
920
        return msg
×
921
}
922

923
// A compile time check to ensure DynReject implements the lnwire.TestMessage
924
// interface.
925
var _ TestMessage = (*DynReject)(nil)
926

927
// RandTestMessage populates the message with random data suitable for testing.
928
// It uses the rapid testing framework to generate random values.
929
//
930
// This is part of the TestMessage interface.
UNCOV
931
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
×
UNCOV
932
        featureVec := NewRawFeatureVector()
×
UNCOV
933

×
UNCOV
934
        numFeatures := rapid.IntRange(0, 8).Draw(t, "numRejections")
×
UNCOV
935
        for i := 0; i < numFeatures; i++ {
×
UNCOV
936
                bit := FeatureBit(
×
UNCOV
937
                        rapid.IntRange(0, 31).Draw(
×
UNCOV
938
                                t, fmt.Sprintf("rejectionBit-%d", i),
×
UNCOV
939
                        ),
×
UNCOV
940
                )
×
UNCOV
941
                featureVec.Set(bit)
×
UNCOV
942
        }
×
943

UNCOV
944
        var extraData ExtraOpaqueData
×
UNCOV
945
        randData := RandExtraOpaqueData(t, nil)
×
UNCOV
946
        if len(randData) > 0 {
×
UNCOV
947
                extraData = randData
×
UNCOV
948
        }
×
949

UNCOV
950
        return &DynReject{
×
UNCOV
951
                ChanID:           RandChannelID(t),
×
UNCOV
952
                UpdateRejections: *featureVec,
×
UNCOV
953
                ExtraData:        extraData,
×
UNCOV
954
        }
×
955
}
956

957
// A compile time check to ensure DynCommit implements the lnwire.TestMessage
958
// interface.
959
var _ TestMessage = (*DynCommit)(nil)
960

961
// RandTestMessage populates the message with random data suitable for testing.
962
// It uses the rapid testing framework to generate random values.
963
//
964
// This is part of the TestMessage interface.
UNCOV
965
func (dc *DynCommit) RandTestMessage(t *rapid.T) Message {
×
UNCOV
966
        chanID := RandChannelID(t)
×
UNCOV
967

×
UNCOV
968
        da := &DynAck{
×
UNCOV
969
                ChanID: chanID,
×
UNCOV
970
        }
×
UNCOV
971

×
UNCOV
972
        dp := &DynPropose{
×
UNCOV
973
                ChanID: chanID,
×
UNCOV
974
        }
×
UNCOV
975

×
UNCOV
976
        // Randomly decide which optional fields to include
×
UNCOV
977
        includeDustLimit := rapid.Bool().Draw(t, "includeDustLimit")
×
UNCOV
978
        includeMaxValueInFlight := rapid.Bool().Draw(
×
UNCOV
979
                t, "includeMaxValueInFlight",
×
UNCOV
980
        )
×
UNCOV
981
        includeChannelReserve := rapid.Bool().Draw(t, "includeChannelReserve")
×
UNCOV
982
        includeCsvDelay := rapid.Bool().Draw(t, "includeCsvDelay")
×
UNCOV
983
        includeMaxAcceptedHTLCs := rapid.Bool().Draw(
×
UNCOV
984
                t, "includeMaxAcceptedHTLCs",
×
UNCOV
985
        )
×
UNCOV
986
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
UNCOV
987

×
UNCOV
988
        // Generate random values for each included field
×
UNCOV
989
        if includeDustLimit {
×
UNCOV
990
                var rec tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
×
UNCOV
991
                val := btcutil.Amount(rapid.Uint32().Draw(t, "dustLimit"))
×
UNCOV
992
                rec.Val = tlv.NewBigSizeT(val)
×
UNCOV
993
                dp.DustLimit = tlv.SomeRecordT(rec)
×
UNCOV
994
        }
×
995

UNCOV
996
        if includeMaxValueInFlight {
×
UNCOV
997
                var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
×
UNCOV
998
                val := MilliSatoshi(rapid.Uint64().Draw(t, "maxValueInFlight"))
×
UNCOV
999
                rec.Val = val
×
UNCOV
1000
                dp.MaxValueInFlight = tlv.SomeRecordT(rec)
×
UNCOV
1001
        }
×
1002

UNCOV
1003
        if includeChannelReserve {
×
UNCOV
1004
                var rec tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
×
UNCOV
1005
                val := btcutil.Amount(rapid.Uint32().Draw(t, "channelReserve"))
×
UNCOV
1006
                rec.Val = tlv.NewBigSizeT(val)
×
UNCOV
1007
                dp.ChannelReserve = tlv.SomeRecordT(rec)
×
UNCOV
1008
        }
×
1009

UNCOV
1010
        if includeCsvDelay {
×
UNCOV
1011
                csvDelay := dp.CsvDelay.Zero()
×
UNCOV
1012
                val := rapid.Uint16().Draw(t, "csvDelay")
×
UNCOV
1013
                csvDelay.Val = val
×
UNCOV
1014
                dp.CsvDelay = tlv.SomeRecordT(csvDelay)
×
UNCOV
1015
        }
×
1016

UNCOV
1017
        if includeMaxAcceptedHTLCs {
×
UNCOV
1018
                maxHtlcs := dp.MaxAcceptedHTLCs.Zero()
×
UNCOV
1019
                maxHtlcs.Val = rapid.Uint16().Draw(t, "maxAcceptedHTLCs")
×
UNCOV
1020
                dp.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs)
×
UNCOV
1021
        }
×
1022

UNCOV
1023
        if includeChannelType {
×
UNCOV
1024
                chanType := dp.ChannelType.Zero()
×
UNCOV
1025
                chanType.Val = *RandChannelType(t)
×
UNCOV
1026
                dp.ChannelType = tlv.SomeRecordT(chanType)
×
UNCOV
1027
        }
×
1028

UNCOV
1029
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
1030
        if includeLocalNonce {
×
UNCOV
1031
                nonce := RandMusig2Nonce(t)
×
UNCOV
1032
                rec := tlv.NewRecordT[tlv.TlvType14](nonce)
×
UNCOV
1033
                da.LocalNonce = tlv.SomeRecordT(rec)
×
UNCOV
1034
        }
×
1035

1036
        // Create a tlv type lists to hold all known records which will be
1037
        // ignored when creating ExtraData records.
UNCOV
1038
        ignoreRecords := fn.NewSet[uint64]()
×
UNCOV
1039
        for i := range uint64(15) {
×
UNCOV
1040
                // Ignore known records.
×
UNCOV
1041
                if i%2 == 0 {
×
UNCOV
1042
                        ignoreRecords.Add(i)
×
UNCOV
1043
                }
×
1044
        }
UNCOV
1045
        msg := &DynCommit{
×
UNCOV
1046
                DynPropose: *dp,
×
UNCOV
1047
                DynAck:     *da,
×
UNCOV
1048
        }
×
UNCOV
1049

×
UNCOV
1050
        msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
×
UNCOV
1051

×
UNCOV
1052
        return msg
×
1053
}
1054

1055
// A compile time check to ensure FundingCreated implements the TestMessage
1056
// interface.
1057
var _ TestMessage = (*FundingCreated)(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.
UNCOV
1063
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1064
        var pendingChanID [32]byte
×
UNCOV
1065
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
1066
                t, "pendingChanID",
×
UNCOV
1067
        )
×
UNCOV
1068
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
1069

×
UNCOV
1070
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
UNCOV
1071
        var partialSig OptPartialSigWithNonceTLV
×
UNCOV
1072
        var commitSig Sig
×
UNCOV
1073

×
UNCOV
1074
        if includePartialSig {
×
UNCOV
1075
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
1076
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
1077

×
UNCOV
1078
                // When using partial sig, CommitSig should be empty/blank.
×
UNCOV
1079
                commitSig = Sig{}
×
UNCOV
1080
        } else {
×
UNCOV
1081
                commitSig = RandSignature(t)
×
UNCOV
1082
        }
×
1083

UNCOV
1084
        return &FundingCreated{
×
UNCOV
1085
                PendingChannelID: pendingChanID,
×
UNCOV
1086
                FundingPoint:     RandOutPoint(t),
×
UNCOV
1087
                CommitSig:        commitSig,
×
UNCOV
1088
                PartialSig:       partialSig,
×
UNCOV
1089
                ExtraData:        RandExtraOpaqueData(t, nil),
×
UNCOV
1090
        }
×
1091
}
1092

1093
// A compile time check to ensure FundingSigned implements the
1094
// lnwire.TestMessage interface.
1095
var _ TestMessage = (*FundingSigned)(nil)
1096

1097
// RandTestMessage populates the message with random data suitable for testing.
1098
// It uses the rapid testing framework to generate random values.
1099
//
1100
// This is part of the TestMessage interface.
UNCOV
1101
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1102
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
UNCOV
1103

×
UNCOV
1104
        msg := &FundingSigned{
×
UNCOV
1105
                ChanID:    RandChannelID(t),
×
UNCOV
1106
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1107
        }
×
UNCOV
1108

×
UNCOV
1109
        if usePartialSig {
×
UNCOV
1110
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
1111
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
1112

×
UNCOV
1113
                msg.CommitSig = Sig{}
×
UNCOV
1114
        } else {
×
UNCOV
1115
                msg.CommitSig = RandSignature(t)
×
UNCOV
1116
        }
×
1117

UNCOV
1118
        return msg
×
1119
}
1120

1121
// A compile time check to ensure GossipTimestampRange implements the
1122
// lnwire.TestMessage interface.
1123
var _ TestMessage = (*GossipTimestampRange)(nil)
1124

1125
// RandTestMessage populates the message with random data suitable for testing.
1126
// It uses the rapid testing framework to generate random values.
1127
//
1128
// This is part of the TestMessage interface.
UNCOV
1129
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1130
        var chainHash chainhash.Hash
×
UNCOV
1131
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
1132
        copy(chainHash[:], hashBytes)
×
UNCOV
1133

×
UNCOV
1134
        msg := &GossipTimestampRange{
×
UNCOV
1135
                ChainHash:      chainHash,
×
UNCOV
1136
                FirstTimestamp: rapid.Uint32().Draw(t, "firstTimestamp"),
×
UNCOV
1137
                TimestampRange: rapid.Uint32().Draw(t, "timestampRange"),
×
UNCOV
1138
                ExtraData:      RandExtraOpaqueData(t, nil),
×
UNCOV
1139
        }
×
UNCOV
1140

×
UNCOV
1141
        includeFirstBlockHeight := rapid.Bool().Draw(
×
UNCOV
1142
                t, "includeFirstBlockHeight",
×
UNCOV
1143
        )
×
UNCOV
1144
        includeBlockRange := rapid.Bool().Draw(t, "includeBlockRange")
×
UNCOV
1145

×
UNCOV
1146
        if includeFirstBlockHeight {
×
UNCOV
1147
                height := rapid.Uint32().Draw(t, "firstBlockHeight")
×
UNCOV
1148
                msg.FirstBlockHeight = tlv.SomeRecordT(
×
UNCOV
1149
                        tlv.RecordT[tlv.TlvType2, uint32]{Val: height},
×
UNCOV
1150
                )
×
UNCOV
1151
        }
×
1152

UNCOV
1153
        if includeBlockRange {
×
UNCOV
1154
                blockRange := rapid.Uint32().Draw(t, "blockRange")
×
UNCOV
1155
                msg.BlockRange = tlv.SomeRecordT(
×
UNCOV
1156
                        tlv.RecordT[tlv.TlvType4, uint32]{Val: blockRange},
×
UNCOV
1157
                )
×
UNCOV
1158
        }
×
1159

UNCOV
1160
        return msg
×
1161
}
1162

1163
// RandTestMessage populates the message with random data suitable for testing.
1164
// It uses the rapid testing framework to generate random values.
1165
//
1166
// This is part of the TestMessage interface.
UNCOV
1167
func (msg *Init) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1168
        global := NewRawFeatureVector()
×
UNCOV
1169
        local := NewRawFeatureVector()
×
UNCOV
1170

×
UNCOV
1171
        numGlobalFeatures := rapid.IntRange(0, 20).Draw(t, "numGlobalFeatures")
×
UNCOV
1172
        for i := 0; i < numGlobalFeatures; i++ {
×
UNCOV
1173
                bit := FeatureBit(
×
UNCOV
1174
                        rapid.IntRange(0, 100).Draw(
×
UNCOV
1175
                                t, fmt.Sprintf("globalFeatureBit%d", i),
×
UNCOV
1176
                        ),
×
UNCOV
1177
                )
×
UNCOV
1178
                global.Set(bit)
×
UNCOV
1179
        }
×
1180

UNCOV
1181
        numLocalFeatures := rapid.IntRange(0, 20).Draw(t, "numLocalFeatures")
×
UNCOV
1182
        for i := 0; i < numLocalFeatures; i++ {
×
UNCOV
1183
                bit := FeatureBit(
×
UNCOV
1184
                        rapid.IntRange(0, 100).Draw(
×
UNCOV
1185
                                t, fmt.Sprintf("localFeatureBit%d", i),
×
UNCOV
1186
                        ),
×
UNCOV
1187
                )
×
UNCOV
1188
                local.Set(bit)
×
UNCOV
1189
        }
×
1190

UNCOV
1191
        return NewInitMessage(global, local)
×
1192
}
1193

1194
// A compile time check to ensure KickoffSig implements the lnwire.TestMessage
1195
// interface.
1196
var _ TestMessage = (*KickoffSig)(nil)
1197

1198
// RandTestMessage populates the message with random data suitable for testing.
1199
// It uses the rapid testing framework to generate random values.
1200
//
1201
// This is part of the TestMessage interface.
UNCOV
1202
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1203
        return &KickoffSig{
×
UNCOV
1204
                ChanID:    RandChannelID(t),
×
UNCOV
1205
                Signature: RandSignature(t),
×
UNCOV
1206
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1207
        }
×
UNCOV
1208
}
×
1209

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

1214
// RandTestMessage populates the message with random data suitable for testing.
1215
// It uses the rapid testing framework to generate random values.
1216
//
1217
// This is part of the TestMessage interface.
UNCOV
1218
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1219
        // Generate random compressed public key for node ID
×
UNCOV
1220
        pubKey := RandPubKey(t)
×
UNCOV
1221
        var nodeID [33]byte
×
UNCOV
1222
        copy(nodeID[:], pubKey.SerializeCompressed())
×
UNCOV
1223

×
UNCOV
1224
        // Generate random RGB color
×
UNCOV
1225
        rgbColor := color.RGBA{
×
UNCOV
1226
                R: uint8(rapid.IntRange(0, 255).Draw(t, "rgbR")),
×
UNCOV
1227
                G: uint8(rapid.IntRange(0, 255).Draw(t, "rgbG")),
×
UNCOV
1228
                B: uint8(rapid.IntRange(0, 255).Draw(t, "rgbB")),
×
UNCOV
1229
        }
×
UNCOV
1230

×
UNCOV
1231
        return &NodeAnnouncement{
×
UNCOV
1232
                Signature: RandSignature(t),
×
UNCOV
1233
                Features:  RandFeatureVector(t),
×
UNCOV
1234
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
1235
                        t, "timestamp"),
×
UNCOV
1236
                ),
×
UNCOV
1237
                NodeID:          nodeID,
×
UNCOV
1238
                RGBColor:        rgbColor,
×
UNCOV
1239
                Alias:           RandNodeAlias(t),
×
UNCOV
1240
                Addresses:       RandNetAddrs(t),
×
UNCOV
1241
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
1242
        }
×
UNCOV
1243
}
×
1244

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

1249
// RandTestMessage populates the message with random data suitable for testing.
1250
// It uses the rapid testing framework to generate random values.
1251
//
1252
// This is part of the TestMessage interface.
UNCOV
1253
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1254
        chainHash := RandChainHash(t)
×
UNCOV
1255
        var hash chainhash.Hash
×
UNCOV
1256
        copy(hash[:], chainHash[:])
×
UNCOV
1257

×
UNCOV
1258
        var pendingChanID [32]byte
×
UNCOV
1259
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
1260
                t, "pendingChanID",
×
UNCOV
1261
        )
×
UNCOV
1262
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
1263

×
UNCOV
1264
        includeChannelType := rapid.Bool().Draw(t, "includeChannelType")
×
UNCOV
1265
        includeLeaseExpiry := rapid.Bool().Draw(t, "includeLeaseExpiry")
×
UNCOV
1266
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
1267

×
UNCOV
1268
        var channelFlags FundingFlag
×
UNCOV
1269
        if rapid.Bool().Draw(t, "announceChannel") {
×
UNCOV
1270
                channelFlags |= FFAnnounceChannel
×
UNCOV
1271
        }
×
1272

UNCOV
1273
        var localNonce OptMusig2NonceTLV
×
UNCOV
1274
        if includeLocalNonce {
×
UNCOV
1275
                nonce := RandMusig2Nonce(t)
×
UNCOV
1276
                localNonce = tlv.SomeRecordT(
×
UNCOV
1277
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
UNCOV
1278
                )
×
UNCOV
1279
        }
×
1280

UNCOV
1281
        var channelType *ChannelType
×
UNCOV
1282
        if includeChannelType {
×
UNCOV
1283
                channelType = RandChannelType(t)
×
UNCOV
1284
        }
×
1285

UNCOV
1286
        var leaseExpiry *LeaseExpiry
×
UNCOV
1287
        if includeLeaseExpiry {
×
UNCOV
1288
                leaseExpiry = RandLeaseExpiry(t)
×
UNCOV
1289
        }
×
1290

UNCOV
1291
        return &OpenChannel{
×
UNCOV
1292
                ChainHash:        hash,
×
UNCOV
1293
                PendingChannelID: pendingChanID,
×
UNCOV
1294
                FundingAmount: btcutil.Amount(
×
UNCOV
1295
                        rapid.IntRange(5000, 10000000).Draw(t, "fundingAmount"),
×
UNCOV
1296
                ),
×
UNCOV
1297
                PushAmount: MilliSatoshi(
×
UNCOV
1298
                        rapid.IntRange(0, 1000000).Draw(t, "pushAmount"),
×
UNCOV
1299
                ),
×
UNCOV
1300
                DustLimit: btcutil.Amount(
×
UNCOV
1301
                        rapid.IntRange(100, 1000).Draw(t, "dustLimit"),
×
UNCOV
1302
                ),
×
UNCOV
1303
                MaxValueInFlight: MilliSatoshi(
×
UNCOV
1304
                        rapid.IntRange(10000, 1000000).Draw(
×
UNCOV
1305
                                t, "maxValueInFlight",
×
UNCOV
1306
                        ),
×
UNCOV
1307
                ),
×
UNCOV
1308
                ChannelReserve: btcutil.Amount(
×
UNCOV
1309
                        rapid.IntRange(1000, 10000).Draw(t, "channelReserve"),
×
UNCOV
1310
                ),
×
UNCOV
1311
                HtlcMinimum: MilliSatoshi(
×
UNCOV
1312
                        rapid.IntRange(1, 1000).Draw(t, "htlcMinimum"),
×
UNCOV
1313
                ),
×
UNCOV
1314
                FeePerKiloWeight: uint32(
×
UNCOV
1315
                        rapid.IntRange(250, 10000).Draw(t, "feePerKw"),
×
UNCOV
1316
                ),
×
UNCOV
1317
                CsvDelay: uint16(
×
UNCOV
1318
                        rapid.IntRange(144, 1000).Draw(t, "csvDelay"),
×
UNCOV
1319
                ),
×
UNCOV
1320
                MaxAcceptedHTLCs: uint16(
×
UNCOV
1321
                        rapid.IntRange(10, 500).Draw(t, "maxAcceptedHTLCs"),
×
UNCOV
1322
                ),
×
UNCOV
1323
                FundingKey:            RandPubKey(t),
×
UNCOV
1324
                RevocationPoint:       RandPubKey(t),
×
UNCOV
1325
                PaymentPoint:          RandPubKey(t),
×
UNCOV
1326
                DelayedPaymentPoint:   RandPubKey(t),
×
UNCOV
1327
                HtlcPoint:             RandPubKey(t),
×
UNCOV
1328
                FirstCommitmentPoint:  RandPubKey(t),
×
UNCOV
1329
                ChannelFlags:          channelFlags,
×
UNCOV
1330
                UpfrontShutdownScript: RandDeliveryAddress(t),
×
UNCOV
1331
                ChannelType:           channelType,
×
UNCOV
1332
                LeaseExpiry:           leaseExpiry,
×
UNCOV
1333
                LocalNonce:            localNonce,
×
UNCOV
1334
                ExtraData:             RandExtraOpaqueData(t, nil),
×
UNCOV
1335
        }
×
1336
}
1337

1338
// A compile time check to ensure Ping implements the lnwire.TestMessage
1339
// interface.
1340
var _ TestMessage = (*Ping)(nil)
1341

1342
// RandTestMessage populates the message with random data suitable for testing.
1343
// It uses the rapid testing framework to generate random values.
1344
//
1345
// This is part of the TestMessage interface.
UNCOV
1346
func (p *Ping) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1347
        numPongBytes := uint16(rapid.IntRange(0, int(MaxPongBytes)).Draw(
×
UNCOV
1348
                t, "numPongBytes"),
×
UNCOV
1349
        )
×
UNCOV
1350

×
UNCOV
1351
        // Generate padding bytes (but keeping within allowed message size)
×
UNCOV
1352
        // MaxMsgBody - 2 (for NumPongBytes) - 2 (for padding length)
×
UNCOV
1353
        maxPaddingLen := MaxMsgBody - 4
×
UNCOV
1354
        paddingLen := rapid.IntRange(0, maxPaddingLen).Draw(
×
UNCOV
1355
                t, "paddingLen",
×
UNCOV
1356
        )
×
UNCOV
1357
        padding := make(PingPayload, paddingLen)
×
UNCOV
1358

×
UNCOV
1359
        // Fill padding with random bytes
×
UNCOV
1360
        for i := 0; i < paddingLen; i++ {
×
UNCOV
1361
                padding[i] = byte(rapid.IntRange(0, 255).Draw(
×
UNCOV
1362
                        t, fmt.Sprintf("paddingByte%d", i)),
×
UNCOV
1363
                )
×
UNCOV
1364
        }
×
1365

UNCOV
1366
        return &Ping{
×
UNCOV
1367
                NumPongBytes: numPongBytes,
×
UNCOV
1368
                PaddingBytes: padding,
×
UNCOV
1369
        }
×
1370
}
1371

1372
// A compile time check to ensure Pong implements the lnwire.TestMessage
1373
// interface.
1374
var _ TestMessage = (*Pong)(nil)
1375

1376
// RandTestMessage populates the message with random data suitable for testing.
1377
// It uses the rapid testing framework to generate random values.
1378
//
1379
// This is part of the TestMessage interface.
UNCOV
1380
func (p *Pong) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1381
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
×
UNCOV
1382
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
×
UNCOV
1383
                t, "pongPayload",
×
UNCOV
1384
        )
×
UNCOV
1385

×
UNCOV
1386
        return &Pong{
×
UNCOV
1387
                PongBytes: payload,
×
UNCOV
1388
        }
×
UNCOV
1389
}
×
1390

1391
// A compile time check to ensure QueryChannelRange implements the
1392
// lnwire.TestMessage interface.
1393
var _ TestMessage = (*QueryChannelRange)(nil)
1394

1395
// RandTestMessage populates the message with random data suitable for testing.
1396
// It uses the rapid testing framework to generate random values.
1397
//
1398
// This is part of the TestMessage interface.
UNCOV
1399
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1400
        msg := &QueryChannelRange{
×
UNCOV
1401
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
UNCOV
1402
                        t, "firstBlockHeight"),
×
UNCOV
1403
                ),
×
UNCOV
1404
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
UNCOV
1405
                        t, "numBlocks"),
×
UNCOV
1406
                ),
×
UNCOV
1407
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1408
        }
×
UNCOV
1409

×
UNCOV
1410
        // Generate chain hash
×
UNCOV
1411
        chainHash := RandChainHash(t)
×
UNCOV
1412
        var chainHashObj chainhash.Hash
×
UNCOV
1413
        copy(chainHashObj[:], chainHash[:])
×
UNCOV
1414
        msg.ChainHash = chainHashObj
×
UNCOV
1415

×
UNCOV
1416
        // Randomly include QueryOptions
×
UNCOV
1417
        if rapid.Bool().Draw(t, "includeQueryOptions") {
×
UNCOV
1418
                queryOptions := &QueryOptions{}
×
UNCOV
1419
                *queryOptions = QueryOptions(*RandFeatureVector(t))
×
UNCOV
1420
                msg.QueryOptions = queryOptions
×
UNCOV
1421
        }
×
1422

UNCOV
1423
        return msg
×
1424
}
1425

1426
// A compile time check to ensure QueryShortChanIDs implements the
1427
// lnwire.TestMessage interface.
1428
var _ TestMessage = (*QueryShortChanIDs)(nil)
1429

1430
// RandTestMessage populates the message with random data suitable for testing.
1431
// It uses the rapid testing framework to generate random values.
1432
//
1433
// This is part of the TestMessage interface.
UNCOV
1434
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1435
        var chainHash chainhash.Hash
×
UNCOV
1436
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
1437
        copy(chainHash[:], hashBytes)
×
UNCOV
1438

×
UNCOV
1439
        encodingType := EncodingSortedPlain
×
UNCOV
1440
        if rapid.Bool().Draw(t, "useZlibEncoding") {
×
UNCOV
1441
                encodingType = EncodingSortedZlib
×
UNCOV
1442
        }
×
1443

UNCOV
1444
        msg := &QueryShortChanIDs{
×
UNCOV
1445
                ChainHash:    chainHash,
×
UNCOV
1446
                EncodingType: encodingType,
×
UNCOV
1447
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
1448
                noSort:       false,
×
UNCOV
1449
        }
×
UNCOV
1450

×
UNCOV
1451
        numIDs := rapid.IntRange(2, 20).Draw(t, "numShortChanIDs")
×
UNCOV
1452

×
UNCOV
1453
        // Generate sorted short channel IDs.
×
UNCOV
1454
        shortChanIDs := make([]ShortChannelID, numIDs)
×
UNCOV
1455
        for i := 0; i < numIDs; i++ {
×
UNCOV
1456
                shortChanIDs[i] = RandShortChannelID(t)
×
UNCOV
1457

×
UNCOV
1458
                // Ensure they're properly sorted.
×
UNCOV
1459
                if i > 0 && shortChanIDs[i].ToUint64() <=
×
UNCOV
1460
                        shortChanIDs[i-1].ToUint64() {
×
UNCOV
1461

×
UNCOV
1462
                        // Ensure this ID is larger than the previous one.
×
UNCOV
1463
                        shortChanIDs[i] = NewShortChanIDFromInt(
×
UNCOV
1464
                                shortChanIDs[i-1].ToUint64() + 1,
×
UNCOV
1465
                        )
×
UNCOV
1466
                }
×
1467
        }
1468

UNCOV
1469
        msg.ShortChanIDs = shortChanIDs
×
UNCOV
1470

×
UNCOV
1471
        return msg
×
1472
}
1473

1474
// A compile time check to ensure ReplyChannelRange implements the
1475
// lnwire.TestMessage interface.
1476
var _ TestMessage = (*ReplyChannelRange)(nil)
1477

1478
// RandTestMessage populates the message with random data suitable for testing.
1479
// It uses the rapid testing framework to generate random values.
1480
//
1481
// This is part of the TestMessage interface.
UNCOV
1482
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1483
        msg := &ReplyChannelRange{
×
UNCOV
1484
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
UNCOV
1485
                        t, "firstBlockHeight"),
×
UNCOV
1486
                ),
×
UNCOV
1487
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
UNCOV
1488
                        t, "numBlocks"),
×
UNCOV
1489
                ),
×
UNCOV
1490
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
×
UNCOV
1491
                EncodingType: QueryEncoding(
×
UNCOV
1492
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
×
UNCOV
1493
                ),
×
UNCOV
1494
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1495
        }
×
UNCOV
1496

×
UNCOV
1497
        msg.ChainHash = RandChainHash(t)
×
UNCOV
1498

×
UNCOV
1499
        numShortChanIDs := rapid.IntRange(0, 20).Draw(t, "numShortChanIDs")
×
UNCOV
1500
        if numShortChanIDs == 0 {
×
UNCOV
1501
                return msg
×
UNCOV
1502
        }
×
1503

UNCOV
1504
        scidSet := fn.NewSet[ShortChannelID]()
×
UNCOV
1505
        scids := make([]ShortChannelID, numShortChanIDs)
×
UNCOV
1506
        for i := 0; i < numShortChanIDs; i++ {
×
UNCOV
1507
                scid := RandShortChannelID(t)
×
UNCOV
1508
                for scidSet.Contains(scid) {
×
UNCOV
1509
                        scid = RandShortChannelID(t)
×
UNCOV
1510
                }
×
1511

UNCOV
1512
                scids[i] = scid
×
UNCOV
1513

×
UNCOV
1514
                scidSet.Add(scid)
×
1515
        }
1516

1517
        // Make sure there're no duplicates.
UNCOV
1518
        msg.ShortChanIDs = scids
×
UNCOV
1519

×
UNCOV
1520
        if rapid.Bool().Draw(t, "includeTimestamps") && numShortChanIDs > 0 {
×
UNCOV
1521
                msg.Timestamps = make(Timestamps, numShortChanIDs)
×
UNCOV
1522
                for i := 0; i < numShortChanIDs; i++ {
×
UNCOV
1523
                        msg.Timestamps[i] = ChanUpdateTimestamps{
×
UNCOV
1524
                                Timestamp1: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-1-%d", i))), //nolint:ll
×
UNCOV
1525
                                Timestamp2: uint32(rapid.IntRange(0, math.MaxInt32).Draw(t, fmt.Sprintf("timestamp-2-%d", i))), //nolint:ll
×
UNCOV
1526
                        }
×
UNCOV
1527
                }
×
1528
        }
1529

UNCOV
1530
        return msg
×
1531
}
1532

1533
// A compile time check to ensure ReplyShortChanIDsEnd implements the
1534
// lnwire.TestMessage interface.
1535
var _ TestMessage = (*ReplyShortChanIDsEnd)(nil)
1536

1537
// RandTestMessage populates the message with random data suitable for testing.
1538
// It uses the rapid testing framework to generate random values.
1539
//
1540
// This is part of the TestMessage interface.
UNCOV
1541
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1542
        var chainHash chainhash.Hash
×
UNCOV
1543
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
1544
        copy(chainHash[:], hashBytes)
×
UNCOV
1545

×
UNCOV
1546
        complete := uint8(rapid.IntRange(0, 1).Draw(t, "complete"))
×
UNCOV
1547

×
UNCOV
1548
        return &ReplyShortChanIDsEnd{
×
UNCOV
1549
                ChainHash: chainHash,
×
UNCOV
1550
                Complete:  complete,
×
UNCOV
1551
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1552
        }
×
UNCOV
1553
}
×
1554

1555
// RandTestMessage returns a RevokeAndAck message populated with random data.
1556
//
1557
// This is part of the TestMessage interface.
UNCOV
1558
func (c *RevokeAndAck) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1559
        msg := NewRevokeAndAck()
×
UNCOV
1560

×
UNCOV
1561
        var chanID ChannelID
×
UNCOV
1562
        bytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "channelID")
×
UNCOV
1563
        copy(chanID[:], bytes)
×
UNCOV
1564
        msg.ChanID = chanID
×
UNCOV
1565

×
UNCOV
1566
        revBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "revocation")
×
UNCOV
1567
        copy(msg.Revocation[:], revBytes)
×
UNCOV
1568

×
UNCOV
1569
        msg.NextRevocationKey = RandPubKey(t)
×
UNCOV
1570

×
UNCOV
1571
        if rapid.Bool().Draw(t, "includeLocalNonce") {
×
UNCOV
1572
                var nonce Musig2Nonce
×
UNCOV
1573
                nonceBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
1574
                        t, "nonce",
×
UNCOV
1575
                )
×
UNCOV
1576
                copy(nonce[:], nonceBytes)
×
UNCOV
1577

×
UNCOV
1578
                msg.LocalNonce = tlv.SomeRecordT(
×
UNCOV
1579
                        tlv.NewRecordT[NonceRecordTypeT, Musig2Nonce](nonce),
×
UNCOV
1580
                )
×
UNCOV
1581
        }
×
1582

UNCOV
1583
        return msg
×
1584
}
1585

1586
// A compile-time check to ensure Shutdown implements the lnwire.TestMessage
1587
// interface.
1588
var _ TestMessage = (*Shutdown)(nil)
1589

1590
// RandTestMessage populates the message with random data suitable for testing.
1591
// It uses the rapid testing framework to generate random values.
1592
//
1593
// This is part of the TestMessage interface.
UNCOV
1594
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1595
        // Generate random delivery address
×
UNCOV
1596
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
×
UNCOV
1597
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
×
UNCOV
1598

×
UNCOV
1599
        // Generate random address length based on type
×
UNCOV
1600
        var addrLen int
×
UNCOV
1601
        switch addrType {
×
1602
        // P2PKH
UNCOV
1603
        case 0:
×
UNCOV
1604
                addrLen = 25
×
1605
        // P2SH
UNCOV
1606
        case 1:
×
UNCOV
1607
                addrLen = 23
×
1608
        // P2WPKH
UNCOV
1609
        case 2:
×
UNCOV
1610
                addrLen = 22
×
1611
        // P2WSH
UNCOV
1612
        case 3:
×
UNCOV
1613
                addrLen = 34
×
1614
        // P2TR
UNCOV
1615
        case 4:
×
UNCOV
1616
                addrLen = 34
×
1617
        }
1618

UNCOV
1619
        addr := rapid.SliceOfN(rapid.Byte(), addrLen, addrLen).Draw(
×
UNCOV
1620
                t, "address",
×
UNCOV
1621
        )
×
UNCOV
1622

×
UNCOV
1623
        // Randomly decide whether to include a shutdown nonce
×
UNCOV
1624
        includeNonce := rapid.Bool().Draw(t, "includeNonce")
×
UNCOV
1625
        var shutdownNonce ShutdownNonceTLV
×
UNCOV
1626

×
UNCOV
1627
        if includeNonce {
×
UNCOV
1628
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
×
UNCOV
1629
        }
×
1630

UNCOV
1631
        cr, _ := RandCustomRecords(t, nil)
×
UNCOV
1632

×
UNCOV
1633
        return &Shutdown{
×
UNCOV
1634
                ChannelID:     RandChannelID(t),
×
UNCOV
1635
                Address:       addr,
×
UNCOV
1636
                ShutdownNonce: shutdownNonce,
×
UNCOV
1637
                CustomRecords: cr,
×
UNCOV
1638
        }
×
1639
}
1640

1641
// A compile time check to ensure Stfu implements the lnwire.TestMessage
1642
// interface.
1643
var _ TestMessage = (*Stfu)(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.
UNCOV
1649
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1650
        m := &Stfu{
×
UNCOV
1651
                ChanID:    RandChannelID(t),
×
UNCOV
1652
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
UNCOV
1653
        }
×
UNCOV
1654

×
UNCOV
1655
        extraData := RandExtraOpaqueData(t, nil)
×
UNCOV
1656
        if len(extraData) > 0 {
×
UNCOV
1657
                m.ExtraData = extraData
×
UNCOV
1658
        }
×
1659

UNCOV
1660
        return m
×
1661
}
1662

1663
// A compile time check to ensure UpdateAddHTLC implements the
1664
// lnwire.TestMessage interface.
1665
var _ TestMessage = (*UpdateAddHTLC)(nil)
1666

1667
// RandTestMessage returns an UpdateAddHTLC message populated with random data.
1668
//
1669
// This is part of the TestMessage interface.
UNCOV
1670
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1671
        msg := &UpdateAddHTLC{
×
UNCOV
1672
                ChanID: RandChannelID(t),
×
UNCOV
1673
                ID:     rapid.Uint64().Draw(t, "id"),
×
UNCOV
1674
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
×
UNCOV
1675
                Expiry: rapid.Uint32().Draw(t, "expiry"),
×
UNCOV
1676
        }
×
UNCOV
1677

×
UNCOV
1678
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "paymentHash")
×
UNCOV
1679
        copy(msg.PaymentHash[:], hashBytes)
×
UNCOV
1680

×
UNCOV
1681
        onionBytes := rapid.SliceOfN(
×
UNCOV
1682
                rapid.Byte(), OnionPacketSize, OnionPacketSize,
×
UNCOV
1683
        ).Draw(t, "onionBlob")
×
UNCOV
1684
        copy(msg.OnionBlob[:], onionBytes)
×
UNCOV
1685

×
UNCOV
1686
        numRecords := rapid.IntRange(0, 5).Draw(t, "numRecords")
×
UNCOV
1687
        if numRecords > 0 {
×
UNCOV
1688
                msg.CustomRecords, _ = RandCustomRecords(t, nil)
×
UNCOV
1689
        }
×
1690

1691
        // 50/50 chance to add a blinding point
UNCOV
1692
        if rapid.Bool().Draw(t, "includeBlindingPoint") {
×
UNCOV
1693
                pubKey := RandPubKey(t)
×
UNCOV
1694

×
UNCOV
1695
                msg.BlindingPoint = tlv.SomeRecordT(
×
UNCOV
1696
                        tlv.NewPrimitiveRecord[BlindingPointTlvType](pubKey),
×
UNCOV
1697
                )
×
UNCOV
1698
        }
×
1699

UNCOV
1700
        return msg
×
1701
}
1702

1703
// A compile time check to ensure UpdateFailHTLC implements the TestMessage
1704
// interface.
1705
var _ TestMessage = (*UpdateFailHTLC)(nil)
1706

1707
// RandTestMessage populates the message with random data suitable for testing.
1708
// It uses the rapid testing framework to generate random values.
1709
//
1710
// This is part of the TestMessage interface.
UNCOV
1711
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1712
        return &UpdateFailHTLC{
×
UNCOV
1713
                ChanID:    RandChannelID(t),
×
UNCOV
1714
                ID:        rapid.Uint64().Draw(t, "id"),
×
UNCOV
1715
                Reason:    RandOpaqueReason(t),
×
UNCOV
1716
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1717
        }
×
UNCOV
1718
}
×
1719

1720
// A compile time check to ensure UpdateFailMalformedHTLC implements the
1721
// TestMessage interface.
1722
var _ TestMessage = (*UpdateFailMalformedHTLC)(nil)
1723

1724
// RandTestMessage populates the message with random data suitable for testing.
1725
// It uses the rapid testing framework to generate random values.
1726
//
1727
// This is part of the TestMessage interface.
UNCOV
1728
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1729
        return &UpdateFailMalformedHTLC{
×
UNCOV
1730
                ChanID:       RandChannelID(t),
×
UNCOV
1731
                ID:           rapid.Uint64().Draw(t, "id"),
×
UNCOV
1732
                ShaOnionBlob: RandSHA256Hash(t),
×
UNCOV
1733
                FailureCode:  RandFailCode(t),
×
UNCOV
1734
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
1735
        }
×
UNCOV
1736
}
×
1737

1738
// A compile time check to ensure UpdateFee implements the TestMessage
1739
// interface.
1740
var _ TestMessage = (*UpdateFee)(nil)
1741

1742
// RandTestMessage populates the message with random data suitable for testing.
1743
// It uses the rapid testing framework to generate random values.
1744
//
1745
// This is part of the TestMessage interface.
UNCOV
1746
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1747
        return &UpdateFee{
×
UNCOV
1748
                ChanID:    RandChannelID(t),
×
UNCOV
1749
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
×
UNCOV
1750
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1751
        }
×
UNCOV
1752
}
×
1753

1754
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage
1755
// interface.
1756
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
1757

1758
// RandTestMessage populates the message with random data suitable for testing.
1759
// It uses the rapid testing framework to generate random values.
1760
//
1761
// This is part of the TestMessage interface.
UNCOV
1762
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1763
        msg := &UpdateFulfillHTLC{
×
UNCOV
1764
                ChanID:          RandChannelID(t),
×
UNCOV
1765
                ID:              rapid.Uint64().Draw(t, "id"),
×
UNCOV
1766
                PaymentPreimage: RandPaymentPreimage(t),
×
UNCOV
1767
        }
×
UNCOV
1768

×
UNCOV
1769
        cr, ignoreRecords := RandCustomRecords(t, nil)
×
UNCOV
1770
        msg.CustomRecords = cr
×
UNCOV
1771

×
UNCOV
1772
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
UNCOV
1773
        if len(randData) > 0 {
×
UNCOV
1774
                msg.ExtraData = randData
×
UNCOV
1775
        }
×
1776

UNCOV
1777
        return msg
×
1778
}
1779

1780
// A compile time check to ensure Warning implements the lnwire.TestMessage
1781
// interface.
1782
var _ TestMessage = (*Warning)(nil)
1783

1784
// RandTestMessage populates the message with random data suitable for testing.
1785
// It uses the rapid testing framework to generate random values.
1786
//
1787
// This is part of the TestMessage interface.
UNCOV
1788
func (c *Warning) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1789
        msg := &Warning{
×
UNCOV
1790
                ChanID: RandChannelID(t),
×
UNCOV
1791
        }
×
UNCOV
1792

×
UNCOV
1793
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
UNCOV
1794
        if useASCII {
×
UNCOV
1795
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
UNCOV
1796
                data := make([]byte, length)
×
UNCOV
1797
                for i := 0; i < length; i++ {
×
UNCOV
1798
                        data[i] = byte(
×
UNCOV
1799
                                rapid.IntRange(32, 126).Draw(
×
UNCOV
1800
                                        t, fmt.Sprintf("warningDataByte-%d", i),
×
UNCOV
1801
                                ),
×
UNCOV
1802
                        )
×
UNCOV
1803
                }
×
UNCOV
1804
                msg.Data = data
×
UNCOV
1805
        } else {
×
UNCOV
1806
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
UNCOV
1807
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
×
UNCOV
1808
                        t, "warningData",
×
UNCOV
1809
                )
×
UNCOV
1810
        }
×
1811

UNCOV
1812
        return msg
×
1813
}
1814

1815
// A compile time check to ensure Error implements the lnwire.TestMessage
1816
// interface.
1817
var _ TestMessage = (*Error)(nil)
1818

1819
// RandTestMessage populates the message with random data suitable for testing.
1820
// It uses the rapid testing framework to generate random values.
1821
//
1822
// This is part of the TestMessage interface.
UNCOV
1823
func (c *Error) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1824
        msg := &Error{
×
UNCOV
1825
                ChanID: RandChannelID(t),
×
UNCOV
1826
        }
×
UNCOV
1827

×
UNCOV
1828
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
UNCOV
1829
        if useASCII {
×
UNCOV
1830
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
UNCOV
1831
                data := make([]byte, length)
×
UNCOV
1832
                for i := 0; i < length; i++ {
×
UNCOV
1833
                        data[i] = byte(
×
UNCOV
1834
                                rapid.IntRange(32, 126).Draw(
×
UNCOV
1835
                                        t, fmt.Sprintf("errorDataByte-%d", i),
×
UNCOV
1836
                                ),
×
UNCOV
1837
                        )
×
UNCOV
1838
                }
×
UNCOV
1839
                msg.Data = data
×
UNCOV
1840
        } else {
×
UNCOV
1841
                // Generate random binary data
×
UNCOV
1842
                length := rapid.IntRange(1, 100).Draw(t, "errorDataLength")
×
UNCOV
1843
                msg.Data = rapid.SliceOfN(
×
UNCOV
1844
                        rapid.Byte(), length, length,
×
UNCOV
1845
                ).Draw(t, "errorData")
×
UNCOV
1846
        }
×
1847

UNCOV
1848
        return msg
×
1849
}
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