Split tests into client-server test and ethprocs test

This commit is contained in:
coffeepots 2018-05-29 21:58:27 +01:00
parent 5292b0b53e
commit f38dcebe34
3 changed files with 38 additions and 20 deletions

View File

@ -1,3 +1,3 @@
import
testrpcmacro, testserverclient
testrpcmacro, testserverclient, testethcalls

32
tests/testethcalls.nim Normal file
View File

@ -0,0 +1,32 @@
import ../ rpcclient, ../ rpcserver
import unittest, asyncdispatch, json, tables
from os import getCurrentDir, DirSep
from strutils import rsplit
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
var srv = sharedRpcServer()
srv.address = "localhost"
srv.port = Port(8546)
# importing ethprocs creates the server rpc calls
import stint, ethtypes, ethprocs
# generate all client ethereum rpc calls
createRpcSigs(sourceDir & DirSep & "ethcallsigs.nim")
asyncCheck srv.serve
suite "Ethereum RPCs":
proc main {.async.} =
var client = newRpcClient()
await client.connect("localhost", Port(8546))
test "Version":
var
response = waitFor client.web3_clientVersion()
check response == "Nimbus-RPC-Test"
test "SHA3":
var response = waitFor client.web3_sha3("0x68656c6c6f20776f726c64")
check response == "0x47173285A8D7341E5E972FC677286384F802F8EF42A5EC5F03BBFA254CB01FAD"
waitFor main()

View File

@ -1,39 +1,25 @@
import ../ rpcclient, ../ rpcserver
import unittest, asyncdispatch, json, tables
from os import getCurrentDir, DirSep
from strutils import rsplit
import unittest, asyncdispatch, json
# TODO: dummy implementations of RPC calls handled in async fashion.
# TODO: check required json parameters like version are being raised
var srv = sharedRpcServer()
var srv = newRpcServer()
srv.address = "localhost"
srv.port = Port(8545)
import stint, ethtypes, ethprocs
# generate all client ethereum rpc calls
createRpcSigs(currentSourcePath.rsplit(DirSep, 1)[0] & DirSep & "ethcallsigs.nim")
srv.rpc("myProc") do(input: string, data: array[0..3, int]):
result = %("Hello " & input & " data: " & $data)
asyncCheck srv.serve
suite "RPC":
suite "Server/Client 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("0x68656c6c6f20776f726c64")
check response == "0x47173285A8D7341E5E972FC677286384F802F8EF42A5EC5F03BBFA254CB01FAD"
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
# TODO: When an error occurs during a test, stop the server
asyncCheck main()