2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2023 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.
|
|
|
|
|
2023-07-09 02:16:22 +00:00
|
|
|
import
|
|
|
|
std/[json],
|
|
|
|
eth/p2p as eth_p2p,
|
|
|
|
eth/trie/trie_defs,
|
|
|
|
stew/[byteutils],
|
|
|
|
json_rpc/[rpcserver, rpcclient],
|
|
|
|
../../../nimbus/[
|
|
|
|
config,
|
|
|
|
constants,
|
|
|
|
transaction,
|
2023-12-12 19:12:56 +00:00
|
|
|
db/ledger,
|
2023-07-09 02:16:22 +00:00
|
|
|
core/chain,
|
|
|
|
core/tx_pool,
|
|
|
|
rpc,
|
|
|
|
sync/protocol,
|
2023-08-27 01:23:45 +00:00
|
|
|
beacon/beacon_engine,
|
2023-07-09 02:16:22 +00:00
|
|
|
common
|
|
|
|
],
|
|
|
|
../../../tests/test_helpers,
|
|
|
|
../../../tools/evmstate/helpers
|
|
|
|
|
|
|
|
type
|
|
|
|
TestEnv* = ref object
|
|
|
|
conf*: NimbusConf
|
|
|
|
ctx: EthContext
|
|
|
|
ethNode: EthereumNode
|
|
|
|
com: CommonRef
|
|
|
|
chainRef: ChainRef
|
|
|
|
rpcServer: RpcHttpServer
|
|
|
|
rpcClient*: RpcHttpClient
|
|
|
|
|
|
|
|
const
|
|
|
|
engineSigner = hexToByteArray[20]("0x658bdf435d810c91414ec09147daa6db62406379")
|
|
|
|
|
|
|
|
proc genesisHeader(node: JsonNode): BlockHeader =
|
|
|
|
let genesisRLP = hexToSeqByte(node["genesisRLP"].getStr)
|
|
|
|
rlp.decode(genesisRLP, EthBlock).header
|
|
|
|
|
|
|
|
proc setupELClient*(t: TestEnv, conf: ChainConfig, node: JsonNode) =
|
2023-08-04 11:10:09 +00:00
|
|
|
let memDB = newCoreDbRef LegacyDbMemory
|
2023-07-09 02:16:22 +00:00
|
|
|
t.ctx = newEthContext()
|
|
|
|
t.ethNode = setupEthNode(t.conf, t.ctx, eth)
|
|
|
|
t.com = CommonRef.new(
|
|
|
|
memDB,
|
|
|
|
conf,
|
|
|
|
t.conf.pruneMode == PruneMode.Full
|
|
|
|
)
|
2023-10-05 03:04:12 +00:00
|
|
|
t.chainRef = newChain(t.com, extraValidation = true)
|
2023-07-09 02:16:22 +00:00
|
|
|
let
|
|
|
|
stateDB = AccountsCache.init(memDB, emptyRlpHash, t.conf.pruneMode == PruneMode.Full)
|
|
|
|
genesisHeader = node.genesisHeader
|
|
|
|
|
|
|
|
setupStateDB(node["pre"], stateDB)
|
|
|
|
stateDB.persist()
|
|
|
|
|
|
|
|
doAssert stateDB.rootHash == genesisHeader.stateRoot
|
|
|
|
|
|
|
|
discard t.com.db.persistHeaderToDb(genesisHeader,
|
|
|
|
t.com.consensus == ConsensusType.POS)
|
|
|
|
doAssert(t.com.db.getCanonicalHead().blockHash == genesisHeader.blockHash)
|
|
|
|
|
|
|
|
let txPool = TxPoolRef.new(t.com, engineSigner)
|
2023-07-24 14:50:39 +00:00
|
|
|
t.rpcServer = newRpcHttpServer(["127.0.0.1:8545"])
|
2023-07-09 02:16:22 +00:00
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
let beaconEngine = BeaconEngineRef.new(txPool, t.chainRef)
|
2023-07-09 02:16:22 +00:00
|
|
|
setupEthRpc(t.ethNode, t.ctx, t.com, txPool, t.rpcServer)
|
2023-08-27 01:23:45 +00:00
|
|
|
setupEngineAPI(beaconEngine, t.rpcServer)
|
2023-07-09 02:16:22 +00:00
|
|
|
|
|
|
|
t.rpcServer.start()
|
|
|
|
|
|
|
|
t.rpcClient = newRpcHttpClient()
|
2023-07-24 14:50:39 +00:00
|
|
|
waitFor t.rpcClient.connect("127.0.0.1", 8545.Port, false)
|
2023-07-09 02:16:22 +00:00
|
|
|
|
|
|
|
proc stopELClient*(t: TestEnv) =
|
|
|
|
waitFor t.rpcClient.close()
|
|
|
|
waitFor t.rpcServer.closeWait()
|