nim-eth/tests/fuzzing/rlp/rlp_decode.nim
Jacek Sieka bb5cb6a4d0
rlp: refresh code (#683)
A first step in cleaning up RLP, which has lots of interesting issues -
the next step would be to clean up the exception handling as well
(Resultify?)

* remove `RlpNode` (unused)
* single-pass parsing for most functionality via RlpItem
* stricter conformance to spec
  * remove float support
  * warn about signed integers
  * raise on invalid RLP earlier
* avoid several pointless allocations, in particular in `listLen`,
`listElem` etc
* include spec docs
2024-05-26 09:58:24 +02:00

32 lines
700 B
Nim

import
testutils/fuzzing, chronicles,
../../../eth/rlp
type
TestEnum = enum
one = 1
two = 2
TestObject* = object
test1: uint32
test2: string
template testDecode(payload: openArray, T: type) =
try:
discard rlp.decode(payload, T)
except RlpError as e:
debug "Decode failed", err = e.msg
test:
testDecode(payload, string)
testDecode(payload, uint)
testDecode(payload, uint8)
testDecode(payload, uint16)
testDecode(payload, uint32)
testDecode(payload, uint64)
testDecode(payload, int)
testDecode(payload, bool)
testDecode(payload, seq[byte])
testDecode(payload, (string, int32))
testDecode(payload, TestEnum)
testDecode(payload, TestObject)