add indexed test config to gst

This commit is contained in:
andri lim 2019-03-21 16:01:26 +07:00
parent 5fc93838d8
commit 51397537b7
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 19 additions and 9 deletions

View File

@ -15,12 +15,14 @@ type
Configuration = ref object
testSubject*: string
fork*: Fork
index*: int
var testConfig {.threadvar.}: Configuration
proc initConfiguration(): Configuration =
result = new Configuration
result.fork = FkFrontier
result.index = 0
proc getConfiguration*(): Configuration {.gcsafe.} =
if isNil(testConfig):
@ -40,6 +42,7 @@ proc processArguments*(msg: var string): ConfigStatus =
of cmdLongOption, cmdShortOption:
case key.toLowerAscii()
of "fork": config.fork = parseEnum[Fork](strip(value))
of "index": config.index = parseInt(value)
else:
msg = "Unknown option " & key
if value.len > 0: msg = msg & " : " & value

View File

@ -25,6 +25,7 @@ type
expectedLogs: string
fork: Fork
debugMode: bool
index: int
GST_VMState = ref object of BaseVMState
@ -56,7 +57,7 @@ proc dumpAccount(accountDb: ReadOnlyStateDB, address: EthAddress, name: string):
"storageRoot": %($accountDb.getStorageRoot(address))
}
proc dumpDebugData(tester: Tester, vmState: BaseVMState, sender: EthAddress, gasUsed: GasInt) =
proc dumpDebugData(tester: Tester, vmState: BaseVMState, sender: EthAddress, gasUsed: GasInt, success: bool) =
let recipient = tester.tx.getRecipient()
let miner = tester.header.coinbase
var accounts = newJObject()
@ -78,11 +79,15 @@ proc dumpDebugData(tester: Tester, vmState: BaseVMState, sender: EthAddress, gas
"structLogs": vmState.getTracingResult(),
"accounts": accounts
}
writeFile("debug_" & tester.name & ".json", debugData.pretty())
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 vmState = newGST_VMState(emptyRlpHash, tester.header, newBaseChainDB(newMemoryDb()), tracerFlags)
var gasUsed: GasInt
let sender = tester.tx.getSender()
vmState.mutateStateDB:
setupStateDB(tester.pre, db)
@ -93,8 +98,10 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
let actualLogsHash = hashLogEntries(logEntries)
let expectedLogsHash = toLowerAscii(tester.expectedLogs)
check(expectedLogsHash == actualLogsHash)
if tester.debugMode:
let success = expectedLogsHash == actualLogsHash and obtainedHash == tester.expectedHash
tester.dumpDebugData(vmState, sender, gasUsed, success)
let sender = tester.tx.getSender()
if not validateTransaction(vmState, tester.tx, sender):
vmState.mutateStateDB:
# pre-EIP158 (e.g., Byzantium) should ensure currentCoinbase exists
@ -102,7 +109,6 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
db.addBalance(tester.header.coinbase, 0.u256)
return
var gasUsed: GasInt
if gasUsed + tester.tx.gasLimit <= tester.header.gasLimit:
vmState.mutateStateDB:
gasUsed = tester.tx.processTransaction(sender, vmState, some(tester.fork))
@ -115,9 +121,6 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
vmState.mutateStateDB:
db.addBalance(tester.header.coinbase, 0.u256)
if tester.debugMode:
tester.dumpDebugData(vmState, sender, gasUsed)
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
debugMode = false, supportedForks: set[Fork] = supportedForks) =
var tester: Tester
@ -137,13 +140,17 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
stateRoot: emptyRlpHash
)
let specifyIndex = getConfiguration().index
tester.debugMode = debugMode
let ftrans = fixture["transaction"]
var testedInFork = false
for fork in supportedForks:
if fixture["post"].hasKey(forkNames[fork]):
testedInFork = true
for expectation in fixture["post"][forkNames[fork]]:
inc tester.index
if specifyIndex > 0 and tester.index != specifyIndex:
continue
testedInFork = true
tester.expectedHash = expectation["hash"].getStr
tester.expectedLogs = expectation["logs"].getStr
let