2018-12-25 12:10:04 +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
|
2019-05-30 16:42:55 +00:00
|
|
|
unittest2, json, os, tables, strformat, strutils,
|
2019-07-07 10:12:01 +00:00
|
|
|
eth/[common, rlp], stew/byteutils, eth/trie/db,
|
2019-11-13 14:49:39 +00:00
|
|
|
./test_helpers, ../nimbus/db/db_chain,
|
2018-12-25 12:10:04 +00:00
|
|
|
../nimbus/p2p/chain
|
|
|
|
|
|
|
|
# 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"]
|
|
|
|
|
|
|
|
for k, v in state:
|
|
|
|
let key = hexToSeqByte(k)
|
|
|
|
let value = hexToSeqByte(v.getStr())
|
|
|
|
memoryDB.put(key, value)
|
|
|
|
|
|
|
|
let
|
|
|
|
parentNumber = blockNumber - 1
|
|
|
|
parent = chainDB.getBlockHeader(parentNumber)
|
|
|
|
header = chainDB.getBlockHeader(blockNumber)
|
|
|
|
headerHash = header.blockHash
|
|
|
|
blockBody = chainDB.getBlockBody(headerHash)
|
|
|
|
chain = newChain(chainDB)
|
|
|
|
headers = @[header]
|
|
|
|
bodies = @[blockBody]
|
|
|
|
|
2019-01-01 03:55:40 +00:00
|
|
|
chainDB.setHead(parent, true)
|
2018-12-25 12:10:04 +00:00
|
|
|
let validationResult = chain.persistBlocks(headers, bodies)
|
|
|
|
check validationResult == ValidationResult.OK
|
2019-05-30 16:42:55 +00:00
|
|
|
|
|
|
|
proc persistBlockJsonMain*() =
|
|
|
|
suite "persist block json tests":
|
2019-11-20 17:07:17 +00:00
|
|
|
jsonTest("PersistBlockTests", testFixture)
|