2020-10-06 18:36:44 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
std/[unittest, options, os, strutils],
|
|
|
|
stew/shims/net as stewNet,
|
|
|
|
json_rpc/[rpcserver, rpcclient],
|
|
|
|
libp2p/crypto/crypto,
|
2020-11-17 09:34:53 +00:00
|
|
|
../../waku/v2/node/wakunode2,
|
|
|
|
../../waku/v2/node/rpc/wakurpc,
|
|
|
|
../../waku/v2/protocol/waku_relay,
|
|
|
|
../../waku/v2/waku_types,
|
2020-10-06 18:36:44 +00:00
|
|
|
../test_helpers
|
|
|
|
|
2020-11-17 09:34:53 +00:00
|
|
|
|
2020-10-06 18:36:44 +00:00
|
|
|
template sourceDir*: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
2020-11-17 09:34:53 +00:00
|
|
|
const sigPath = sourceDir / ParDir / ParDir / "waku" / "v2" / "node" / "rpc" / "wakucallsigs.nim"
|
2020-10-06 18:36:44 +00:00
|
|
|
createRpcSigs(RpcHttpClient, sigPath)
|
|
|
|
|
|
|
|
suite "Waku v2 Remote Procedure Calls":
|
|
|
|
# WakuNode setup
|
|
|
|
let
|
|
|
|
rng = crypto.newRng()
|
|
|
|
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
|
|
|
bindIp = ValidIpAddress.init("0.0.0.0")
|
|
|
|
extIp = ValidIpAddress.init("127.0.0.1")
|
|
|
|
port = Port(9000)
|
2020-10-20 02:36:27 +00:00
|
|
|
node = WakuNode.init(privkey, bindIp, port, some(extIp), some(port))
|
2020-10-06 18:36:44 +00:00
|
|
|
|
|
|
|
waitFor node.start()
|
|
|
|
|
2020-10-20 02:36:27 +00:00
|
|
|
waitFor node.mountRelay(@["waku"])
|
|
|
|
|
2020-10-06 18:36:44 +00:00
|
|
|
# RPC server setup
|
|
|
|
let
|
|
|
|
rpcPort = Port(8545)
|
|
|
|
ta = initTAddress(bindIp, rpcPort)
|
|
|
|
server = newRpcHttpServer([ta])
|
|
|
|
|
|
|
|
setupWakuRPC(node, server)
|
|
|
|
server.start()
|
|
|
|
|
|
|
|
asyncTest "waku_info":
|
|
|
|
# RPC client setup
|
|
|
|
let client = newRpcHttpClient()
|
|
|
|
await client.connect("127.0.0.1", rpcPort)
|
|
|
|
|
|
|
|
check await(client.waku_version()) == WakuRelayCodec
|