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
|
||||
json, strutils, eth/rlp
|
||||
json, strutils, unittest, eth/rlp
|
||||
|
||||
proc append(output: var RlpWriter, js: JsonNode) =
|
||||
case js.kind
|
||||
|
@ -25,37 +25,32 @@ proc `==`(lhs: JsonNode, rhs: string): bool =
|
|||
proc runTests*(filename: string) =
|
||||
let js = json.parseFile(filename)
|
||||
|
||||
suite filename:
|
||||
for testname, testdata in js:
|
||||
template testStatus(status: string) =
|
||||
echo status, " ", filename, " :: ", testname
|
||||
|
||||
test testname:
|
||||
let
|
||||
input = testdata{"in"}
|
||||
output = testdata{"out"}
|
||||
|
||||
if input.isNil or output.isNil or output.kind != JString:
|
||||
testStatus "IGNORED"
|
||||
skip()
|
||||
continue
|
||||
|
||||
if input == "VALID":
|
||||
var rlp = rlpFromHex(output.str)
|
||||
discard rlp.inspect
|
||||
elif input == "INVALID":
|
||||
var success = false
|
||||
var success = true
|
||||
var inspectOutput = ""
|
||||
try:
|
||||
expect MalformedRlpError, UnsupportedRlpError, ValueError:
|
||||
var rlp = rlpFromHex(output.str)
|
||||
inspectOutput = rlp.inspect(1)
|
||||
discard rlp.getType
|
||||
while rlp.hasData: discard rlp.toNodes
|
||||
except MalformedRlpError, UnsupportedRlpError, ValueError:
|
||||
success = true
|
||||
success = false
|
||||
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
|
||||
|
@ -65,12 +60,5 @@ proc runTests*(filename: string) =
|
|||
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"
|
||||
check actual == expected
|
||||
|
||||
|
|
Loading…
Reference in New Issue