nim-eth/tests/fuzzing/discoveryv5/fuzz_decode_message.nim

30 lines
1.1 KiB
Nim
Raw Normal View History

2020-07-14 20:56:34 +00:00
import
testutils/fuzzing,
../../../eth/p2p/discoveryv5/messages_encoding
2020-07-14 20:56:34 +00:00
test:
block testBlock:
2020-07-14 20:56:34 +00:00
let decoded = decodeMessage(payload)
if decoded.isOk():
2020-07-14 20:56:34 +00:00
let message = decoded.get()
var encoded: seq[byte]
case message.kind
of unused: break testBlock
2020-07-14 20:56:34 +00:00
of ping: encoded = encodeMessage(message.ping, message.reqId)
of pong: encoded = encodeMessage(message.pong, message.reqId)
of findNode: encoded = encodeMessage(message.findNode, message.reqId)
2020-07-14 20:56:34 +00:00
of nodes: encoded = encodeMessage(message.nodes, message.reqId)
of talkReq: encoded = encodeMessage(message.talkReq, message.reqId)
of talkResp: encoded = encodeMessage(message.talkResp, message.reqId)
of regTopic, ticket, regConfirmation, topicQuery:
break testBlock
2020-07-14 20:56:34 +00:00
# This will hit assert because of issue:
# https://github.com/status-im/nim-eth/issues/255
# if encoded != payload:
# echo "payload: ", toHex(payload)
# echo "encoded: ", toHex(encoded)
# doAssert(false, "re-encoded result does not equal original payload")