Fix, improve and activate rpc test
This commit is contained in:
parent
28dfaad588
commit
7ab84641d6
|
@ -34,6 +34,7 @@ proc test(name: string, lang = "c") =
|
|||
task test, "Run tests":
|
||||
test "all_tests"
|
||||
test "test_rpc"
|
||||
test "test_rpc_whisper"
|
||||
|
||||
task nimbus, "Build Nimbus":
|
||||
buildBinary "nimbus", "nimbus/", "-d:chronicles_log_level=TRACE"
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
import
|
||||
os, macros, json, strformat, strutils, parseutils, ospaths, tables,
|
||||
byteutils, eth/[common, keys, rlp], ranges/typedranges,
|
||||
../nimbus/[vm_state, constants],
|
||||
byteutils, ranges/typedranges, net, eth/[common, keys, rlp, p2p],
|
||||
../nimbus/[vm_state, constants, config, transaction, utils],
|
||||
../nimbus/db/[db_chain, state_db],
|
||||
../nimbus/[transaction, utils],
|
||||
../nimbus/vm/interpreter/[gas_costs, vm_forks],
|
||||
../tests/test_generalstate_failing
|
||||
|
||||
|
@ -293,3 +292,19 @@ proc getFixtureTransaction*(j: JsonNode, dataIndex, gasIndex, valueIndex: int):
|
|||
|
||||
proc hashLogEntries*(logs: seq[Log]): string =
|
||||
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
|
|
@ -6,16 +6,16 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
unittest, json, strformat, options,
|
||||
nimcrypto, eth/[rlp, keys], eth/trie/db, eth/p2p as eth_p2p,
|
||||
json_rpc/[rpcserver, rpcclient],
|
||||
unittest, json, strformat, options, nimcrypto, byteutils,
|
||||
json_rpc/[rpcserver, rpcclient], eth/common as eth_common,
|
||||
eth/[rlp, keys], eth/trie/db, eth/p2p/rlpx_protocols/eth_protocol,
|
||||
../nimbus/rpc/[common, p2p, hexstrings, rpc_types],
|
||||
../nimbus/constants,
|
||||
../nimbus/[vm_state, config],
|
||||
../nimbus/db/[state_db, db_chain, storage_types], eth/common as eth_common, byteutils,
|
||||
../nimbus/[constants, vm_state, config, genesis],
|
||||
../nimbus/db/[state_db, db_chain, storage_types],
|
||||
../nimbus/p2p/chain,
|
||||
../nimbus/genesis,
|
||||
./rpcclient/test_hexstrings
|
||||
./rpcclient/test_hexstrings, ./test_helpers
|
||||
|
||||
from eth/p2p/rlpx_protocols/whisper_protocol import SymKey
|
||||
|
||||
# Perform checks for hex string validation
|
||||
doHexStrTests()
|
||||
|
@ -29,26 +29,12 @@ template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
|||
const sigPath = &"{sourceDir}{DirSep}rpcclient{DirSep}ethcallsigs.nim"
|
||||
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 =
|
||||
result = ("0x" & address.toHex).ethAddressStr
|
||||
|
||||
proc doTests =
|
||||
# TODO: Include other transports such as Http
|
||||
var ethNode = setupEthNode()
|
||||
var ethNode = setupEthNode(eth)
|
||||
let
|
||||
emptyRlpHash = keccak256.digest(rlp.encode(""))
|
||||
header = BlockHeader(stateRoot: emptyRlpHash)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import
|
||||
unittest, strformat, options, byteutils, json_rpc/[rpcserver, rpcclient],
|
||||
eth/common as eth_common, eth/p2p as eth_p2p,
|
||||
eth/[rlp, keys], eth/p2p/rlpx_protocols/whisper_protocol,
|
||||
../nimbus/rpc/[common, hexstrings, rpc_types, whisper], ../nimbus/config
|
||||
eth/common as eth_common, eth/[rlp, keys], eth/p2p/rlpx_protocols/whisper_protocol,
|
||||
../nimbus/rpc/[common, hexstrings, rpc_types, whisper], ./test_helpers
|
||||
|
||||
from os import DirSep
|
||||
from strutils import rsplit
|
||||
|
@ -13,23 +12,8 @@ template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
|||
const sigPath = &"{sourceDir}{DirSep}rpcclient{DirSep}ethcallsigs.nim"
|
||||
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 =
|
||||
var ethNode = setupEthNode()
|
||||
var ethNode = setupEthNode(Whisper)
|
||||
|
||||
# Create Ethereum RPCs
|
||||
let RPC_PORT = 8545
|
||||
|
@ -37,7 +21,6 @@ proc doTests =
|
|||
rpcServer = newRpcSocketServer(["localhost:" & $RPC_PORT])
|
||||
client = newRpcSocketClient()
|
||||
let keys = newWhisperKeys()
|
||||
setupCommonRPC(rpcServer)
|
||||
setupWhisperRPC(ethNode, keys, rpcServer)
|
||||
|
||||
# Begin tests
|
||||
|
@ -128,6 +111,20 @@ proc doTests =
|
|||
powTarget = 0.001
|
||||
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":
|
||||
let
|
||||
topic = topicStr.toTopic()
|
||||
|
@ -156,6 +153,8 @@ proc doTests =
|
|||
messages[0].padding.len > 0
|
||||
messages[0].pow >= powTarget
|
||||
|
||||
waitFor(client.shh_deleteMessageFilter(filterID))
|
||||
|
||||
test "shh asymKey post and filter loop":
|
||||
let
|
||||
topic = topicStr.toTopic()
|
||||
|
@ -184,6 +183,8 @@ proc doTests =
|
|||
messages[0].padding.len > 0
|
||||
messages[0].pow >= powTarget
|
||||
|
||||
waitFor(client.shh_deleteMessageFilter(filterID))
|
||||
|
||||
test "shh signature in post and filter loop":
|
||||
let
|
||||
topic = topicStr.toTopic()
|
||||
|
@ -216,6 +217,8 @@ proc doTests =
|
|||
messages[0].padding.len > 0
|
||||
messages[0].pow >= powTarget
|
||||
|
||||
waitFor(client.shh_deleteMessageFilter(filterID))
|
||||
|
||||
rpcServer.stop()
|
||||
rpcServer.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue