add indexed test config to gst
This commit is contained in:
parent
5fc93838d8
commit
51397537b7
|
@ -15,12 +15,14 @@ type
|
||||||
Configuration = ref object
|
Configuration = ref object
|
||||||
testSubject*: string
|
testSubject*: string
|
||||||
fork*: Fork
|
fork*: Fork
|
||||||
|
index*: int
|
||||||
|
|
||||||
var testConfig {.threadvar.}: Configuration
|
var testConfig {.threadvar.}: Configuration
|
||||||
|
|
||||||
proc initConfiguration(): Configuration =
|
proc initConfiguration(): Configuration =
|
||||||
result = new Configuration
|
result = new Configuration
|
||||||
result.fork = FkFrontier
|
result.fork = FkFrontier
|
||||||
|
result.index = 0
|
||||||
|
|
||||||
proc getConfiguration*(): Configuration {.gcsafe.} =
|
proc getConfiguration*(): Configuration {.gcsafe.} =
|
||||||
if isNil(testConfig):
|
if isNil(testConfig):
|
||||||
|
@ -40,6 +42,7 @@ proc processArguments*(msg: var string): ConfigStatus =
|
||||||
of cmdLongOption, cmdShortOption:
|
of cmdLongOption, cmdShortOption:
|
||||||
case key.toLowerAscii()
|
case key.toLowerAscii()
|
||||||
of "fork": config.fork = parseEnum[Fork](strip(value))
|
of "fork": config.fork = parseEnum[Fork](strip(value))
|
||||||
|
of "index": config.index = parseInt(value)
|
||||||
else:
|
else:
|
||||||
msg = "Unknown option " & key
|
msg = "Unknown option " & key
|
||||||
if value.len > 0: msg = msg & " : " & value
|
if value.len > 0: msg = msg & " : " & value
|
||||||
|
|
|
@ -25,6 +25,7 @@ type
|
||||||
expectedLogs: string
|
expectedLogs: string
|
||||||
fork: Fork
|
fork: Fork
|
||||||
debugMode: bool
|
debugMode: bool
|
||||||
|
index: int
|
||||||
|
|
||||||
GST_VMState = ref object of BaseVMState
|
GST_VMState = ref object of BaseVMState
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ proc dumpAccount(accountDb: ReadOnlyStateDB, address: EthAddress, name: string):
|
||||||
"storageRoot": %($accountDb.getStorageRoot(address))
|
"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 recipient = tester.tx.getRecipient()
|
||||||
let miner = tester.header.coinbase
|
let miner = tester.header.coinbase
|
||||||
var accounts = newJObject()
|
var accounts = newJObject()
|
||||||
|
@ -78,11 +79,15 @@ proc dumpDebugData(tester: Tester, vmState: BaseVMState, sender: EthAddress, gas
|
||||||
"structLogs": vmState.getTracingResult(),
|
"structLogs": vmState.getTracingResult(),
|
||||||
"accounts": accounts
|
"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) =
|
proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
|
||||||
var tracerFlags: set[TracerFlags] = if tester.debugMode: {TracerFlags.EnableTracing} else : {}
|
var tracerFlags: set[TracerFlags] = if tester.debugMode: {TracerFlags.EnableTracing} else : {}
|
||||||
var vmState = newGST_VMState(emptyRlpHash, tester.header, newBaseChainDB(newMemoryDb()), tracerFlags)
|
var vmState = newGST_VMState(emptyRlpHash, tester.header, newBaseChainDB(newMemoryDb()), tracerFlags)
|
||||||
|
var gasUsed: GasInt
|
||||||
|
let sender = tester.tx.getSender()
|
||||||
|
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
setupStateDB(tester.pre, db)
|
setupStateDB(tester.pre, db)
|
||||||
|
|
||||||
|
@ -93,8 +98,10 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
|
||||||
let actualLogsHash = hashLogEntries(logEntries)
|
let actualLogsHash = hashLogEntries(logEntries)
|
||||||
let expectedLogsHash = toLowerAscii(tester.expectedLogs)
|
let expectedLogsHash = toLowerAscii(tester.expectedLogs)
|
||||||
check(expectedLogsHash == actualLogsHash)
|
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):
|
if not validateTransaction(vmState, tester.tx, sender):
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
# pre-EIP158 (e.g., Byzantium) should ensure currentCoinbase exists
|
# 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)
|
db.addBalance(tester.header.coinbase, 0.u256)
|
||||||
return
|
return
|
||||||
|
|
||||||
var gasUsed: GasInt
|
|
||||||
if gasUsed + tester.tx.gasLimit <= tester.header.gasLimit:
|
if gasUsed + tester.tx.gasLimit <= tester.header.gasLimit:
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
gasUsed = tester.tx.processTransaction(sender, vmState, some(tester.fork))
|
gasUsed = tester.tx.processTransaction(sender, vmState, some(tester.fork))
|
||||||
|
@ -115,9 +121,6 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
db.addBalance(tester.header.coinbase, 0.u256)
|
db.addBalance(tester.header.coinbase, 0.u256)
|
||||||
|
|
||||||
if tester.debugMode:
|
|
||||||
tester.dumpDebugData(vmState, sender, gasUsed)
|
|
||||||
|
|
||||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
|
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
|
||||||
debugMode = false, supportedForks: set[Fork] = supportedForks) =
|
debugMode = false, supportedForks: set[Fork] = supportedForks) =
|
||||||
var tester: Tester
|
var tester: Tester
|
||||||
|
@ -137,13 +140,17 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
|
||||||
stateRoot: emptyRlpHash
|
stateRoot: emptyRlpHash
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let specifyIndex = getConfiguration().index
|
||||||
tester.debugMode = debugMode
|
tester.debugMode = debugMode
|
||||||
let ftrans = fixture["transaction"]
|
let ftrans = fixture["transaction"]
|
||||||
var testedInFork = false
|
var testedInFork = false
|
||||||
for fork in supportedForks:
|
for fork in supportedForks:
|
||||||
if fixture["post"].hasKey(forkNames[fork]):
|
if fixture["post"].hasKey(forkNames[fork]):
|
||||||
testedInFork = true
|
|
||||||
for expectation in fixture["post"][forkNames[fork]]:
|
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.expectedHash = expectation["hash"].getStr
|
||||||
tester.expectedLogs = expectation["logs"].getStr
|
tester.expectedLogs = expectation["logs"].getStr
|
||||||
let
|
let
|
||||||
|
|
Loading…
Reference in New Issue