mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-24 08:58:18 +00:00
Updated test to use new on
macro
This commit is contained in:
parent
44439fb746
commit
364fa6f031
@ -1,19 +1,18 @@
|
|||||||
import ../eth-rpc / rpcclient, ../eth-rpc / rpcserver,
|
import ../eth-rpc / rpcclient, ../eth-rpc / rpcserver,
|
||||||
asyncdispatch, json, unittest, tables
|
asyncdispatch, json, unittest, tables, ../eth-rpc / server / ethprocs
|
||||||
|
|
||||||
# REVIEW: I'd like to see some dummy implementations of RPC calls handled in async fashion.
|
# TODO: dummy implementations of RPC calls handled in async fashion.
|
||||||
proc myProc* {.rpc.} =
|
var srv = sharedRpcServer()
|
||||||
|
srv.address = "localhost"
|
||||||
|
srv.port = Port(8545)
|
||||||
|
|
||||||
|
srv.on("myProc") do(input: string):
|
||||||
# Custom async RPC call
|
# Custom async RPC call
|
||||||
return %"Hello"
|
result = %("Hello " & input)
|
||||||
|
|
||||||
var srv = newRpcServer("")
|
|
||||||
# This is required to automatically register `myProc` to new servers
|
|
||||||
registerRpcs(srv)
|
|
||||||
asyncCheck srv.serve
|
asyncCheck srv.serve
|
||||||
# TODO: Avoid having to add procs twice, once for the ethprocs in newRpcServer,
|
|
||||||
# and again with the extra `myProc` rpc
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
# create on localhost, default port
|
|
||||||
suite "RPC":
|
suite "RPC":
|
||||||
proc main {.async.} =
|
proc main {.async.} =
|
||||||
var client = newRpcClient()
|
var client = newRpcClient()
|
||||||
@ -24,11 +23,11 @@ when isMainModule:
|
|||||||
response = waitFor client.web3_clientVersion(newJNull())
|
response = waitFor client.web3_clientVersion(newJNull())
|
||||||
check response.result == %"Nimbus-RPC-Test"
|
check response.result == %"Nimbus-RPC-Test"
|
||||||
test "SHA3":
|
test "SHA3":
|
||||||
response = waitFor client.web3_sha3(%"abc")
|
response = waitFor client.web3_sha3(%["abc"])
|
||||||
check response.result.getStr == "3A985DA74FE225B2045C172D6BD390BD855F086E3E9D525B46BFE24511431532"
|
check response.result.getStr == "3A985DA74FE225B2045C172D6BD390BD855F086E3E9D525B46BFE24511431532"
|
||||||
test "Custom RPC":
|
test "Custom RPC":
|
||||||
response = waitFor client.call("myProc", %"abc")
|
response = waitFor client.call("myProc", %["abc"])
|
||||||
check response.result.getStr == "Hello"
|
check response.result.getStr == "Hello abc"
|
||||||
|
|
||||||
|
|
||||||
waitFor main()
|
waitFor main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user