From e05108b7e4c1556c86ce8be4f069810174c745e9 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 19 Aug 2019 21:12:32 +0700 Subject: [PATCH] add 'trace' switch to tester configuration --- tests/test_config.nim | 3 +++ tests/test_generalstate_json.nim | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_config.nim b/tests/test_config.nim index c3b909a38..0ca6d61c3 100644 --- a/tests/test_config.nim +++ b/tests/test_config.nim @@ -16,6 +16,7 @@ type testSubject*: string fork*: Fork index*: int + trace*: bool var testConfig {.threadvar.}: Configuration @@ -23,6 +24,7 @@ proc initConfiguration(): Configuration = result = new Configuration result.fork = FkFrontier result.index = 0 + result.trace = true proc getConfiguration*(): Configuration {.gcsafe.} = if isNil(testConfig): @@ -43,6 +45,7 @@ proc processArguments*(msg: var string): ConfigStatus = case key.toLowerAscii() of "fork": config.fork = parseEnum[Fork](strip(value)) of "index": config.index = parseInt(value) + of "trace": config.trace = parseBool(value) else: msg = "Unknown option " & key if value.len > 0: msg = msg & " : " & value diff --git a/tests/test_generalstate_json.nim b/tests/test_generalstate_json.nim index 7989a6479..db26c9487 100644 --- a/tests/test_generalstate_json.nim +++ b/tests/test_generalstate_json.nim @@ -25,6 +25,7 @@ type expectedLogs: string fork: Fork debugMode: bool + trace: bool index: int GST_VMState = ref object of BaseVMState @@ -74,16 +75,17 @@ proc dumpDebugData(tester: Tester, vmState: BaseVMState, sender: EthAddress, gas accounts[$account] = dumpAccount(vmState.readOnlyStateDB, account, "pre" & $i) inc i + let tracingResult = if tester.trace: vmState.getTracingResult() else: %[] let debugData = %{ "gasUsed": %gasUsed, - "structLogs": vmState.getTracingResult(), + "structLogs": tracingResult, "accounts": accounts } let status = if success: "_success" else: "_failed" writeFile("debug_" & tester.name & "_" & $tester.index & status & ".json", debugData.pretty()) proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) = - var tracerFlags: set[TracerFlags] = if tester.debugMode: {TracerFlags.EnableTracing} else : {} + var tracerFlags: set[TracerFlags] = if tester.trace: {TracerFlags.EnableTracing} else : {} var vmState = newGST_VMState(emptyRlpHash, tester.header, newBaseChainDB(newMemoryDb()), tracerFlags) var gasUsed: GasInt let sender = tester.tx.getSender() @@ -125,7 +127,7 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) = gasUsed = tester.tx.processTransaction(sender, vmState, tester.fork) proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus, - debugMode = false, supportedForks: set[Fork] = supportedForks) = + trace = false, debugMode = false, supportedForks: set[Fork] = supportedForks) = var tester: Tester var fixture: JsonNode for label, child in fixtures: @@ -144,6 +146,7 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus, ) let specifyIndex = getConfiguration().index + tester.trace = trace tester.debugMode = debugMode let ftrans = fixture["transaction"] var testedInFork = false @@ -186,7 +189,7 @@ proc main() = var testStatusIMPL: TestStatus var forks: set[Fork] = {} forks.incl config.fork - testFixture(n, testStatusIMPL, true, forks) + testFixture(n, testStatusIMPL, config.trace, true, forks) when isMainModule: var message: string