fixes test_graphql crash due to recent changes related to `chainId`
now test_graphql takes another route to initialize the empty db that is safer instead of bypassing commonly used route.
This commit is contained in:
parent
f6a0e4bcbd
commit
5ee918f4ef
|
@ -97,6 +97,7 @@ proc defaultGenesisBlockForNetwork*(id: PublicNetwork): Genesis =
|
||||||
of CustomNet:
|
of CustomNet:
|
||||||
let genesis = getConfiguration().customGenesis
|
let genesis = getConfiguration().customGenesis
|
||||||
var alloc = new GenesisAlloc
|
var alloc = new GenesisAlloc
|
||||||
|
assert(genesis.prealloc.isNil.not, "genesis prealloc should not nil")
|
||||||
if genesis.prealloc != parseJson("{}"):
|
if genesis.prealloc != parseJson("{}"):
|
||||||
alloc = customNetPrealloc(genesis.prealloc)
|
alloc = customNetPrealloc(genesis.prealloc)
|
||||||
Genesis(
|
Genesis(
|
||||||
|
|
|
@ -13,7 +13,7 @@ import
|
||||||
eth/[p2p, common, trie/db, rlp, trie],
|
eth/[p2p, common, trie/db, rlp, trie],
|
||||||
eth/p2p/rlpx_protocols/eth_protocol,
|
eth/p2p/rlpx_protocols/eth_protocol,
|
||||||
graphql, ../nimbus/graphql/ethapi, graphql/test_common,
|
graphql, ../nimbus/graphql/ethapi, graphql/test_common,
|
||||||
../nimbus/config, ../nimbus/db/[db_chain, state_db],
|
../nimbus/[genesis, config], ../nimbus/db/[db_chain, state_db],
|
||||||
../nimbus/p2p/chain, ../premix/parser, ./test_helpers
|
../nimbus/p2p/chain, ../premix/parser, ./test_helpers
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -38,26 +38,18 @@ proc setupChain(chainDB: BaseChainDB) =
|
||||||
break
|
break
|
||||||
|
|
||||||
let genesisBlock = jn.toBlock("genesisRLP")
|
let genesisBlock = jn.toBlock("genesisRLP")
|
||||||
discard chainDB.persistHeaderToDb(genesisBlock.header)
|
|
||||||
|
|
||||||
var trie = initHexaryTrie(chainDB.db)
|
let conf = getConfiguration()
|
||||||
var sdb = newAccountStateDB(chainDB.db, trie.rootHash, chainDB.pruneTrie)
|
conf.customGenesis.nonce = genesisBlock.header.nonce
|
||||||
|
conf.customGenesis.extraData = genesisBlock.header.extraData
|
||||||
|
conf.customGenesis.gasLimit = genesisBlock.header.gasLimit
|
||||||
|
conf.customGenesis.difficulty = genesisBlock.header.difficulty
|
||||||
|
conf.customGenesis.mixHash = genesisBlock.header.mixDigest
|
||||||
|
conf.customGenesis.coinBase = genesisBlock.header.coinbase
|
||||||
|
conf.customGenesis.timestamp = genesisBlock.header.timestamp
|
||||||
|
conf.customGenesis.prealloc = jn["pre"]
|
||||||
|
chainDB.initializeEmptyDb()
|
||||||
|
|
||||||
let preState = jn["pre"]
|
|
||||||
for addrStr, accNode in preState:
|
|
||||||
let address = hexToByteArray[20](addrStr)
|
|
||||||
let balance = UInt256.fromHex(accNode["balance"].str)
|
|
||||||
let nonce = hexToInt(accNode["nonce"].str, AccountNonce)
|
|
||||||
let code = hexToSeqByte(accNode["code"].str)
|
|
||||||
sdb.setAccount(address, newAccount(nonce, balance))
|
|
||||||
sdb.setCode(address, code)
|
|
||||||
let storage = accNode["storage"]
|
|
||||||
for k, v in storage:
|
|
||||||
let slot = UInt256.fromHex(k)
|
|
||||||
let val = UInt256.fromHex(v.str)
|
|
||||||
sdb.setStorage(address, slot, val)
|
|
||||||
|
|
||||||
assert(sdb.rootHash == genesisBlock.header.stateRoot)
|
|
||||||
let blocks = jn["blocks"]
|
let blocks = jn["blocks"]
|
||||||
var headers: seq[BlockHeader]
|
var headers: seq[BlockHeader]
|
||||||
var bodies: seq[BlockBody]
|
var bodies: seq[BlockBody]
|
||||||
|
|
Loading…
Reference in New Issue