mirror of https://github.com/status-im/nim-eth.git
Use unittest and no longer possible crash on unhandled exception
This commit is contained in:
parent
dc9f7351a1
commit
f8d506dcb1
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
json, strutils, eth/rlp
|
json, strutils, unittest, eth/rlp
|
||||||
|
|
||||||
proc append(output: var RlpWriter, js: JsonNode) =
|
proc append(output: var RlpWriter, js: JsonNode) =
|
||||||
case js.kind
|
case js.kind
|
||||||
|
@ -25,52 +25,40 @@ proc `==`(lhs: JsonNode, rhs: string): bool =
|
||||||
proc runTests*(filename: string) =
|
proc runTests*(filename: string) =
|
||||||
let js = json.parseFile(filename)
|
let js = json.parseFile(filename)
|
||||||
|
|
||||||
for testname, testdata in js:
|
suite filename:
|
||||||
template testStatus(status: string) =
|
for testname, testdata in js:
|
||||||
echo status, " ", filename, " :: ", testname
|
test testname:
|
||||||
|
let
|
||||||
|
input = testdata{"in"}
|
||||||
|
output = testdata{"out"}
|
||||||
|
|
||||||
let
|
if input.isNil or output.isNil or output.kind != JString:
|
||||||
input = testdata{"in"}
|
skip()
|
||||||
output = testdata{"out"}
|
continue
|
||||||
|
|
||||||
if input.isNil or output.isNil or output.kind != JString:
|
if input == "VALID":
|
||||||
testStatus "IGNORED"
|
var rlp = rlpFromHex(output.str)
|
||||||
continue
|
discard rlp.inspect
|
||||||
|
elif input == "INVALID":
|
||||||
|
var success = true
|
||||||
|
var inspectOutput = ""
|
||||||
|
expect MalformedRlpError, UnsupportedRlpError, ValueError:
|
||||||
|
var rlp = rlpFromHex(output.str)
|
||||||
|
inspectOutput = rlp.inspect(1)
|
||||||
|
discard rlp.getType
|
||||||
|
while rlp.hasData: discard rlp.toNodes
|
||||||
|
success = false
|
||||||
|
if not success:
|
||||||
|
echo " ACCEPTED MALFORMED BYTES: ", output.str
|
||||||
|
echo " INTERPRETATION:\n", inspectOutput
|
||||||
|
else:
|
||||||
|
if input.kind == JString and input.str.len != 0 and input.str[0] == '#':
|
||||||
|
continue
|
||||||
|
|
||||||
if input == "VALID":
|
var outRlp = initRlpWriter()
|
||||||
var rlp = rlpFromHex(output.str)
|
outRlp.append input
|
||||||
discard rlp.inspect
|
let
|
||||||
elif input == "INVALID":
|
actual = outRlp.finish.hexRepr
|
||||||
var success = false
|
expected = output.str
|
||||||
var inspectOutput = ""
|
check actual == expected
|
||||||
try:
|
|
||||||
var rlp = rlpFromHex(output.str)
|
|
||||||
inspectOutput = rlp.inspect(1)
|
|
||||||
discard rlp.getType
|
|
||||||
while rlp.hasData: discard rlp.toNodes
|
|
||||||
except MalformedRlpError, UnsupportedRlpError, ValueError:
|
|
||||||
success = true
|
|
||||||
if not success:
|
|
||||||
testStatus "FAILED"
|
|
||||||
echo " ACCEPTED MALFORMED BYTES: ", output.str
|
|
||||||
echo " INTERPRETATION:\n", inspectOutput
|
|
||||||
program_result = 1
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
if input.kind == JString and input.str.len != 0 and input.str[0] == '#':
|
|
||||||
continue
|
|
||||||
|
|
||||||
var outRlp = initRlpWriter()
|
|
||||||
outRlp.append input
|
|
||||||
let
|
|
||||||
actual = outRlp.finish.hexRepr
|
|
||||||
expected = output.str
|
|
||||||
if actual != expected:
|
|
||||||
testStatus "FAILED"
|
|
||||||
echo " EXPECTED BYTES: ", expected
|
|
||||||
echo " ACTUAL BYTES: ", actual
|
|
||||||
program_result = 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
testStatus "OK"
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue