mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
Basic eth node setup for RPC testing (WIP)
This commit is contained in:
parent
a027ca2b25
commit
155457d47f
@ -1,10 +1,15 @@
|
||||
import
|
||||
unittest, json, strformat,
|
||||
json_rpc/[rpcserver, rpcclient],
|
||||
../nimbus/rpc/common, ../nimbus/constants, ../nimbus/nimbus/account,
|
||||
eth_common
|
||||
unittest, json, strformat, nimcrypto, rlp,
|
||||
json_rpc/[rpcserver, rpcclient],
|
||||
../nimbus/rpc/[common, p2p],
|
||||
../nimbus/constants,
|
||||
../nimbus/nimbus/[account, vm_state, config],
|
||||
../nimbus/db/[state_db, db_chain], eth_common, byteutils,
|
||||
eth_trie/[memDb, types],
|
||||
eth_p2p, eth_keys
|
||||
import rpcclient/test_hexstrings
|
||||
|
||||
# Perform checks for hex string validation
|
||||
doHexStrTests()
|
||||
|
||||
from os import getCurrentDir, DirSep
|
||||
@ -12,29 +17,64 @@ from strutils import rsplit
|
||||
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
||||
|
||||
## Generate client convenience marshalling wrappers from forward declarations
|
||||
## For testing, ethcallsigs needs to be kept in sync with ../nimbus/rpc/common
|
||||
## For testing, ethcallsigs needs to be kept in sync with ../nimbus/rpc/[common, p2p]
|
||||
const sigPath = &"{sourceDir}{DirSep}rpcclient{DirSep}ethcallsigs.nim"
|
||||
createRpcSigs(RpcSocketClient, sigPath)
|
||||
|
||||
# TODO: Include other transports such as Http
|
||||
var srv = newRpcSocketServer(["localhost:8545"])
|
||||
var client = newRpcSocketClient()
|
||||
proc setupEthNode: EthereumNode =
|
||||
var
|
||||
conf = getConfiguration()
|
||||
keypair: KeyPair
|
||||
keypair.seckey = conf.net.nodekey
|
||||
keypair.pubkey = conf.net.nodekey.getPublicKey()
|
||||
|
||||
# Create Ethereum RPCs
|
||||
setupCommonRpc(srv)
|
||||
var srvAddress: Address
|
||||
srvAddress.ip = parseIpAddress("0.0.0.0")
|
||||
srvAddress.tcpPort = Port(conf.net.bindPort)
|
||||
srvAddress.udpPort = Port(conf.net.discPort)
|
||||
result = newEthereumNode(keypair, srvAddress, conf.net.networkId,
|
||||
nil, "nimbus 0.1.0")
|
||||
|
||||
srv.start()
|
||||
waitFor client.connect("localhost", Port(8545))
|
||||
proc doTests =
|
||||
# TODO: Include other transports such as Http
|
||||
var ethNode = setupEthNode()
|
||||
let
|
||||
emptyRlpHash = keccak256.digest(rlp.encode("").toOpenArray)
|
||||
header = BlockHeader(stateRoot: emptyRlpHash)
|
||||
var
|
||||
chain = newBaseChainDB(trieDB newMemDB())
|
||||
state = newBaseVMState(header, chain)
|
||||
ethNode.chain = chain
|
||||
|
||||
suite "Server/Client RPC":
|
||||
var acct = newAccount(balance = 100.u256)
|
||||
test "eth_getBalance":
|
||||
expect ValueError:
|
||||
# check error is raised on null address
|
||||
let
|
||||
blockNumStr = "1"
|
||||
address = ZERO_ADDRESS
|
||||
var r = waitFor client.eth_getBalance(address, blockNumStr)
|
||||
let balance = 100.u256
|
||||
var
|
||||
account = newAccount()
|
||||
address: EthAddress = hexToByteArray[20]("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
|
||||
state.mutateStateDB:
|
||||
db.setBalance(address, balance)
|
||||
|
||||
srv.stop()
|
||||
srv.close()
|
||||
# Create Ethereum RPCs
|
||||
var
|
||||
rpcServer = newRpcSocketServer(["localhost:8545"])
|
||||
client = newRpcSocketClient()
|
||||
setupCommonRpc(rpcServer)
|
||||
setupP2PRpc(ethNode, rpcServer)
|
||||
|
||||
# Begin tests
|
||||
rpcServer.start()
|
||||
waitFor client.connect("localhost", Port(8545))
|
||||
|
||||
suite "Server/Client RPC":
|
||||
test "eth_getBalance":
|
||||
expect ValueError:
|
||||
# check error is raised on null address
|
||||
var r = waitFor client.eth_getBalance(ZERO_ADDRESS, "0x0")
|
||||
|
||||
let blockNum = state.blockheader.blockNumber
|
||||
var r = waitFor client.eth_getBalance(address, "0x" & blockNum.toHex)
|
||||
echo r
|
||||
|
||||
rpcServer.stop()
|
||||
rpcServer.close()
|
||||
|
||||
doTests()
|
Loading…
x
Reference in New Issue
Block a user