mirror of https://github.com/status-im/nim-eth.git
Add the rlpx fuzzing thunk test
This commit is contained in:
parent
02a6906c01
commit
72d6c46950
|
@ -0,0 +1,35 @@
|
|||
import
|
||||
chronos, eth/p2p, eth/p2p/rlpx, eth/p2p/private/p2p_types,
|
||||
eth/p2p/rlpx_protocols/[whisper_protocol, eth_protocol],
|
||||
../fuzztest, ../p2p/p2p_test_helper
|
||||
|
||||
proc recvMsgMock(msg: openArray[byte]): tuple[msgId: int, msgData: Rlp] =
|
||||
var rlp = rlpFromBytes(@msg.toRange)
|
||||
|
||||
let msgid = rlp.read(int)
|
||||
return (msgId, rlp)
|
||||
|
||||
var
|
||||
node1: EthereumNode
|
||||
node2: EthereumNode
|
||||
peer: Peer
|
||||
|
||||
# This is not a good example of a fuzzing test and it would be much better
|
||||
# to mock more to get rid of anything sockets, async, etc.
|
||||
# However, it can and has provided reasonably quick results anyhow.
|
||||
init:
|
||||
node1 = setupTestNode(eth, Whisper)
|
||||
node2 = setupTestNode(eth, Whisper)
|
||||
|
||||
node2.startListening()
|
||||
peer = waitFor node1.rlpxConnect(newNode(initENode(node2.keys.pubKey,
|
||||
node2.address)))
|
||||
|
||||
test:
|
||||
aflLoop: # This appears to have unstable results with afl-clang-fast, probably
|
||||
# because of undeterministic behaviour due to usage of network/async.
|
||||
try:
|
||||
var (msgId, msgData) = recvMsgMock(payload)
|
||||
waitFor peer.invokeThunk(msgId.int, msgData)
|
||||
except CatchableError as e:
|
||||
debug "Test caused CatchableError", exception=e.name, trace=e.repr, msg=e.msg
|
Loading…
Reference in New Issue