mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-08 08:33:14 +00:00
Improve tests, add check for invalid json
This commit is contained in:
parent
4143c2cc41
commit
6701fc7723
@ -15,18 +15,34 @@ waitFor client.connect("localhost", Port(8547))
|
||||
server.rpc("rpc") do(a: int, b: int):
|
||||
result = %(&"a: {a}, b: {b}")
|
||||
|
||||
proc testMalformed: Future[Response] =
|
||||
let malformedJson = "{field: 2, \"field: 3}\n"
|
||||
result = client.rawCall("rpc", malformedJson)
|
||||
proc testMissingRpc: Future[Response] {.async.} =
|
||||
var fut = client.call("phantomRpc", %[])
|
||||
result = await fut
|
||||
|
||||
proc testMissingRpc: Future[Response] =
|
||||
result = client.call("phantomRpc", %[])
|
||||
proc testMalformed: Future[Response] {.async.} =
|
||||
let malformedJson = "{field: 2, \"field: 3}"
|
||||
var fut = client.rawCall("rpc", malformedJson)
|
||||
await fut or sleepAsync(10000)
|
||||
if fut.finished: result = fut.read()
|
||||
|
||||
proc testInvalidJsonVer: Future[Response] {.async.} =
|
||||
let json =
|
||||
$ %{"jsonrpc": %"3.99", "method": %"rpc", "params": %[],
|
||||
"id": % $client.nextId} & "\c\l"
|
||||
var fut = client.rawCall("rpc", json)
|
||||
result = await fut
|
||||
|
||||
suite "RPC Errors":
|
||||
test "Malformed json":
|
||||
test "Missing RPC":
|
||||
let res = waitfor testMissingRpc()
|
||||
|
||||
test "Incorrect json version":
|
||||
let res = waitFor testInvalidJsonVer()
|
||||
|
||||
# TODO: Missing ID causes client await to not return next call
|
||||
# For now we can use curl for this test
|
||||
#[test "Malformed json":
|
||||
expect ValueError:
|
||||
let res = waitFor testMalformed()
|
||||
test "Missing RPC":
|
||||
let res = waitFor testMissingRpc()
|
||||
echo ">>", res
|
||||
echo "Error tests completed"
|
||||
echo res
|
||||
]#
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user