mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-24 17:08:17 +00:00
38 lines
1.4 KiB
Nim
38 lines
1.4 KiB
Nim
import ../ rpcclient, ../ rpcserver, unittest, asyncdispatch, json, tables
|
|
|
|
#[
|
|
TODO: Importing client before server causes the error:
|
|
Error: undeclared identifier: 'result' for the `myProc` RPC.
|
|
This is because the RPC procs created by clientdispatch clash with ethprocs.
|
|
Currently, easiest solution is to import rpcserver (and therefore generate
|
|
ethprocs) before rpcclient.
|
|
]#
|
|
# TODO: dummy implementations of RPC calls handled in async fashion.
|
|
# TODO: check required json parameters like version are being raised
|
|
var srv = sharedRpcServer()
|
|
srv.address = "localhost"
|
|
srv.port = Port(8545)
|
|
|
|
srv.rpc("myProc") do(input: string, data: array[0..3, int]):
|
|
result = %("Hello " & input & " data: " & $data)
|
|
|
|
asyncCheck srv.serve
|
|
|
|
suite "RPC":
|
|
proc main {.async.} =
|
|
var client = newRpcClient()
|
|
await client.connect("localhost", Port(8545))
|
|
|
|
test "Version":
|
|
var response = waitFor client.web3_clientVersion()
|
|
check response == "Nimbus-RPC-Test"
|
|
test "SHA3":
|
|
var response = waitFor client.web3_sha3("abc")
|
|
check response == "3A985DA74FE225B2045C172D6BD390BD855F086E3E9D525B46BFE24511431532"
|
|
test "Custom RPC":
|
|
# Custom async RPC call
|
|
var response = waitFor client.call("myProc", %[%"abc", %[1, 2, 3, 4]])
|
|
check response.result.getStr == "Hello abc data: [1, 2, 3, 4]"
|
|
|
|
waitFor main() # TODO: When an error occurs during a test, stop the server
|
|
|