Skip to content

Commit 9bf48a7

Browse files
committed
Merge branch '0-18-4-branch-rc1-9082' into 0-18-4-branch-rc1
2 parents af08c42 + a4414fb commit 9bf48a7

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

lnwire/fuzz_test.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,47 @@ func FuzzReplyChannelRange(f *testing.F) {
494494
// Prefix with MsgReplyChannelRange.
495495
data = prefixWithMsgType(data, MsgReplyChannelRange)
496496

497-
// Pass the message into our general fuzz harness for wire
498-
// messages!
499-
harness(t, data)
497+
// Because require.Equal considers nil slices and empty slices
498+
// to be non-equal, we must manually compare the Timestamps
499+
// field rather than using the harness.
500+
501+
if len(data) > MaxSliceLength {
502+
return
503+
}
504+
505+
r := bytes.NewReader(data)
506+
msg, err := ReadMessage(r, 0)
507+
if err != nil {
508+
return
509+
}
510+
511+
// We will serialize the message into a new bytes buffer.
512+
var b bytes.Buffer
513+
_, err = WriteMessage(&b, msg, 0)
514+
require.NoError(t, err)
515+
516+
// Deserialize the message from the serialized bytes buffer, and
517+
// then assert that the original message is equal to the newly
518+
// deserialized message.
519+
newMsg, err := ReadMessage(&b, 0)
520+
require.NoError(t, err)
521+
522+
require.IsType(t, &ReplyChannelRange{}, msg)
523+
first, _ := msg.(*ReplyChannelRange)
524+
require.IsType(t, &ReplyChannelRange{}, newMsg)
525+
second, _ := newMsg.(*ReplyChannelRange)
526+
527+
// We can't use require.Equal for Timestamps, since we consider
528+
// the empty slice and nil to be equivalent.
529+
require.Equal(t, len(first.Timestamps), len(second.Timestamps))
530+
for i, ts1 := range first.Timestamps {
531+
ts2 := second.Timestamps[i]
532+
require.Equal(t, ts1, ts2)
533+
}
534+
first.Timestamps = nil
535+
second.Timestamps = nil
536+
537+
require.Equal(t, first, second)
500538
})
501539
}
502540

0 commit comments

Comments
 (0)