From 5ee918f4ef278fee3514c0922a0f8f1cad652983 Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 12 May 2021 08:57:24 +0700 Subject: [PATCH] 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. --- nimbus/genesis.nim | 1 + tests/test_graphql.nim | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/nimbus/genesis.nim b/nimbus/genesis.nim index 67b1d3163..4edf5f0f0 100644 --- a/nimbus/genesis.nim +++ b/nimbus/genesis.nim @@ -97,6 +97,7 @@ proc defaultGenesisBlockForNetwork*(id: PublicNetwork): Genesis = of CustomNet: let genesis = getConfiguration().customGenesis var alloc = new GenesisAlloc + assert(genesis.prealloc.isNil.not, "genesis prealloc should not nil") if genesis.prealloc != parseJson("{}"): alloc = customNetPrealloc(genesis.prealloc) Genesis( diff --git a/tests/test_graphql.nim b/tests/test_graphql.nim index 69c7f247a..ef36dc2ec 100644 --- a/tests/test_graphql.nim +++ b/tests/test_graphql.nim @@ -13,7 +13,7 @@ import eth/[p2p, common, trie/db, rlp, trie], eth/p2p/rlpx_protocols/eth_protocol, 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 type @@ -38,26 +38,18 @@ proc setupChain(chainDB: BaseChainDB) = break let genesisBlock = jn.toBlock("genesisRLP") - discard chainDB.persistHeaderToDb(genesisBlock.header) - var trie = initHexaryTrie(chainDB.db) - var sdb = newAccountStateDB(chainDB.db, trie.rootHash, chainDB.pruneTrie) + let conf = getConfiguration() + 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"] var headers: seq[BlockHeader] var bodies: seq[BlockBody]