2018-04-12 18:51:06 +01:00
|
|
|
import ../eth-rpc / rpcclient, ../eth-rpc / rpcserver,
|
2018-04-24 14:01:28 +01:00
|
|
|
asyncdispatch, json, unittest, tables
|
2018-03-02 11:46:59 +00:00
|
|
|
|
2018-04-24 13:43:04 +01:00
|
|
|
# TODO: dummy implementations of RPC calls handled in async fashion.
|
|
|
|
var srv = sharedRpcServer()
|
|
|
|
srv.address = "localhost"
|
|
|
|
srv.port = Port(8545)
|
|
|
|
|
2018-04-24 19:22:16 +01:00
|
|
|
srv.on("myProc") do(input: string, data: array[0..3, int]):
|
2018-04-12 18:51:06 +01:00
|
|
|
# Custom async RPC call
|
2018-04-24 19:22:16 +01:00
|
|
|
result = %("Hello " & input & " data: " & $data)
|
2018-04-12 18:51:06 +01:00
|
|
|
|
2018-04-12 19:29:48 +01:00
|
|
|
asyncCheck srv.serve
|
2018-04-24 13:43:04 +01:00
|
|
|
|
2018-04-24 13:50:56 +01: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-04-24 13:50:56 +01: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"
|
|
|
|
test "Custom RPC":
|
2018-04-24 19:22:16 +01:00
|
|
|
response = waitFor client.call("myProc", %[%"abc", %[1, 2, 3, 4]])
|
|
|
|
check response.result.getStr == "Hello abc data: [1, 2, 3, 4]"
|
2018-04-24 13:50:56 +01:00
|
|
|
|
2018-03-22 17:29:43 +00:00
|
|
|
|
2018-04-24 13:50:56 +01:00
|
|
|
waitFor main()
|
|
|
|
|