add config to gst

This commit is contained in:
andri lim 2019-03-18 10:05:24 +07:00
parent 31e8b3d7ed
commit 0b43b143b1
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 85 additions and 10 deletions

51
tests/test_config.nim Normal file
View File

@ -0,0 +1,51 @@
import
parseopt, strutils,
../nimbus/vm/interpreter/vm_forks
type
ConfigStatus* = enum
## Configuration status flags
Success, ## Success
EmptyOption, ## No options in category
ErrorUnknownOption, ## Unknown option in command line found
ErrorParseOption, ## Error in parsing command line option
ErrorIncorrectOption, ## Option has incorrect value
Error ## Unspecified error
Configuration = ref object
testSubject*: string
fork*: Fork
var testConfig {.threadvar.}: Configuration
proc initConfiguration(): Configuration =
result = new Configuration
result.fork = FkFrontier
proc getConfiguration*(): Configuration {.gcsafe.} =
if isNil(testConfig):
testConfig = initConfiguration()
result = testConfig
proc processArguments*(msg: var string): ConfigStatus =
var
opt = initOptParser()
config = getConfiguration()
result = Success
for kind, key, value in opt.getopt():
case kind
of cmdArgument:
config.testSubject = key
of cmdLongOption, cmdShortOption:
case key.toLowerAscii()
of "fork": config.fork = parseEnum[Fork](strip(value))
else:
msg = "Unknown option " & key
if value.len > 0: msg = msg & " : " & value
result = ErrorUnknownOption
break
of cmdEnd:
msg = "Error processing option [" & key & "]"
result = ErrorParseOption
break

View File

@ -8,8 +8,8 @@
import
unittest, strformat, strutils, tables, json, ospaths, times, os,
byteutils, ranges/typedranges, nimcrypto, options,
eth/[rlp, common, keys], eth/trie/[db, trie_defs], chronicles,
./test_helpers, ../nimbus/p2p/executor,
eth/[rlp, common], eth/trie/[db, trie_defs], chronicles,
./test_helpers, ../nimbus/p2p/executor, test_config,
../nimbus/[constants, errors, transaction],
../nimbus/[vm_state, vm_types, vm_state_transactions, utils],
../nimbus/vm/interpreter,
@ -90,7 +90,8 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
if tester.debugMode:
tester.dumpDebugData(vmState, sender, gasUsed)
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus, debugMode = false) =
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
debugMode = false, supportedForks: set[Fork] = supportedForks) =
var tester: Tester
var fixture: JsonNode
for label, child in fixtures:
@ -110,9 +111,10 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus, debugMode =
tester.debugMode = debugMode
let ftrans = fixture["transaction"]
var testedInFork = false
for fork in supportedForks:
if fixture["post"].hasKey(forkNames[fork]):
# echo "[fork: ", forkNames[fork], "]"
testedInFork = true
for expectation in fixture["post"][forkNames[fork]]:
tester.expectedHash = expectation["hash"].getStr
tester.expectedLogs = expectation["logs"].getStr
@ -126,6 +128,9 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus, debugMode =
tester.fork = fork
testFixtureIndexes(tester, testStatusIMPL)
if not testedInFork:
echo "test subject '", tester.name, "' not tested in any forks"
proc main() =
if paramCount() == 0:
# run all test fixtures
@ -133,9 +138,28 @@ proc main() =
jsonTest("GeneralStateTests", testFixture)
else:
# execute single test in debug mode
let path = "tests" / "fixtures" / "GeneralStateTests"
let n = json.parseFile(path / paramStr(1))
var testStatusIMPL: TestStatus
testFixture(n, testStatusIMPL, true)
let config = getConfiguration()
if config.testSubject.len == 0:
echo "missing test subject"
quit(QuitFailure)
main()
let path = "tests" / "fixtures" / "GeneralStateTests"
let n = json.parseFile(path / config.testSubject)
var testStatusIMPL: TestStatus
var forks: set[Fork] = {}
forks.incl config.fork
testFixture(n, testStatusIMPL, true, forks)
when isMainModule:
var message: string
## Processing command line arguments
if processArguments(message) != Success:
echo message
quit(QuitFailure)
else:
if len(message) > 0:
echo message
quit(QuitSuccess)
main()

View File

@ -24,7 +24,7 @@ const
FkByzantium: "Byzantium",
}.toTable
supportedForks* = [FkFrontier, FkHomestead]
supportedForks* = {FkFrontier, FkHomestead}
type
Status* {.pure.} = enum OK, Fail, Skip