WIP tests for errors

This commit is contained in:
coffeepots 2018-06-11 19:26:16 +01:00
parent f9d20db511
commit 4c38164688
2 changed files with 43 additions and 0 deletions

18
tests/debugclient.nim Normal file
View File

@ -0,0 +1,18 @@
include ../ eth-rpc / client
import chronicles
proc rawCall*(self: RpcClient, name: string,
msg: string): Future[Response] {.async.} =
# For debug purposes only
let id = $self.nextId
self.nextId.inc
debug "Sending message", msg = msg
let res = await self.transp.write(msg & "\c\l")
debug "Receiving length assert", value = res, length = len(msg), lengthDifferent = res != len(msg)
# completed by processMessage.
var newFut = newFuture[Response]()
# add to awaiting responses
self.awaiting[id] = newFut
result = await newFut

25
tests/testerrors.nim Normal file
View File

@ -0,0 +1,25 @@
#[
This module uses debug versions of the rpc components that
allow unchecked and unformatted calls.
]#
import unittest, debugclient, ../rpcserver
import strformat, chronicles
var server = newRpcServer("localhost", 8547.Port)
var client = newRpcClient()
server.start()
waitFor client.connect("localhost", Port(8547))
server.rpc("rpc") do(a: int, b: int):
result = %(&"a: {a}, b: {b}")
suite "RPC Errors":
test "Malformed json":
expect ValueError:
let
malformedJson = "{field: 2, \"field: 3}\n"
res = waitFor client.rawCall("rpc", malformedJson)
info "res", res