add logs hash check to GST

This commit is contained in:
andri lim 2019-02-28 15:22:07 +07:00 committed by zah
parent ffe8769259
commit 9ee3458dd4
1 changed files with 14 additions and 3 deletions

View File

@ -15,12 +15,16 @@ import
../nimbus/vm/interpreter, ../nimbus/vm/interpreter,
../nimbus/db/[db_chain, state_db] ../nimbus/db/[db_chain, state_db]
proc hashLogEntries(logs: seq[Log]): string =
toLowerAscii("0x" & $keccak(rlp.encode(logs)))
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus)
suite "generalstate json tests": suite "generalstate json tests":
jsonTest("GeneralStateTests", testFixture) jsonTest("GeneralStateTests", testFixture)
proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNode, tx: Transaction, sender: EthAddress, expectedHash: string, testStatusIMPL: var TestStatus, fork: Fork) = proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNode, tx: Transaction,
sender: EthAddress, expectedHash, expectedLogs: string, testStatusIMPL: var TestStatus, fork: Fork) =
when enabledLogLevel <= TRACE: when enabledLogLevel <= TRACE:
let tracerFlags = {TracerFlags.EnableTracing} let tracerFlags = {TracerFlags.EnableTracing}
else: else:
@ -33,6 +37,10 @@ proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNo
#echo vmState.readOnlyStateDB.dumpAccount("c94f5374fce5edbc8e2a8697c15331677e6ebf0b") #echo vmState.readOnlyStateDB.dumpAccount("c94f5374fce5edbc8e2a8697c15331677e6ebf0b")
let obtainedHash = "0x" & `$`(vmState.readOnlyStateDB.rootHash).toLowerAscii let obtainedHash = "0x" & `$`(vmState.readOnlyStateDB.rootHash).toLowerAscii
check obtainedHash == expectedHash check obtainedHash == expectedHash
let logEntries = vmState.getAndClearLogEntries()
let actualLogsHash = hashLogEntries(logEntries)
let expectedLogsHash = toLowerAscii(expectedLogs)
check(expectedLogsHash == actualLogsHash)
if not validateTransaction(vmState, tx, sender): if not validateTransaction(vmState, tx, sender):
vmState.mutateStateDB: vmState.mutateStateDB:
@ -70,15 +78,18 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
let ftrans = fixture["transaction"] let ftrans = fixture["transaction"]
for fork in supportedForks: for fork in supportedForks:
if fixture["post"].has_key(forkNames[fork]): if fixture["post"].hasKey(forkNames[fork]):
# echo "[fork: ", forkNames[fork], "]" # echo "[fork: ", forkNames[fork], "]"
for expectation in fixture["post"][forkNames[fork]]: for expectation in fixture["post"][forkNames[fork]]:
let let
expectedHash = expectation["hash"].getStr expectedHash = expectation["hash"].getStr
expectedLogs = expectation["logs"].getStr
indexes = expectation["indexes"] indexes = expectation["indexes"]
dataIndex = indexes["data"].getInt dataIndex = indexes["data"].getInt
gasIndex = indexes["gas"].getInt gasIndex = indexes["gas"].getInt
valueIndex = indexes["value"].getInt valueIndex = indexes["value"].getInt
let transaction = ftrans.getFixtureTransaction(dataIndex, gasIndex, valueIndex) let transaction = ftrans.getFixtureTransaction(dataIndex, gasIndex, valueIndex)
let sender = ftrans.getFixtureTransactionSender let sender = ftrans.getFixtureTransactionSender
testFixtureIndexes(emptyRlpHash, header, fixture["pre"], transaction, sender, expectedHash, testStatusIMPL, fork) testFixtureIndexes(emptyRlpHash, header, fixture["pre"], transaction,
sender, expectedHash, expectedLogs, testStatusIMPL, fork)