nim-eth/tests/fuzzing/whisper/encode_decode.nim
Kim De Mey df6020832b
Build fuzzing tests in CI and fix current fuzzing tests (#396)
* Build fuzzing tests in CI and fix current fuzzing tests

* Build fuzzing tests separately (fix Windows CI)
2021-09-07 16:00:01 +02:00

21 lines
555 B
Nim

import
std/[options, sequtils],
chronicles, testutils/fuzzing,
../../../eth/p2p/rlpx_protocols/whisper_protocol as whisper,
../../../eth/keys
test:
let
rng = newRng()
data = @payload.distribute(2)
whisperPayload = Payload(payload: data[0], padding: some(data[1]))
encoded = whisper.encode(rng[], whisperPayload)
decoded = whisper.decode(encoded.get())
doAssert data[0] == decoded.get().payload
if data[1].len > 0:
doAssert data[1] == decoded.get().padding.get()
else:
doAssert decoded.get().padding.isNone()