add fuzz test tool

This commit is contained in:
jangko 2020-05-19 11:34:40 +07:00
parent 6c583c8e32
commit 0f9b31a958
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 43 additions and 1 deletions

11
stateless/test_fuzz.nim Normal file
View File

@ -0,0 +1,11 @@
import
testutils/fuzzing, eth/trie/db,
./tree_from_witness, ./witness_types
test:
var db = newMemoryDB()
try:
var tb = initTreeBuilder(payload, db, {wfEIP170})
let root = tb.buildTree()
except ParsingError, ContractCodeError:
debugEcho "Error detected ", getCurrentExceptionMsg()

View File

@ -1,6 +1,6 @@
import
eth/common, eth/trie/db, json, os, unittest,
../stateless/[tree_from_witness],
./tree_from_witness, parseopt,
./witness_types, stew/byteutils
type
@ -132,7 +132,38 @@ proc runTest(filePath, fileName: string) =
debugEcho "Error detected ", getCurrentExceptionMsg()
check t.error == true
proc writeFuzzData(filePath, fileName: string) =
let t = parseTester(filePath)
var db = newMemoryDB()
var tb = initTreeBuilder(t.output, db, {wfEIP170})
let root = tb.buildTree()
writeFile(filename, t.output)
proc witnessJsonMain*() =
var filename: string
var numArg = 0
for kind, key, val in getopt():
case kind
of cmdArgument:
inc numArg
case numArg
of 1:
if key != "fuzz":
quit(1)
of 2:
filename = key
else:
discard
of cmdLongOption, cmdShortOption:
discard
of cmdEnd: assert(false) # cannot happen
if filename != "":
echo "generate fuzz data"
writeFuzzData(filename, "fuzz.data")
return
for x in walkDirRec("stateless" / "fixtures"):
let y = splitPath(x)
runTest(x, y.tail)