lnwire: s/harness/wireMsgHarness

This slightly more descriptive name distinguishes the wire message
harness from the onion failure harness while also obviating the
repetitive comments at every call site.
This commit is contained in:
Matt Morehouse committed 2024-11-13 10:25:16 -06:00
1 parent 4097527efc
commit b7a1a1e9b8
1 file changed
+41 -152
+41 -152
View File
@@ -20,11 +20,11 @@ func prefixWithMsgType(data []byte, prefix MessageType) []byte {
return data return data
} }
// harness performs the actual fuzz testing of the appropriate wire message. // wireMsgHarness performs the actual fuzz testing of the appropriate wire
// This function will check that the passed-in message passes wire length // message. This function will check that the passed-in message passes wire
// checks, is a valid message once deserialized, and passes a sequence of // length checks, is a valid message once deserialized, and passes a sequence of
// serialization and deserialization checks. // serialization and deserialization checks.
func harness(t *testing.T, data []byte) { func wireMsgHarness(t *testing.T, data []byte) {
t.Helper() t.Helper()
// Create a reader with the byte array. // Create a reader with the byte array.
@@ -106,30 +106,21 @@ func FuzzAcceptChannel(f *testing.F) {
func FuzzAnnounceSignatures(f *testing.F) { func FuzzAnnounceSignatures(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgAnnounceSignatures) data = prefixWithMsgType(data, MsgAnnounceSignatures)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzAnnounceSignatures2(f *testing.F) { func FuzzAnnounceSignatures2(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgAnnounceSignatures2) data = prefixWithMsgType(data, MsgAnnounceSignatures2)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzChannelAnnouncement(f *testing.F) { func FuzzChannelAnnouncement(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgChannelAnnouncement) data = prefixWithMsgType(data, MsgChannelAnnouncement)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
@@ -180,130 +171,91 @@ func FuzzChannelAnnouncement2(f *testing.F) {
func FuzzChannelReestablish(f *testing.F) { func FuzzChannelReestablish(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgChannelReestablish) data = prefixWithMsgType(data, MsgChannelReestablish)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzChannelUpdate(f *testing.F) { func FuzzChannelUpdate(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgChannelUpdate) data = prefixWithMsgType(data, MsgChannelUpdate)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzChannelUpdate2(f *testing.F) { func FuzzChannelUpdate2(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgChannelUpdate2) data = prefixWithMsgType(data, MsgChannelUpdate2)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzClosingSigned(f *testing.F) { func FuzzClosingSigned(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgClosingSigned) data = prefixWithMsgType(data, MsgClosingSigned)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzCommitSig(f *testing.F) { func FuzzCommitSig(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgCommitSig) data = prefixWithMsgType(data, MsgCommitSig)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzError(f *testing.F) { func FuzzError(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgError) data = prefixWithMsgType(data, MsgError)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzWarning(f *testing.F) { func FuzzWarning(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgWarning) data = prefixWithMsgType(data, MsgWarning)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzStfu(f *testing.F) { func FuzzStfu(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgStfu) data = prefixWithMsgType(data, MsgStfu)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages.
harness(t, data)
}) })
} }
func FuzzFundingCreated(f *testing.F) { func FuzzFundingCreated(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgFundingCreated) data = prefixWithMsgType(data, MsgFundingCreated)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzChannelReady(f *testing.F) { func FuzzChannelReady(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgChannelReady) data = prefixWithMsgType(data, MsgChannelReady)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzFundingSigned(f *testing.F) { func FuzzFundingSigned(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgFundingSigned) data = prefixWithMsgType(data, MsgFundingSigned)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzGossipTimestampRange(f *testing.F) { func FuzzGossipTimestampRange(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgGossipTimestampRange) data = prefixWithMsgType(data, MsgGossipTimestampRange)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzInit(f *testing.F) { func FuzzInit(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgInit) data = prefixWithMsgType(data, MsgInit)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
@@ -422,30 +374,21 @@ func FuzzOpenChannel(f *testing.F) {
func FuzzPing(f *testing.F) { func FuzzPing(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgPing) data = prefixWithMsgType(data, MsgPing)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzPong(f *testing.F) { func FuzzPong(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgPong) data = prefixWithMsgType(data, MsgPong)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzQueryChannelRange(f *testing.F) { func FuzzQueryChannelRange(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgQueryChannelRange) data = prefixWithMsgType(data, MsgQueryChannelRange)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
@@ -474,20 +417,14 @@ func FuzzZlibQueryShortChanIDs(f *testing.F) {
payload = append(payload, compressedPayload...) payload = append(payload, compressedPayload...)
payload = prefixWithMsgType(payload, MsgQueryShortChanIDs) payload = prefixWithMsgType(payload, MsgQueryShortChanIDs)
wireMsgHarness(t, payload)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, payload)
}) })
} }
func FuzzQueryShortChanIDs(f *testing.F) { func FuzzQueryShortChanIDs(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgQueryShortChanIDs) data = prefixWithMsgType(data, MsgQueryShortChanIDs)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
@@ -524,10 +461,7 @@ func FuzzZlibReplyChannelRange(f *testing.F) {
payload = append(payload, compressedPayload...) payload = append(payload, compressedPayload...)
payload = prefixWithMsgType(payload, MsgReplyChannelRange) payload = prefixWithMsgType(payload, MsgReplyChannelRange)
wireMsgHarness(t, payload)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, payload)
}) })
} }
@@ -582,120 +516,84 @@ func FuzzReplyChannelRange(f *testing.F) {
func FuzzReplyShortChanIDsEnd(f *testing.F) { func FuzzReplyShortChanIDsEnd(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgReplyShortChanIDsEnd) data = prefixWithMsgType(data, MsgReplyShortChanIDsEnd)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzRevokeAndAck(f *testing.F) { func FuzzRevokeAndAck(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgRevokeAndAck) data = prefixWithMsgType(data, MsgRevokeAndAck)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzShutdown(f *testing.F) { func FuzzShutdown(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgShutdown) data = prefixWithMsgType(data, MsgShutdown)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzUpdateAddHTLC(f *testing.F) { func FuzzUpdateAddHTLC(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgUpdateAddHTLC) data = prefixWithMsgType(data, MsgUpdateAddHTLC)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzUpdateFailHTLC(f *testing.F) { func FuzzUpdateFailHTLC(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgUpdateFailHTLC) data = prefixWithMsgType(data, MsgUpdateFailHTLC)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzUpdateFailMalformedHTLC(f *testing.F) { func FuzzUpdateFailMalformedHTLC(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgUpdateFailMalformedHTLC) data = prefixWithMsgType(data, MsgUpdateFailMalformedHTLC)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzUpdateFee(f *testing.F) { func FuzzUpdateFee(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgUpdateFee) data = prefixWithMsgType(data, MsgUpdateFee)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzUpdateFulfillHTLC(f *testing.F) { func FuzzUpdateFulfillHTLC(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgUpdateFulfillHTLC) data = prefixWithMsgType(data, MsgUpdateFulfillHTLC)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzDynPropose(f *testing.F) { func FuzzDynPropose(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgDynPropose) data = prefixWithMsgType(data, MsgDynPropose)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzDynReject(f *testing.F) { func FuzzDynReject(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgDynReject) data = prefixWithMsgType(data, MsgDynReject)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzDynAck(f *testing.F) { func FuzzDynAck(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgDynAck) data = prefixWithMsgType(data, MsgDynAck)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzKickoffSig(f *testing.F) { func FuzzKickoffSig(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgKickoffSig) data = prefixWithMsgType(data, MsgKickoffSig)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
@@ -706,10 +604,7 @@ func FuzzCustomMessage(f *testing.F) {
} }
data = prefixWithMsgType(data, MessageType(customMessageType)) data = prefixWithMsgType(data, MessageType(customMessageType))
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
@@ -996,20 +891,14 @@ func FuzzFailInvalidBlinding(f *testing.F) {
func FuzzClosingSig(f *testing.F) { func FuzzClosingSig(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgClosingSig) data = prefixWithMsgType(data, MsgClosingSig)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }
func FuzzClosingComplete(f *testing.F) { func FuzzClosingComplete(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
data = prefixWithMsgType(data, MsgClosingComplete) data = prefixWithMsgType(data, MsgClosingComplete)
wireMsgHarness(t, data)
// Pass the message into our general fuzz harness for wire
// messages!
harness(t, data)
}) })
} }