2018-12-12 15:18:46 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
import
|
2018-12-25 10:31:51 +00:00
|
|
|
unittest, json, os, tables, strformat, strutils,
|
2018-12-14 07:32:45 +00:00
|
|
|
eth_common, byteutils, eth_trie/db,
|
|
|
|
./test_helpers, ../nimbus/db/db_chain, ../nimbus/[tracer, vm_types]
|
2018-12-12 15:18:46 +00:00
|
|
|
|
|
|
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
|
|
|
|
|
|
|
suite "tracer json tests":
|
|
|
|
jsonTest("TracerTests", testFixture)
|
|
|
|
|
|
|
|
# use tracerTestGen.nim to generate additional test data
|
|
|
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
|
|
|
|
var
|
|
|
|
blockNumber = UInt256.fromHex(node["blockNumber"].getStr())
|
|
|
|
memoryDB = newMemoryDB()
|
|
|
|
chainDB = newBaseChainDB(memoryDB, false)
|
|
|
|
state = node["state"]
|
2018-12-25 10:31:51 +00:00
|
|
|
receipts = node["receipts"]
|
2018-12-12 15:18:46 +00:00
|
|
|
|
|
|
|
for k, v in state:
|
|
|
|
let key = hexToSeqByte(k)
|
|
|
|
let value = hexToSeqByte(v.getStr())
|
|
|
|
memoryDB.put(key, value)
|
|
|
|
|
|
|
|
var header = chainDB.getBlockHeader(blockNumber)
|
|
|
|
var headerHash = header.blockHash
|
|
|
|
var blockBody = chainDB.getBlockBody(headerHash)
|
|
|
|
|
2018-12-25 10:31:51 +00:00
|
|
|
let txTraces = traceTransactions(chainDB, header, blockBody)
|
2018-12-12 15:18:46 +00:00
|
|
|
let stateDump = dumpBlockState(chainDB, header, blockBody)
|
|
|
|
let blockTrace = traceBlock(chainDB, header, blockBody, {DisableState})
|
|
|
|
|
2018-12-25 10:31:51 +00:00
|
|
|
check node["txTraces"] == txTraces
|
2018-12-12 15:18:46 +00:00
|
|
|
check node["stateDump"] == stateDump
|
|
|
|
check node["blockTrace"] == blockTrace
|
2018-12-25 10:31:51 +00:00
|
|
|
for i in 0 ..< receipts.len:
|
|
|
|
let receipt = receipts[i]
|
|
|
|
let stateDiff = txTraces[i]["stateDiff"]
|
|
|
|
check receipt["root"].getStr().toLowerAscii() == stateDiff["afterRoot"].getStr().toLowerAscii()
|