add more test cases to evmstate tool

This commit is contained in:
jangko 2022-12-15 10:46:28 +07:00
parent 9256c741a0
commit 3a7d3311e5
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 99 additions and 29 deletions

View File

@ -55,6 +55,8 @@ type
error: string
state: StateDump
TestVMState = ref object of BaseVMState
proc extractNameAndFixture(ctx: var StateContext, n: JsonNode): JsonNode =
for label, child in n:
result = child
@ -73,15 +75,8 @@ proc toBytes(x: string): seq[byte] =
result = newSeq[byte](x.len)
for i in 0..<x.len: result[i] = x[i].byte
method getAncestorHash*(vmState: BaseVMState; blockNumber: BlockNumber): Hash256 {.gcsafe.} =
if blockNumber >= vmState.blockNumber:
return
elif blockNumber < 0:
return
elif blockNumber < vmState.blockNumber - 256:
return
else:
return keccakHash(toBytes($blockNumber))
method getAncestorHash(vmState: TestVMState; blockNumber: BlockNumber): Hash256 {.gcsafe.} =
keccakHash(toBytes($blockNumber))
proc verifyResult(ctx: var StateContext, vmState: BaseVMState) =
ctx.error = ""
@ -218,7 +213,8 @@ proc runExecution(ctx: var StateContext, conf: StateConf, pre: JsonNode): StateR
com = CommonRef.new(newMemoryDB(), params, pruneTrie = false)
parent = BlockHeader(stateRoot: emptyRlpHash)
let vmState = BaseVMState.new(
let vmState = TestVMState()
vmState.init(
parent = parent,
header = ctx.header,
com = com,

View File

@ -14,8 +14,15 @@ import
testutils/markdown_reports,
../../tests/test_allowed_to_fail
type
StatusMap = OrderedTable[string, OrderedTable[string, Status]]
TestFile = object
fullPath: string
dispName: string
const
inputFolder = "tests" / "fixtures" / "eth_tests" / "GeneralStateTests"
testData = "tools" / "evmstate" / "testdata"
proc runTest(filename: string): bool =
let appDir = getAppDir()
@ -30,31 +37,37 @@ proc runTest(filename: string): bool =
template skipTest(folder, name: untyped): bool =
skipNewGSTTests(folder, name)
proc collectFileNames(inputPath: string, map: var StatusMap, fileNames: var seq[TestFile]) =
for filename in walkDirRec(inputPath):
if not fileName.endsWith(".json"):
continue
let (folder, name) = fileName.splitPath()
let last = folder.splitPath().tail
if not map.hasKey(last):
map[last] = initOrderedTable[string, Status]()
map[last][name] = Status.Skip
if skipTest(last, name):
continue
fileNames.add TestFile(
fullPath: filename,
dispName: substr(filename, inputPath.len+1)
)
proc main() =
suite "evmstate test suite":
var status = initOrderedTable[string, OrderedTable[string, Status]]()
var filenames: seq[string] = @[]
for filename in walkDirRec(inputFolder):
if not filename.endsWith(".json"):
continue
var filenames: seq[TestFile] = @[]
collectFileNames(testData, status, filenames)
collectFileNames(inputFolder, status, filenames)
let (folder, name) = filename.splitPath()
let last = folder.splitPath().tail
if not status.hasKey(last):
status[last] = initOrderedTable[string, Status]()
status[last][name] = Status.Skip
if skipTest(last, name):
continue
filenames.add filename
for inputFile in filenames:
let testName = substr(inputFile, inputFolder.len+1)
test testName:
let (folder, name) = inputFile.splitPath()
for input in filenames:
test input.dispName:
let (folder, name) = input.fullPath.splitPath()
let last = folder.splitPath().tail
status[last][name] = Status.Fail
let res = runTest(inputFile)
let res = runTest(input.fullPath)
check true == res
if res:
status[last][name] = Status.OK

View File

@ -0,0 +1,61 @@
{
"00000682-mixed-0": {
"env": {
"currentCoinbase": "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty": "0x20000",
"currentGasLimit": "0x26e1f476fe1e22",
"currentNumber": "0x1",
"currentTimestamp": "0x3e8",
"previousHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"currentBaseFee": "0x10"
},
"pre": {
"0x00000000000000000000000000000000000000f1": {
"code": "0x600060016001600260026101f461ffff354019683d888ff28ff1a43906687896373464789f3492768e86403e407137a3915212358c89898d330b6761a1046286f1207897443a1813867aa27c9d135afd1b387e60546d6a087c9b885b41f398907c9945630a56937a03028b9af358f3407e637f13979102134684105316455b64428f5a693b3f58489067a16315649ea19c9d853d7d859200f0904758333a50115f1c6a34388a32fa1a8b3f93558c1d174179a39a5a457bf3028b6988f396425a6247a384913389190036317a587930920962f3f00960879a3a806517a254968588f448fdf3f39f8c131803694446341c3f76109739826439365873a0531b46fa89325f7a1c8ca0319293849efe737c7d753c7ea48d201620569b648384906e173276069ff12013350542a01b138b36f29539735f9a006e723d50940297a1fe3d767f7e9a3f08518a76999ffe746d91975a6e3f7f8e16703f60386e6b985b59937a70073a673547a33947925f7446641c8010348f773847359d1c776384886e5f646745185b3a6d98151aff57608f3b16459b835493119e756f3f52357878fd6f583af36e7f92106a3344614131518d95590110999e8c46558e64571d949ef40115618099053e1303a1690648130a088b587757808c11549c7b41926c8b73f1f2880709983c3153778b9966a49214f59a8c9898f27c6a880b1c33086809071a1d328f8d9e3fff7a68428b5337f3663b35567f35188b173690416051426831a04000763c17696a7c72771d375ff49e824154a36e08726154396b90a1fd0a7ff1999a68007d8c83f0985754018687917f43609e85871b9d375b648c6b17201da2817c3f6b7d789e16f2633d051554a173fd20931604f542480484955760536c8197657d008aa37b7e9d6710629241ffff3d5090861c9b6e989f5856396f5476380b13a219125f4683603c207ffa53748b6194fa439138596036799c61707b6895f4853e715f985b5af16433121676004391877e16936e6f611214410218933b5b13483c1a431d7af06678966b087a0a66f4a06920103c18163740a16efe7f007a883b188e37f037703433805b3c75801a79737c6c1456f0629b1b65a2161111378683963c3bff366461033a9633803095069785700136328e3b835889f18b136a625652203b451b1b155a556a7c53956b145773558b328b467914611a8271930367a1900253f57df49711603287748956700b9d808071987f753a8a40848f5996457b923ea3403653347905971264376dfd109da18901859d3d8a3b065b45948c11687c0542129455773a20008113920a61a2718f6d89fe9b537c1430094183945091377d7c8c333d4794521a184411338dfd746f7996303e85939702f078143a63137c9c1471413d378d140550520aa39709a095809a18428879fa789738a26aff7d",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x0000000000000000000000000000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000000000000000000000000000010",
"0x0000000000000000000000000000000000000000000000000000000000000004": "0x0000000000000000000000000000000000000000000000000000000000000010",
"0x0000000000000000000000000000000000000000000000000000000000000005": "0x0000000000000000000000000000000000000000000000000000000000000001"
},
"balance": "0x0",
"nonce": "0x0"
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"code": "0x",
"storage": {},
"balance": "0xffffffffff",
"nonce": "0x0"
}
},
"transaction": {
"gasPrice": "0x10",
"nonce": "0x0",
"to": "0x00000000000000000000000000000000000000f1",
"data": [
"0x926d2ee3090609be5a0303d046cf67e745dd024332738d5170a4ddabc53cd55ed1d2ad3ff86a7b90b94f44089d4067fded11819aed63b4963b19076e49928bb24683eff0ccab4825442af2b8"
],
"gasLimit": [
"0x7a1200"
],
"value": [
"0x"
],
"secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
},
"out": "0x",
"post": {
"London": [
{
"hash": "0x78a2cbec70a8de9eb8b073cff8071d042b5a62fe299a9b2105af54b0f49a8f01",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"indexes": {
"data": 0,
"gas": 0,
"value": 0
}
}
]
}
}
}