2018-04-11 20:08:48 +01:00
|
|
|
import ../eth-rpc / rpcclient, ../eth-rpc / rpcserver, asyncdispatch, json, unittest, ../eth-rpc/server/ethprocs
|
2018-03-02 11:46:59 +00:00
|
|
|
|
2018-04-11 15:34:49 +03:00
|
|
|
# REVIEW: I'd like to see some dummy implementations of RPC calls handled in async fashion.
|
2018-04-11 20:08:48 +01:00
|
|
|
proc myProc {.rpc.} =
|
|
|
|
return %"hello"
|
2018-04-11 15:34:49 +03:00
|
|
|
|
2018-03-02 11:46:59 +00:00
|
|
|
when isMainModule:
|
2018-04-10 18:41:12 +01:00
|
|
|
# create on localhost, default port
|
|
|
|
var srv = newRpcServer("")
|
2018-04-11 20:08:48 +01:00
|
|
|
registerEthereumRpcs(srv)
|
2018-04-10 18:41:12 +01:00
|
|
|
asyncCheck srv.serve()
|
|
|
|
|
2018-03-22 17:29:43 +00:00
|
|
|
suite "RPC":
|
|
|
|
proc main {.async.} =
|
|
|
|
var client = newRpcClient()
|
|
|
|
await client.connect("localhost", Port(8545))
|
|
|
|
var response: Response
|
2018-03-02 11:46:59 +00:00
|
|
|
|
2018-03-22 17:29:43 +00:00
|
|
|
test "Version":
|
|
|
|
response = waitFor client.web3_clientVersion(newJNull())
|
|
|
|
check response.result == %"Nimbus-RPC-Test"
|
|
|
|
test "SHA3":
|
|
|
|
response = waitFor client.web3_sha3(%"abc")
|
|
|
|
check response.result.getStr == "3A985DA74FE225B2045C172D6BD390BD855F086E3E9D525B46BFE24511431532"
|
2018-04-11 20:08:48 +01:00
|
|
|
response = waitFor client.call("myProc", %"abc")
|
|
|
|
echo response.result.getStr
|
|
|
|
|
2018-03-22 17:29:43 +00:00
|
|
|
|
|
|
|
waitFor main()
|