2021-11-14 14:52:22 +07:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
|
|
|
import
|
2022-04-20 14:57:50 +07:00
|
|
|
std/[os, times],
|
2021-11-14 14:52:22 +07:00
|
|
|
eth/[trie/db],
|
2022-04-20 14:57:50 +07:00
|
|
|
eth/p2p as ethp2p,
|
2021-11-14 14:52:22 +07:00
|
|
|
stew/shims/net as stewNet,
|
|
|
|
stew/results,
|
|
|
|
chronos, json_rpc/[rpcserver, rpcclient],
|
|
|
|
../../../nimbus/db/db_chain,
|
2022-04-20 14:57:50 +07:00
|
|
|
../../../nimbus/sync/protocol_ethxx,
|
|
|
|
../../../nimbus/[config, context, genesis, utils/tx_pool],
|
2021-11-14 14:52:22 +07:00
|
|
|
../../../nimbus/rpc/[common, p2p, debug],
|
|
|
|
../../../tests/test_helpers,
|
2022-04-20 14:57:50 +07:00
|
|
|
"."/[ethclient, vault, client],
|
|
|
|
../sim_utils
|
2021-11-14 14:52:22 +07:00
|
|
|
|
|
|
|
const
|
|
|
|
initPath = "hive_integration" / "nodocker" / "rpc" / "init"
|
|
|
|
|
|
|
|
proc manageAccounts(ctx: EthContext, conf: NimbusConf) =
|
|
|
|
if string(conf.importKey).len > 0:
|
|
|
|
let res = ctx.am.importPrivateKey(string conf.importKey)
|
|
|
|
if res.isErr:
|
|
|
|
echo res.error()
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
2022-04-20 14:57:50 +07:00
|
|
|
proc setupRpcServer(ctx: EthContext, chainDB: BaseChainDB,
|
|
|
|
ethNode: EthereumNode, txPool: TxPoolRef,
|
|
|
|
conf: NimbusConf): RpcServer =
|
2021-11-14 14:52:22 +07:00
|
|
|
let rpcServer = newRpcHttpServer([initTAddress(conf.rpcAddress, conf.rpcPort)])
|
|
|
|
setupCommonRpc(ethNode, conf, rpcServer)
|
2022-04-20 14:57:50 +07:00
|
|
|
setupEthRpc(ethNode, ctx, chainDB, txPool, rpcServer)
|
2021-11-14 14:52:22 +07:00
|
|
|
|
|
|
|
rpcServer.start()
|
|
|
|
rpcServer
|
|
|
|
|
2022-04-20 14:57:50 +07:00
|
|
|
proc setupWsRpcServer(ctx: EthContext, chainDB: BaseChainDB,
|
|
|
|
ethNode: EthereumNode, txPool: TxPoolRef,
|
|
|
|
conf: NimbusConf): RpcServer =
|
2021-11-14 14:52:22 +07:00
|
|
|
let rpcServer = newRpcWebSocketServer(initTAddress(conf.wsAddress, conf.wsPort))
|
|
|
|
setupCommonRpc(ethNode, conf, rpcServer)
|
2022-04-20 14:57:50 +07:00
|
|
|
setupEthRpc(ethNode, ctx, chainDB, txPool, rpcServer)
|
2021-11-14 14:52:22 +07:00
|
|
|
|
|
|
|
rpcServer.start()
|
|
|
|
rpcServer
|
|
|
|
|
|
|
|
proc runRpcTest() =
|
|
|
|
let client = newRpcHttpClient()
|
|
|
|
waitFor client.connect("127.0.0.1", Port(8545), false)
|
|
|
|
|
|
|
|
let testEnv = TestEnv(
|
|
|
|
client: client,
|
|
|
|
vault : newVault(chainID, gasPrice, client)
|
|
|
|
)
|
|
|
|
|
2022-04-20 14:57:50 +07:00
|
|
|
var stat: SimStat
|
|
|
|
let start = getTime()
|
|
|
|
for x in testList:
|
|
|
|
try:
|
|
|
|
let status = waitFor x.run(testEnv)
|
|
|
|
stat.inc(x.name, status)
|
|
|
|
except ValueError as ex:
|
|
|
|
stat.inc(x.name, TestStatus.Failed)
|
|
|
|
echo ex.msg
|
|
|
|
|
|
|
|
let elpd = getTime() - start
|
|
|
|
print(stat, elpd, "rpc")
|
|
|
|
|
2021-11-14 14:52:22 +07:00
|
|
|
proc main() =
|
|
|
|
let conf = makeConfig(@[
|
|
|
|
"--prune-mode:archive",
|
|
|
|
# "--nat:extip:0.0.0.0",
|
|
|
|
"--network:7",
|
|
|
|
"--import-key:" & initPath / "private-key",
|
|
|
|
"--engine-signer:658bdf435d810c91414ec09147daa6db62406379",
|
|
|
|
"--custom-network:" & initPath / "genesis.json",
|
|
|
|
"--rpc",
|
|
|
|
"--rpc-api:eth,debug",
|
|
|
|
# "--rpc-address:0.0.0.0",
|
|
|
|
"--rpc-port:8545",
|
|
|
|
"--ws",
|
|
|
|
"--ws-api:eth,debug",
|
|
|
|
# "--ws-address:0.0.0.0",
|
|
|
|
"--ws-port:8546"
|
|
|
|
])
|
|
|
|
|
|
|
|
let
|
|
|
|
ethCtx = newEthContext()
|
|
|
|
ethNode = setupEthNode(conf, ethCtx, eth)
|
|
|
|
chainDB = newBaseChainDB(newMemoryDb(),
|
|
|
|
conf.pruneMode == PruneMode.Full,
|
|
|
|
conf.networkId,
|
|
|
|
conf.networkParams
|
|
|
|
)
|
|
|
|
|
|
|
|
chainDB.populateProgress()
|
|
|
|
chainDB.initializeEmptyDb()
|
2022-04-20 14:57:50 +07:00
|
|
|
|
|
|
|
let txPool = TxPoolRef.new(chainDB, conf.engineSigner)
|
|
|
|
let rpcServer = setupRpcServer(ethCtx, chainDB, ethNode, txPool, conf)
|
2021-11-14 14:52:22 +07:00
|
|
|
runRpcTest()
|
|
|
|
|
|
|
|
main()
|