fix test_witness_json wrong code arrangement

This commit is contained in:
jangko 2020-05-20 11:36:09 +07:00
parent 048c8a41f1
commit ed3434f38f
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 18 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import import
eth/common, eth/trie/db, json, os, unittest, eth/common, eth/trie/db, json, os, unittest2,
./tree_from_witness, parseopt, ./tree_from_witness, parseopt,
./witness_types, stew/byteutils ./witness_types, stew/byteutils
@ -99,7 +99,7 @@ proc processNode(t: var Tester, x: JsonNode, storageMode: bool = false) =
proc parseRootHash(x: string): KeccakHash = proc parseRootHash(x: string): KeccakHash =
result.data = hexToByteArray[32](x) result.data = hexToByteArray[32](x)
proc parseTester(t: var Tester, n: JsonNode) = proc parseTester(t: var Tester, n: JsonNode, testStatusIMPL: var TestStatus) =
t.error = n["error"].getBool() t.error = n["error"].getBool()
t.rootHash = parseRootHash(n["rootHash"].getStr()) t.rootHash = parseRootHash(n["rootHash"].getStr())
t.write(n["version"]) t.write(n["version"])
@ -112,13 +112,13 @@ proc parseTester(t: var Tester, n: JsonNode) =
except ParsingError: except ParsingError:
check t.error == true check t.error == true
proc parseTester(filename: string): Tester = proc parseTester(filename: string, testStatusIMPL: var TestStatus): Tester =
let n = parseFile(filename) let n = parseFile(filename)
parseTester(result, n) parseTester(result, n, testStatusIMPL)
proc runTest(filePath, fileName: string) = proc runTest(filePath, fileName: string) =
test fileName: test fileName:
let t = parseTester(filePath) let t = parseTester(filePath, testStatusIMPL)
var db = newMemoryDB() var db = newMemoryDB()
try: try:
var tb = initTreeBuilder(t.output, db, {wfEIP170}) var tb = initTreeBuilder(t.output, db, {wfEIP170})
@ -129,17 +129,18 @@ proc runTest(filePath, fileName: string) =
check root == t.rootHash check root == t.rootHash
check t.error == false check t.error == false
except ParsingError, ContractCodeError: except ParsingError, ContractCodeError:
debugEcho "Error detected ", getCurrentExceptionMsg() echo "Exception detected ", getCurrentExceptionMsg()
check t.error == true check t.error == true
proc writeFuzzData(filePath, fileName: string) = proc writeFuzzData(filePath, fileName: string) =
let t = parseTester(filePath) var testStatusIMPL: TestStatus
let t = parseTester(filePath, testStatusIMPL)
var db = newMemoryDB() var db = newMemoryDB()
var tb = initTreeBuilder(t.output, db, {wfEIP170}) var tb = initTreeBuilder(t.output, db, {wfEIP170})
let root = tb.buildTree() let root = tb.buildTree()
writeFile(filename, t.output) writeFile(filename, t.output)
proc witnessJsonMain*() = proc fuzzTool(): bool =
var filename: string var filename: string
var numArg = 0 var numArg = 0
@ -162,11 +163,14 @@ proc witnessJsonMain*() =
if filename != "": if filename != "":
echo "generate fuzz data" echo "generate fuzz data"
writeFuzzData(filename, "fuzz.data") writeFuzzData(filename, "fuzz.data")
return return true
for x in walkDirRec("stateless" / "fixtures"): proc witnessJsonMain*() =
let y = splitPath(x) suite "test tree builder against json fixtures":
runTest(x, y.tail) for x in walkDirRec("stateless" / "fixtures"):
let y = splitPath(x)
runTest(x, y.tail)
when isMainModule: when isMainModule:
witnessJsonMain() if not fuzzTool():
witnessJsonMain()

View File

@ -1,5 +1,5 @@
import import
randutils, random, unittest, stew/byteutils, randutils, random, unittest2, stew/byteutils,
eth/[common, rlp], eth/trie/[hexary, db, trie_defs, nibbles], eth/[common, rlp], eth/trie/[hexary, db, trie_defs, nibbles],
faststreams/inputs, nimcrypto/sysrand, faststreams/inputs, nimcrypto/sysrand,
../stateless/[witness_from_tree, tree_from_witness], ../stateless/[witness_from_tree, tree_from_witness],