mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-27 01:02:56 +02:00
lnwire: add fuzz targets for gossip 1.75 messages
Add simple decode/encode targets for AnnouncementSignatures2, ChannelAnnouncement2, and ChannelUpdate2.
This commit is contained in:
parent
5a8026aba9
commit
2784da13f8
@ -114,6 +114,17 @@ func FuzzAnnounceSignatures(f *testing.F) {
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzAnnounceSignatures2(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
// Prefix with MsgAnnounceSignatures2.
|
||||
data = prefixWithMsgType(data, MsgAnnounceSignatures2)
|
||||
|
||||
// Pass the message into our general fuzz harness for wire
|
||||
// messages!
|
||||
harness(t, data)
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzChannelAnnouncement(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
// Prefix with MsgChannelAnnouncement.
|
||||
@ -125,6 +136,51 @@ func FuzzChannelAnnouncement(f *testing.F) {
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzChannelAnnouncement2(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
// Prefix with MsgChannelAnnouncement2.
|
||||
data = prefixWithMsgType(data, MsgChannelAnnouncement2)
|
||||
|
||||
// Because require.Equal considers nil maps and empty maps
|
||||
// to be non-equal, we must manually compare Features field
|
||||
// rather than using the harness.
|
||||
|
||||
if len(data) > MaxSliceLength {
|
||||
return
|
||||
}
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
msg, err := ReadMessage(r, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// We will serialize the message into a new bytes buffer.
|
||||
var b bytes.Buffer
|
||||
_, err = WriteMessage(&b, msg, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Deserialize the message from the serialized bytes buffer, and
|
||||
// then assert that the original message is equal to the newly
|
||||
// deserialized message.
|
||||
newMsg, err := ReadMessage(&b, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.IsType(t, &ChannelAnnouncement2{}, msg)
|
||||
first, _ := msg.(*ChannelAnnouncement2)
|
||||
require.IsType(t, &ChannelAnnouncement2{}, newMsg)
|
||||
second, _ := newMsg.(*ChannelAnnouncement2)
|
||||
|
||||
// We can't use require.Equal for Features, since we consider
|
||||
// the empty map and nil to be equivalent.
|
||||
require.True(t, first.Features.Val.Equals(&second.Features.Val))
|
||||
first.Features.Val = *NewRawFeatureVector()
|
||||
second.Features.Val = *NewRawFeatureVector()
|
||||
|
||||
require.Equal(t, first, second)
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzChannelReestablish(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
// Prefix with MsgChannelReestablish.
|
||||
@ -147,6 +203,17 @@ func FuzzChannelUpdate(f *testing.F) {
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzChannelUpdate2(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
// Prefix with MsgChannelUpdate2.
|
||||
data = prefixWithMsgType(data, MsgChannelUpdate2)
|
||||
|
||||
// Pass the message into our general fuzz harness for wire
|
||||
// messages!
|
||||
harness(t, data)
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzClosingSigned(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
// Prefix with MsgClosingSigned.
|
||||
|
Loading…
x
Reference in New Issue
Block a user