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

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 hits per line

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

0.0
/lnwire/test_message.go
1
package lnwire
2

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

9
        "github.com/btcsuite/btcd/btcec/v2"
10
        "github.com/btcsuite/btcd/btcutil"
11
        "github.com/btcsuite/btcd/chaincfg/chainhash"
12
        "github.com/lightningnetwork/lnd/fn/v2"
13
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
14
        "github.com/lightningnetwork/lnd/tlv"
15
        "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.
UNCOV
38
func (a *AcceptChannel) RandTestMessage(t *rapid.T) Message {
×
UNCOV
39
        var pendingChanID [32]byte
×
UNCOV
40
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
41
                t, "pendingChanID",
×
UNCOV
42
        )
×
UNCOV
43
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
44

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

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

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

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

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

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

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

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

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

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

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

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

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

×
UNCOV
239
        msg.Signature.ForceSchnorr()
×
UNCOV
240

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
UNCOV
405
        // If max HTLC flag is not set, we need to zero the value
×
UNCOV
406
        if !includeMaxHtlc {
×
UNCOV
407
                maxHtlc = 0
×
UNCOV
408
        }
×
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.
UNCOV
414
        var (
×
UNCOV
415
                customRecords, _ = RandCustomRecords(t, nil, false)
×
UNCOV
416
                inboundFee       tlv.OptionalRecordT[tlv.TlvType55555, Fee]
×
UNCOV
417
        )
×
UNCOV
418
        includeInboundFee := rapid.Bool().Draw(t, "includeInboundFee")
×
UNCOV
419
        if includeInboundFee {
×
UNCOV
420
                if customRecords == nil {
×
UNCOV
421
                        customRecords = make(CustomRecords)
×
UNCOV
422
                }
×
423

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

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

×
UNCOV
443
                customRecords[uint64(FeeRecordType)] = b.Bytes()
×
444
        }
445

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

×
UNCOV
449
        return &ChannelUpdate1{
×
UNCOV
450
                Signature:      RandSignature(t),
×
UNCOV
451
                ChainHash:      hash,
×
UNCOV
452
                ShortChannelID: RandShortChannelID(t),
×
UNCOV
453
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
454
                        t, "timestamp"),
×
UNCOV
455
                ),
×
UNCOV
456
                MessageFlags: msgFlags,
×
UNCOV
457
                ChannelFlags: chanFlags,
×
UNCOV
458
                TimeLockDelta: uint16(rapid.IntRange(0, 65535).Draw(
×
UNCOV
459
                        t, "timelockDelta"),
×
UNCOV
460
                ),
×
UNCOV
461
                HtlcMinimumMsat: MilliSatoshi(rapid.Uint64().Draw(
×
UNCOV
462
                        t, "htlcMinimum"),
×
UNCOV
463
                ),
×
UNCOV
464
                BaseFee: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
465
                        t, "baseFee"),
×
UNCOV
466
                ),
×
UNCOV
467
                FeeRate: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
468
                        t, "feeRate"),
×
UNCOV
469
                ),
×
UNCOV
470
                HtlcMaximumMsat: maxHtlc,
×
UNCOV
471
                InboundFee:      inboundFee,
×
UNCOV
472
                ExtraOpaqueData: extraBytes,
×
UNCOV
473
        }
×
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.
UNCOV
484
func (c *ChannelUpdate2) RandTestMessage(t *rapid.T) Message {
×
UNCOV
485
        shortChanID := RandShortChannelID(t)
×
UNCOV
486
        blockHeight := uint32(rapid.IntRange(0, 1000000).Draw(t, "blockHeight"))
×
UNCOV
487

×
UNCOV
488
        var disabledFlags ChanUpdateDisableFlags
×
UNCOV
489
        if rapid.Bool().Draw(t, "disableIncoming") {
×
UNCOV
490
                disabledFlags |= ChanUpdateDisableIncoming
×
UNCOV
491
        }
×
UNCOV
492
        if rapid.Bool().Draw(t, "disableOutgoing") {
×
UNCOV
493
                disabledFlags |= ChanUpdateDisableOutgoing
×
UNCOV
494
        }
×
495

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

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

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

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

×
UNCOV
548
        msg.Signature.ForceSchnorr()
×
UNCOV
549

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

UNCOV
556
        return msg
×
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.
UNCOV
567
func (c *ClosingComplete) RandTestMessage(t *rapid.T) Message {
×
UNCOV
568
        msg := &ClosingComplete{
×
UNCOV
569
                ChannelID: RandChannelID(t),
×
UNCOV
570
                FeeSatoshis: btcutil.Amount(rapid.Int64Range(0, 1000000).Draw(
×
UNCOV
571
                        t, "feeSatoshis"),
×
UNCOV
572
                ),
×
UNCOV
573
                LockTime: rapid.Uint32Range(0, 0xffffffff).Draw(
×
UNCOV
574
                        t, "lockTime",
×
UNCOV
575
                ),
×
UNCOV
576
                CloseeScript: RandDeliveryAddress(t),
×
UNCOV
577
                CloserScript: RandDeliveryAddress(t),
×
UNCOV
578
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
579
        }
×
UNCOV
580

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

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

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

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

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

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

UNCOV
622
        return msg
×
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.
UNCOV
633
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
634
        msg := &ClosingSig{
×
UNCOV
635
                ChannelID:    RandChannelID(t),
×
UNCOV
636
                CloseeScript: RandDeliveryAddress(t),
×
UNCOV
637
                CloserScript: RandDeliveryAddress(t),
×
UNCOV
638
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
639
        }
×
UNCOV
640

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

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

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

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

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

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

UNCOV
682
        return msg
×
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.
UNCOV
693
func (c *ClosingSigned) RandTestMessage(t *rapid.T) Message {
×
UNCOV
694
        // Generate a random boolean to decide whether to include CommitSig or
×
UNCOV
695
        // PartialSig Since they're mutually exclusive, when one is populated,
×
UNCOV
696
        // the other must be blank.
×
UNCOV
697
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
UNCOV
698

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

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

×
UNCOV
714
                msg.PartialSig = SomePartialSig(NewPartialSig(s))
×
UNCOV
715
                msg.Signature = Sig{}
×
UNCOV
716
        } else {
×
UNCOV
717
                msg.Signature = RandSignature(t)
×
UNCOV
718
        }
×
719

UNCOV
720
        return msg
×
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.
UNCOV
731
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
732
        cr, _ := RandCustomRecords(t, nil, true)
×
UNCOV
733
        sig := &CommitSig{
×
UNCOV
734
                ChanID:        RandChannelID(t),
×
UNCOV
735
                CommitSig:     RandSignature(t),
×
UNCOV
736
                CustomRecords: cr,
×
UNCOV
737
        }
×
UNCOV
738

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

UNCOV
745
        if len(htlcSigs) > 0 {
×
UNCOV
746
                sig.HtlcSigs = htlcSigs
×
UNCOV
747
        }
×
748

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

UNCOV
755
        return sig
×
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.
UNCOV
766
func (c *Custom) RandTestMessage(t *rapid.T) Message {
×
UNCOV
767
        msgType := MessageType(
×
UNCOV
768
                rapid.IntRange(int(CustomTypeStart), 65535).Draw(
×
UNCOV
769
                        t, "customMsgType",
×
UNCOV
770
                ),
×
UNCOV
771
        )
×
UNCOV
772

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

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

UNCOV
783
        return msg
×
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.
UNCOV
794
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
×
UNCOV
795
        msg := &DynAck{
×
UNCOV
796
                ChanID:    RandChannelID(t),
×
UNCOV
797
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
798
        }
×
UNCOV
799

×
UNCOV
800
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
UNCOV
801

×
UNCOV
802
        if includeLocalNonce {
×
UNCOV
803
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
×
UNCOV
804
        }
×
805

UNCOV
806
        return msg
×
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.
UNCOV
817
func (dp *DynPropose) RandTestMessage(t *rapid.T) Message {
×
UNCOV
818
        msg := &DynPropose{
×
UNCOV
819
                ChanID:    RandChannelID(t),
×
UNCOV
820
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
UNCOV
821
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
822
        }
×
UNCOV
823

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

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

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

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

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

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

UNCOV
864
        if includeFundingKey {
×
UNCOV
865
                msg.FundingKey = fn.Some(*RandPubKey(t))
×
UNCOV
866
        }
×
867

UNCOV
868
        if includeChannelType {
×
UNCOV
869
                msg.ChannelType = fn.Some(*RandChannelType(t))
×
UNCOV
870
        }
×
871

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

UNCOV
879
        return msg
×
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.
UNCOV
890
func (dr *DynReject) RandTestMessage(t *rapid.T) Message {
×
UNCOV
891
        featureVec := NewRawFeatureVector()
×
UNCOV
892

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

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

UNCOV
909
        return &DynReject{
×
UNCOV
910
                ChanID:           RandChannelID(t),
×
UNCOV
911
                UpdateRejections: *featureVec,
×
UNCOV
912
                ExtraData:        extraData,
×
UNCOV
913
        }
×
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.
UNCOV
924
func (f *FundingCreated) RandTestMessage(t *rapid.T) Message {
×
UNCOV
925
        var pendingChanID [32]byte
×
UNCOV
926
        pendingChanIDBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(
×
UNCOV
927
                t, "pendingChanID",
×
UNCOV
928
        )
×
UNCOV
929
        copy(pendingChanID[:], pendingChanIDBytes)
×
UNCOV
930

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

×
UNCOV
935
        if includePartialSig {
×
UNCOV
936
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
937
                partialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
938

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

UNCOV
945
        return &FundingCreated{
×
UNCOV
946
                PendingChannelID: pendingChanID,
×
UNCOV
947
                FundingPoint:     RandOutPoint(t),
×
UNCOV
948
                CommitSig:        commitSig,
×
UNCOV
949
                PartialSig:       partialSig,
×
UNCOV
950
                ExtraData:        RandExtraOpaqueData(t, nil),
×
UNCOV
951
        }
×
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.
UNCOV
962
func (f *FundingSigned) RandTestMessage(t *rapid.T) Message {
×
UNCOV
963
        usePartialSig := rapid.Bool().Draw(t, "usePartialSig")
×
UNCOV
964

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

×
UNCOV
970
        if usePartialSig {
×
UNCOV
971
                sigWithNonce := RandPartialSigWithNonce(t)
×
UNCOV
972
                msg.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
UNCOV
973

×
UNCOV
974
                msg.CommitSig = Sig{}
×
UNCOV
975
        } else {
×
UNCOV
976
                msg.CommitSig = RandSignature(t)
×
UNCOV
977
        }
×
978

UNCOV
979
        return msg
×
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.
UNCOV
990
func (g *GossipTimestampRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
991
        var chainHash chainhash.Hash
×
UNCOV
992
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
993
        copy(chainHash[:], hashBytes)
×
UNCOV
994

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

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

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

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

UNCOV
1021
        return msg
×
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.
UNCOV
1028
func (msg *Init) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1029
        global := NewRawFeatureVector()
×
UNCOV
1030
        local := NewRawFeatureVector()
×
UNCOV
1031

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

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

UNCOV
1052
        return NewInitMessage(global, local)
×
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.
UNCOV
1063
func (ks *KickoffSig) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1064
        return &KickoffSig{
×
UNCOV
1065
                ChanID:    RandChannelID(t),
×
UNCOV
1066
                Signature: RandSignature(t),
×
UNCOV
1067
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1068
        }
×
UNCOV
1069
}
×
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.
UNCOV
1079
func (a *NodeAnnouncement) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1080
        // Generate random compressed public key for node ID
×
UNCOV
1081
        pubKey := RandPubKey(t)
×
UNCOV
1082
        var nodeID [33]byte
×
UNCOV
1083
        copy(nodeID[:], pubKey.SerializeCompressed())
×
UNCOV
1084

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

×
UNCOV
1092
        return &NodeAnnouncement{
×
UNCOV
1093
                Signature: RandSignature(t),
×
UNCOV
1094
                Features:  RandFeatureVector(t),
×
UNCOV
1095
                Timestamp: uint32(rapid.IntRange(0, 0x7FFFFFFF).Draw(
×
UNCOV
1096
                        t, "timestamp"),
×
UNCOV
1097
                ),
×
UNCOV
1098
                NodeID:          nodeID,
×
UNCOV
1099
                RGBColor:        rgbColor,
×
UNCOV
1100
                Alias:           RandNodeAlias(t),
×
UNCOV
1101
                Addresses:       RandNetAddrs(t),
×
UNCOV
1102
                ExtraOpaqueData: RandExtraOpaqueData(t, nil),
×
UNCOV
1103
        }
×
UNCOV
1104
}
×
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.
UNCOV
1114
func (o *OpenChannel) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1115
        chainHash := RandChainHash(t)
×
UNCOV
1116
        var hash chainhash.Hash
×
UNCOV
1117
        copy(hash[:], chainHash[:])
×
UNCOV
1118

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

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

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

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

UNCOV
1142
        var channelType *ChannelType
×
UNCOV
1143
        if includeChannelType {
×
UNCOV
1144
                channelType = RandChannelType(t)
×
UNCOV
1145
        }
×
1146

UNCOV
1147
        var leaseExpiry *LeaseExpiry
×
UNCOV
1148
        if includeLeaseExpiry {
×
UNCOV
1149
                leaseExpiry = RandLeaseExpiry(t)
×
UNCOV
1150
        }
×
1151

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

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

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

UNCOV
1227
        return &Ping{
×
UNCOV
1228
                NumPongBytes: numPongBytes,
×
UNCOV
1229
                PaddingBytes: padding,
×
UNCOV
1230
        }
×
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.
UNCOV
1241
func (p *Pong) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1242
        payloadLen := rapid.IntRange(0, 1000).Draw(t, "pongPayloadLength")
×
UNCOV
1243
        payload := rapid.SliceOfN(rapid.Byte(), payloadLen, payloadLen).Draw(
×
UNCOV
1244
                t, "pongPayload",
×
UNCOV
1245
        )
×
UNCOV
1246

×
UNCOV
1247
        return &Pong{
×
UNCOV
1248
                PongBytes: payload,
×
UNCOV
1249
        }
×
UNCOV
1250
}
×
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.
UNCOV
1260
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1261
        msg := &QueryChannelRange{
×
UNCOV
1262
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
UNCOV
1263
                        t, "firstBlockHeight"),
×
UNCOV
1264
                ),
×
UNCOV
1265
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
UNCOV
1266
                        t, "numBlocks"),
×
UNCOV
1267
                ),
×
UNCOV
1268
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1269
        }
×
UNCOV
1270

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

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

UNCOV
1284
        return msg
×
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.
UNCOV
1295
func (q *QueryShortChanIDs) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1296
        var chainHash chainhash.Hash
×
UNCOV
1297
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
1298
        copy(chainHash[:], hashBytes)
×
UNCOV
1299

×
UNCOV
1300
        encodingType := EncodingSortedPlain
×
UNCOV
1301
        if rapid.Bool().Draw(t, "useZlibEncoding") {
×
UNCOV
1302
                encodingType = EncodingSortedZlib
×
UNCOV
1303
        }
×
1304

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

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

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

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

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

UNCOV
1330
        msg.ShortChanIDs = shortChanIDs
×
UNCOV
1331

×
UNCOV
1332
        return msg
×
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.
UNCOV
1343
func (c *ReplyChannelRange) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1344
        msg := &ReplyChannelRange{
×
UNCOV
1345
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
UNCOV
1346
                        t, "firstBlockHeight"),
×
UNCOV
1347
                ),
×
UNCOV
1348
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
UNCOV
1349
                        t, "numBlocks"),
×
UNCOV
1350
                ),
×
UNCOV
1351
                Complete: uint8(rapid.IntRange(0, 1).Draw(t, "complete")),
×
UNCOV
1352
                EncodingType: QueryEncoding(
×
UNCOV
1353
                        rapid.IntRange(0, 1).Draw(t, "encodingType"),
×
UNCOV
1354
                ),
×
UNCOV
1355
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1356
        }
×
UNCOV
1357

×
UNCOV
1358
        msg.ChainHash = RandChainHash(t)
×
UNCOV
1359

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

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

UNCOV
1373
                scids[i] = scid
×
UNCOV
1374

×
UNCOV
1375
                scidSet.Add(scid)
×
1376
        }
1377

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

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

UNCOV
1391
        return msg
×
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.
UNCOV
1402
func (c *ReplyShortChanIDsEnd) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1403
        var chainHash chainhash.Hash
×
UNCOV
1404
        hashBytes := rapid.SliceOfN(rapid.Byte(), 32, 32).Draw(t, "chainHash")
×
UNCOV
1405
        copy(chainHash[:], hashBytes)
×
UNCOV
1406

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

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

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

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

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

×
UNCOV
1430
        msg.NextRevocationKey = RandPubKey(t)
×
UNCOV
1431

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

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

UNCOV
1444
        return msg
×
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.
UNCOV
1455
func (s *Shutdown) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1456
        // Generate random delivery address
×
UNCOV
1457
        // First decide the address type (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
×
UNCOV
1458
        addrType := rapid.IntRange(0, 4).Draw(t, "addrType")
×
UNCOV
1459

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

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

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

×
UNCOV
1488
        if includeNonce {
×
UNCOV
1489
                shutdownNonce = SomeShutdownNonce(RandMusig2Nonce(t))
×
UNCOV
1490
        }
×
1491

UNCOV
1492
        cr, _ := RandCustomRecords(t, nil, true)
×
UNCOV
1493

×
UNCOV
1494
        return &Shutdown{
×
UNCOV
1495
                ChannelID:     RandChannelID(t),
×
UNCOV
1496
                Address:       addr,
×
UNCOV
1497
                ShutdownNonce: shutdownNonce,
×
UNCOV
1498
                CustomRecords: cr,
×
UNCOV
1499
        }
×
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.
UNCOV
1510
func (s *Stfu) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1511
        m := &Stfu{
×
UNCOV
1512
                ChanID:    RandChannelID(t),
×
UNCOV
1513
                Initiator: rapid.Bool().Draw(t, "initiator"),
×
UNCOV
1514
        }
×
UNCOV
1515

×
UNCOV
1516
        extraData := RandExtraOpaqueData(t, nil)
×
UNCOV
1517
        if len(extraData) > 0 {
×
UNCOV
1518
                m.ExtraData = extraData
×
UNCOV
1519
        }
×
1520

UNCOV
1521
        return m
×
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.
UNCOV
1531
func (c *UpdateAddHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1532
        msg := &UpdateAddHTLC{
×
UNCOV
1533
                ChanID: RandChannelID(t),
×
UNCOV
1534
                ID:     rapid.Uint64().Draw(t, "id"),
×
UNCOV
1535
                Amount: MilliSatoshi(rapid.Uint64().Draw(t, "amount")),
×
UNCOV
1536
                Expiry: rapid.Uint32().Draw(t, "expiry"),
×
UNCOV
1537
        }
×
UNCOV
1538

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

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

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

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

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

UNCOV
1561
        return msg
×
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.
UNCOV
1572
func (c *UpdateFailHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1573
        return &UpdateFailHTLC{
×
UNCOV
1574
                ChanID:    RandChannelID(t),
×
UNCOV
1575
                ID:        rapid.Uint64().Draw(t, "id"),
×
UNCOV
1576
                Reason:    RandOpaqueReason(t),
×
UNCOV
1577
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1578
        }
×
UNCOV
1579
}
×
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.
UNCOV
1589
func (c *UpdateFailMalformedHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1590
        return &UpdateFailMalformedHTLC{
×
UNCOV
1591
                ChanID:       RandChannelID(t),
×
UNCOV
1592
                ID:           rapid.Uint64().Draw(t, "id"),
×
UNCOV
1593
                ShaOnionBlob: RandSHA256Hash(t),
×
UNCOV
1594
                FailureCode:  RandFailCode(t),
×
UNCOV
1595
                ExtraData:    RandExtraOpaqueData(t, nil),
×
UNCOV
1596
        }
×
UNCOV
1597
}
×
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.
UNCOV
1607
func (c *UpdateFee) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1608
        return &UpdateFee{
×
UNCOV
1609
                ChanID:    RandChannelID(t),
×
UNCOV
1610
                FeePerKw:  uint32(rapid.IntRange(1, 10000).Draw(t, "feePerKw")),
×
UNCOV
1611
                ExtraData: RandExtraOpaqueData(t, nil),
×
UNCOV
1612
        }
×
UNCOV
1613
}
×
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.
UNCOV
1623
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1624
        msg := &UpdateFulfillHTLC{
×
UNCOV
1625
                ChanID:          RandChannelID(t),
×
UNCOV
1626
                ID:              rapid.Uint64().Draw(t, "id"),
×
UNCOV
1627
                PaymentPreimage: RandPaymentPreimage(t),
×
UNCOV
1628
        }
×
UNCOV
1629

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

×
UNCOV
1633
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
UNCOV
1634
        if len(randData) > 0 {
×
UNCOV
1635
                msg.ExtraData = randData
×
UNCOV
1636
        }
×
1637

UNCOV
1638
        return msg
×
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.
UNCOV
1649
func (c *Warning) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1650
        msg := &Warning{
×
UNCOV
1651
                ChanID: RandChannelID(t),
×
UNCOV
1652
        }
×
UNCOV
1653

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

UNCOV
1673
        return msg
×
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.
UNCOV
1684
func (c *Error) RandTestMessage(t *rapid.T) Message {
×
UNCOV
1685
        msg := &Error{
×
UNCOV
1686
                ChanID: RandChannelID(t),
×
UNCOV
1687
        }
×
UNCOV
1688

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

UNCOV
1709
        return msg
×
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