@@ -389,6 +389,45 @@ func TestEmptyMessageUnknownType(t *testing.T) {
389389 }
390390}
391391
392+ // randCustomRecords generates a random set of custom records for testing.
393+ func randCustomRecords (t * testing.T , r * rand.Rand ) CustomRecords {
394+ var (
395+ customRecords = CustomRecords {}
396+
397+ // We'll generate a random number of records,
398+ // between 0 and 10.
399+ numRecords = r .Intn (10 )
400+ )
401+
402+ // For each record, we'll generate a random key and
403+ // value.
404+ for i := 0 ; i < numRecords ; i ++ {
405+ // Keys must be equal to or greater than
406+ // MinCustomRecordsTlvType.
407+ keyOffset := uint64 (r .Intn (100 ))
408+ key := MinCustomRecordsTlvType + keyOffset
409+
410+ // Values are byte slices of any length.
411+ value := make ([]byte , r .Intn (100 ))
412+ _ , err := r .Read (value )
413+ require .NoError (t , err )
414+
415+ customRecords [key ] = value
416+ }
417+
418+ // Validate the custom records as a sanity check.
419+ err := customRecords .Validate ()
420+ require .NoError (t , err )
421+
422+ // If by chance we end up with an empty set of custom records, we'll
423+ // set it to nil to simplify test comparisons.
424+ if len (customRecords ) == 0 {
425+ customRecords = nil
426+ }
427+
428+ return customRecords
429+ }
430+
392431// TestLightningWireProtocol uses the testing/quick package to create a series
393432// of fuzz tests to attempt to break a primary scenario which is implemented as
394433// property based testing scenario.
@@ -1353,6 +1392,8 @@ func TestLightningWireProtocol(t *testing.T) {
13531392 _ , err = r .Read (req .OnionBlob [:])
13541393 require .NoError (t , err )
13551394
1395+ req .CustomRecords = randCustomRecords (t , r )
1396+
13561397 // Generate a blinding point 50% of the time, since not
13571398 // all update adds will use route blinding.
13581399 if r .Int31 ()% 2 == 0 {
0 commit comments