mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-24 00:48:12 +00:00
Re-added malformed json error
This commit is contained in:
parent
9945228bf0
commit
a79351cbd7
@ -19,12 +19,6 @@ proc testMissingRpc: Future[Response] {.async.} =
|
|||||||
var fut = client.call("phantomRpc", %[])
|
var fut = client.call("phantomRpc", %[])
|
||||||
result = await fut
|
result = await fut
|
||||||
|
|
||||||
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.} =
|
proc testInvalidJsonVer: Future[Response] {.async.} =
|
||||||
let json =
|
let json =
|
||||||
$ %{"jsonrpc": %"3.99", "method": %"rpc", "params": %[],
|
$ %{"jsonrpc": %"3.99", "method": %"rpc", "params": %[],
|
||||||
@ -32,24 +26,29 @@ proc testInvalidJsonVer: Future[Response] {.async.} =
|
|||||||
var fut = client.rawCall("rpc", json)
|
var fut = client.rawCall("rpc", json)
|
||||||
result = await fut
|
result = await fut
|
||||||
|
|
||||||
|
proc testMalformed: Future[Response] {.async.} =
|
||||||
|
let malformedJson = "{field: 2, \"field: 3}"
|
||||||
|
var fut = client.rawCall("rpc", malformedJson)
|
||||||
|
await fut or sleepAsync(1000)
|
||||||
|
if fut.finished: result = fut.read()
|
||||||
|
else: result = (true, %"Timeout")
|
||||||
|
|
||||||
suite "RPC Errors":
|
suite "RPC Errors":
|
||||||
|
# Note: We don't expect a exceptions for most of the tests,
|
||||||
|
# because the server should respond with the error in json
|
||||||
test "Missing RPC":
|
test "Missing RPC":
|
||||||
let res = waitFor testMissingRpc()
|
let res = waitFor testMissingRpc()
|
||||||
echo res
|
|
||||||
check res.error == true and
|
check res.error == true and
|
||||||
res.result["message"] == %"Method not found" and
|
res.result["message"] == %"Method not found" and
|
||||||
res.result["data"] == %"phantomRpc is not a registered method."
|
res.result["data"] == %"phantomRpc is not a registered method."
|
||||||
|
|
||||||
test "Incorrect json version":
|
test "Incorrect json version":
|
||||||
# Note: We don't expect an exception here, because the server should
|
|
||||||
# respond with the correct json version
|
|
||||||
let res = waitFor testInvalidJsonVer()
|
let res = waitFor testInvalidJsonVer()
|
||||||
check res.error == true and res.result["message"] == %"JSON 2.0 required"
|
check res.error == true and res.result["message"] == %"JSON 2.0 required"
|
||||||
|
|
||||||
# TODO: Missing ID causes client await to not return next call
|
test "Malformed json":
|
||||||
# For now we can use curl for this test
|
# TODO: We time out here because the server won't be able to
|
||||||
#[test "Malformed json":
|
# find an id to return to us, so we cannot complete the future.
|
||||||
expect ValueError:
|
let res = waitFor testMalformed()
|
||||||
let res = waitFor testMalformed()
|
check res.error == true and res.result == %"Timeout"
|
||||||
echo res
|
|
||||||
]#
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user