From 3844bc9a112bc813c7f2e18e02406e52e010c6cc Mon Sep 17 00:00:00 2001 From: andri lim Date: Fri, 15 Mar 2019 22:34:05 +0700 Subject: [PATCH] faster gst helpers --- tests/test_helpers.nim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index 88cba39c6..1bdac79c8 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -119,10 +119,10 @@ func validTest*(folder: string, name: string): bool = not slowTest(folder, name) and not allowedFailInCurrentBuild(folder, name) -proc lacksSupportedForks*(filename: string): bool = +proc lacksSupportedForks*(fixtures: JsonNode): bool = # XXX: Until Nimbus supports Byzantine or newer forks, as opposed # to Homestead, ~1k of ~2.5k GeneralStateTests won't work. - let fixtures = parseJSON(readFile(filename)) + var fixture: JsonNode for label, child in fixtures: fixture = child @@ -131,10 +131,10 @@ proc lacksSupportedForks*(filename: string): bool = # not all fixtures make a distinction between forks, so default to accepting # them all, until we find the ones that specify forks in their "post" section result = false - if fixture.kind == JObject and fixture.has_key("transaction") and fixture.has_key("post"): + if fixture.kind == JObject and fixture.hasKey("transaction") and fixture.hasKey("post"): result = true for fork in supportedForks: - if fixture["post"].has_key(forkNames[fork]): + if fixture["post"].hasKey(forkNames[fork]): result = false break @@ -158,15 +158,19 @@ macro jsonTest*(s: static[string], handler: untyped): untyped = if not status.hasKey(last): status[last] = initOrderedTable[string, Status]() status[last][name] = Status.Skip - if last.validTest(name) and not filename.lacksSupportedForks: + if last.validTest(name): filenames.add((filename, last, name)) for child in filenames: let (filename, folder, name) = child # we set this here because exceptions might be raised in the handler: status[folder][name] = Status.Fail + let fixtures = parseJSON(readFile(filename)) + if fixtures.lacksSupportedForks: + status[folder][name] = Status.Skip + continue test filename: echo folder / name - `handler`(parseJSON(readFile(filename)), `testStatusIMPL`) + `handler`(fixtures, `testStatusIMPL`) if `testStatusIMPL` == OK: status[folder][name] = Status.OK