Fix, improve and activate rpc test

This commit is contained in:
kdeme 2019-04-24 22:45:29 +02:00
parent 28dfaad588
commit 7ab84641d6
4 changed files with 51 additions and 46 deletions

View File

@ -34,6 +34,7 @@ proc test(name: string, lang = "c") =
task test, "Run tests": task test, "Run tests":
test "all_tests" test "all_tests"
test "test_rpc" test "test_rpc"
test "test_rpc_whisper"
task nimbus, "Build Nimbus": task nimbus, "Build Nimbus":
buildBinary "nimbus", "nimbus/", "-d:chronicles_log_level=TRACE" buildBinary "nimbus", "nimbus/", "-d:chronicles_log_level=TRACE"

View File

@ -7,10 +7,9 @@
import import
os, macros, json, strformat, strutils, parseutils, ospaths, tables, os, macros, json, strformat, strutils, parseutils, ospaths, tables,
byteutils, eth/[common, keys, rlp], ranges/typedranges, byteutils, ranges/typedranges, net, eth/[common, keys, rlp, p2p],
../nimbus/[vm_state, constants], ../nimbus/[vm_state, constants, config, transaction, utils],
../nimbus/db/[db_chain, state_db], ../nimbus/db/[db_chain, state_db],
../nimbus/[transaction, utils],
../nimbus/vm/interpreter/[gas_costs, vm_forks], ../nimbus/vm/interpreter/[gas_costs, vm_forks],
../tests/test_generalstate_failing ../tests/test_generalstate_failing
@ -293,3 +292,19 @@ proc getFixtureTransaction*(j: JsonNode, dataIndex, gasIndex, valueIndex: int):
proc hashLogEntries*(logs: seq[Log]): string = proc hashLogEntries*(logs: seq[Log]): string =
toLowerAscii("0x" & $keccakHash(rlp.encode(logs))) toLowerAscii("0x" & $keccakHash(rlp.encode(logs)))
proc setupEthNode*(capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode =
var
conf = getConfiguration()
keypair: KeyPair
keypair.seckey = conf.net.nodekey
keypair.pubkey = conf.net.nodekey.getPublicKey()
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", addAllCapabilities = false)
for capability in capabilities:
result.addCapability capability

View File

@ -6,16 +6,16 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
unittest, json, strformat, options, unittest, json, strformat, options, nimcrypto, byteutils,
nimcrypto, eth/[rlp, keys], eth/trie/db, eth/p2p as eth_p2p, json_rpc/[rpcserver, rpcclient], eth/common as eth_common,
json_rpc/[rpcserver, rpcclient], eth/[rlp, keys], eth/trie/db, eth/p2p/rlpx_protocols/eth_protocol,
../nimbus/rpc/[common, p2p, hexstrings, rpc_types], ../nimbus/rpc/[common, p2p, hexstrings, rpc_types],
../nimbus/constants, ../nimbus/[constants, vm_state, config, genesis],
../nimbus/[vm_state, config], ../nimbus/db/[state_db, db_chain, storage_types],
../nimbus/db/[state_db, db_chain, storage_types], eth/common as eth_common, byteutils,
../nimbus/p2p/chain, ../nimbus/p2p/chain,
../nimbus/genesis, ./rpcclient/test_hexstrings, ./test_helpers
./rpcclient/test_hexstrings
from eth/p2p/rlpx_protocols/whisper_protocol import SymKey
# Perform checks for hex string validation # Perform checks for hex string validation
doHexStrTests() doHexStrTests()
@ -29,26 +29,12 @@ template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
const sigPath = &"{sourceDir}{DirSep}rpcclient{DirSep}ethcallsigs.nim" const sigPath = &"{sourceDir}{DirSep}rpcclient{DirSep}ethcallsigs.nim"
createRpcSigs(RpcSocketClient, sigPath) createRpcSigs(RpcSocketClient, sigPath)
proc setupEthNode: EthereumNode =
var
conf = getConfiguration()
keypair: KeyPair
keypair.seckey = conf.net.nodekey
keypair.pubkey = conf.net.nodekey.getPublicKey()
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")
proc toEthAddressStr(address: EthAddress): EthAddressStr = proc toEthAddressStr(address: EthAddress): EthAddressStr =
result = ("0x" & address.toHex).ethAddressStr result = ("0x" & address.toHex).ethAddressStr
proc doTests = proc doTests =
# TODO: Include other transports such as Http # TODO: Include other transports such as Http
var ethNode = setupEthNode() var ethNode = setupEthNode(eth)
let let
emptyRlpHash = keccak256.digest(rlp.encode("")) emptyRlpHash = keccak256.digest(rlp.encode(""))
header = BlockHeader(stateRoot: emptyRlpHash) header = BlockHeader(stateRoot: emptyRlpHash)

View File

@ -1,8 +1,7 @@
import import
unittest, strformat, options, byteutils, json_rpc/[rpcserver, rpcclient], unittest, strformat, options, byteutils, json_rpc/[rpcserver, rpcclient],
eth/common as eth_common, eth/p2p as eth_p2p, eth/common as eth_common, eth/[rlp, keys], eth/p2p/rlpx_protocols/whisper_protocol,
eth/[rlp, keys], eth/p2p/rlpx_protocols/whisper_protocol, ../nimbus/rpc/[common, hexstrings, rpc_types, whisper], ./test_helpers
../nimbus/rpc/[common, hexstrings, rpc_types, whisper], ../nimbus/config
from os import DirSep from os import DirSep
from strutils import rsplit from strutils import rsplit
@ -13,23 +12,8 @@ template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
const sigPath = &"{sourceDir}{DirSep}rpcclient{DirSep}ethcallsigs.nim" const sigPath = &"{sourceDir}{DirSep}rpcclient{DirSep}ethcallsigs.nim"
createRpcSigs(RpcSocketClient, sigPath) createRpcSigs(RpcSocketClient, sigPath)
proc setupEthNode: EthereumNode =
var
conf = getConfiguration()
keypair: KeyPair
keypair.seckey = conf.net.nodekey
keypair.pubkey = conf.net.nodekey.getPublicKey()
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", addAllCapabilities = false)
result.addCapability Whisper
proc doTests = proc doTests =
var ethNode = setupEthNode() var ethNode = setupEthNode(Whisper)
# Create Ethereum RPCs # Create Ethereum RPCs
let RPC_PORT = 8545 let RPC_PORT = 8545
@ -37,7 +21,6 @@ proc doTests =
rpcServer = newRpcSocketServer(["localhost:" & $RPC_PORT]) rpcServer = newRpcSocketServer(["localhost:" & $RPC_PORT])
client = newRpcSocketClient() client = newRpcSocketClient()
let keys = newWhisperKeys() let keys = newWhisperKeys()
setupCommonRPC(rpcServer)
setupWhisperRPC(ethNode, keys, rpcServer) setupWhisperRPC(ethNode, keys, rpcServer)
# Begin tests # Begin tests
@ -128,6 +111,20 @@ proc doTests =
powTarget = 0.001 powTarget = 0.001
powTime = 1.0 powTime = 1.0
test "shh filter create and delete":
let
topic = topicStr.toTopic()
symKeyID = waitFor client.shh_newSymKey()
options = WhisperFilterOptions(symKeyID: some(symKeyID),
topics: some(@[topic]))
filterID = waitFor client.shh_newMessageFilter(options)
check:
filterID.string.isValidIdentifier
waitFor(client.shh_deleteMessageFilter(filterID))
expect Exception:
discard waitFor(client.shh_deleteMessageFilter(filterID))
test "shh symKey post and filter loop": test "shh symKey post and filter loop":
let let
topic = topicStr.toTopic() topic = topicStr.toTopic()
@ -156,6 +153,8 @@ proc doTests =
messages[0].padding.len > 0 messages[0].padding.len > 0
messages[0].pow >= powTarget messages[0].pow >= powTarget
waitFor(client.shh_deleteMessageFilter(filterID))
test "shh asymKey post and filter loop": test "shh asymKey post and filter loop":
let let
topic = topicStr.toTopic() topic = topicStr.toTopic()
@ -184,6 +183,8 @@ proc doTests =
messages[0].padding.len > 0 messages[0].padding.len > 0
messages[0].pow >= powTarget messages[0].pow >= powTarget
waitFor(client.shh_deleteMessageFilter(filterID))
test "shh signature in post and filter loop": test "shh signature in post and filter loop":
let let
topic = topicStr.toTopic() topic = topicStr.toTopic()
@ -216,6 +217,8 @@ proc doTests =
messages[0].padding.len > 0 messages[0].padding.len > 0
messages[0].pow >= powTarget messages[0].pow >= powTarget
waitFor(client.shh_deleteMessageFilter(filterID))
rpcServer.stop() rpcServer.stop()
rpcServer.close() rpcServer.close()