mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
add config to gst
This commit is contained in:
parent
31e8b3d7ed
commit
0b43b143b1
51
tests/test_config.nim
Normal file
51
tests/test_config.nim
Normal 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
|
@ -8,8 +8,8 @@
|
|||||||
import
|
import
|
||||||
unittest, strformat, strutils, tables, json, ospaths, times, os,
|
unittest, strformat, strutils, tables, json, ospaths, times, os,
|
||||||
byteutils, ranges/typedranges, nimcrypto, options,
|
byteutils, ranges/typedranges, nimcrypto, options,
|
||||||
eth/[rlp, common, keys], eth/trie/[db, trie_defs], chronicles,
|
eth/[rlp, common], eth/trie/[db, trie_defs], chronicles,
|
||||||
./test_helpers, ../nimbus/p2p/executor,
|
./test_helpers, ../nimbus/p2p/executor, test_config,
|
||||||
../nimbus/[constants, errors, transaction],
|
../nimbus/[constants, errors, transaction],
|
||||||
../nimbus/[vm_state, vm_types, vm_state_transactions, utils],
|
../nimbus/[vm_state, vm_types, vm_state_transactions, utils],
|
||||||
../nimbus/vm/interpreter,
|
../nimbus/vm/interpreter,
|
||||||
@ -90,7 +90,8 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
|
|||||||
if tester.debugMode:
|
if tester.debugMode:
|
||||||
tester.dumpDebugData(vmState, sender, gasUsed)
|
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 tester: Tester
|
||||||
var fixture: JsonNode
|
var fixture: JsonNode
|
||||||
for label, child in fixtures:
|
for label, child in fixtures:
|
||||||
@ -110,9 +111,10 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus, debugMode =
|
|||||||
|
|
||||||
tester.debugMode = debugMode
|
tester.debugMode = debugMode
|
||||||
let ftrans = fixture["transaction"]
|
let ftrans = fixture["transaction"]
|
||||||
|
var testedInFork = false
|
||||||
for fork in supportedForks:
|
for fork in supportedForks:
|
||||||
if fixture["post"].hasKey(forkNames[fork]):
|
if fixture["post"].hasKey(forkNames[fork]):
|
||||||
# echo "[fork: ", forkNames[fork], "]"
|
testedInFork = true
|
||||||
for expectation in fixture["post"][forkNames[fork]]:
|
for expectation in fixture["post"][forkNames[fork]]:
|
||||||
tester.expectedHash = expectation["hash"].getStr
|
tester.expectedHash = expectation["hash"].getStr
|
||||||
tester.expectedLogs = expectation["logs"].getStr
|
tester.expectedLogs = expectation["logs"].getStr
|
||||||
@ -126,6 +128,9 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus, debugMode =
|
|||||||
tester.fork = fork
|
tester.fork = fork
|
||||||
testFixtureIndexes(tester, testStatusIMPL)
|
testFixtureIndexes(tester, testStatusIMPL)
|
||||||
|
|
||||||
|
if not testedInFork:
|
||||||
|
echo "test subject '", tester.name, "' not tested in any forks"
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
if paramCount() == 0:
|
if paramCount() == 0:
|
||||||
# run all test fixtures
|
# run all test fixtures
|
||||||
@ -133,9 +138,28 @@ proc main() =
|
|||||||
jsonTest("GeneralStateTests", testFixture)
|
jsonTest("GeneralStateTests", testFixture)
|
||||||
else:
|
else:
|
||||||
# execute single test in debug mode
|
# execute single test in debug mode
|
||||||
let path = "tests" / "fixtures" / "GeneralStateTests"
|
let config = getConfiguration()
|
||||||
let n = json.parseFile(path / paramStr(1))
|
if config.testSubject.len == 0:
|
||||||
var testStatusIMPL: TestStatus
|
echo "missing test subject"
|
||||||
testFixture(n, testStatusIMPL, true)
|
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()
|
||||||
|
@ -24,7 +24,7 @@ const
|
|||||||
FkByzantium: "Byzantium",
|
FkByzantium: "Byzantium",
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
supportedForks* = [FkFrontier, FkHomestead]
|
supportedForks* = {FkFrontier, FkHomestead}
|
||||||
|
|
||||||
type
|
type
|
||||||
Status* {.pure.} = enum OK, Fail, Skip
|
Status* {.pure.} = enum OK, Fail, Skip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user