mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-09 17:13:11 +00:00
* fixes * fix https://github.com/status-im/nimbus-eth2/issues/1650 * only one of `result` and `error` allowed in response * fix invalid `string` instances being created from byte sequences * fix large int64 parsing on 32-bit * fix exception inheritance * fix some dangling results * some cleanups * annotate exception issues, fix cancellation * more error handling cleanup * add rudimentary error tests * cleanups * simplify init * use nextId -> lastId to avoid =1 init * remove obsolete tests
33 lines
946 B
Nim
33 lines
946 B
Nim
import
|
|
unittest, json, chronicles,
|
|
../json_rpc/[rpcclient, rpcserver]
|
|
|
|
var srv = newRpcSocketServer(["localhost:8545"])
|
|
var client = newRpcSocketClient()
|
|
|
|
# Create RPC on server
|
|
srv.rpc("myProc") do(input: string, data: array[0..3, int]):
|
|
return %("Hello " & input & " data: " & $data)
|
|
|
|
srv.rpc("myError") do(input: string, data: array[0..3, int]):
|
|
raise (ref ValueError)(msg: "someMessage")
|
|
|
|
srv.start()
|
|
waitFor client.connect("localhost", Port(8545))
|
|
|
|
suite "Server/Client RPC":
|
|
test "Successful RPC call":
|
|
let r = waitFor client.call("myProc", %[%"abc", %[1, 2, 3, 4]])
|
|
check r.getStr == "Hello abc data: [1, 2, 3, 4]"
|
|
|
|
test "Missing params":
|
|
expect(CatchableError):
|
|
discard waitFor client.call("myProc", %[%"abc"])
|
|
|
|
test "Error RPC call":
|
|
expect(CatchableError): # The error type wont be translated
|
|
discard waitFor client.call("myError", %[%"abc", %[1, 2, 3, 4]])
|
|
|
|
srv.stop()
|
|
waitFor srv.closeWait()
|