Add tests for stint return values and parameters

This commit is contained in:
coffeepots 2018-05-17 19:14:31 +01:00 committed by zah
parent 995f268ddf
commit df83872a74

View File

@ -1,4 +1,4 @@
import unittest, ../ rpcserver, asyncdispatch, json, tables
import unittest, ../ rpcserver, asyncdispatch, json, tables, stint
type
# some nested types to check object parsing
@ -51,6 +51,10 @@ s.on("rpc.seqparam") do(a: string, s: seq[int]):
s.on("rpc.objparam") do(a: string, obj: MyObject):
result = %obj
s.on("rpc.uint256param") do(i: UInt256):
let r = i + 1.stUint(256)
result = %r
s.on("rpc.returntypesimple") do(i: int) -> int:
result = i
@ -61,6 +65,10 @@ s.on("rpc.returntypecomplex") do(i: int) -> Test2:
s.on("rpc.testreturns") do() -> int:
return 1234
s.on("rpc.testreturnuint256") do() -> UInt256:
let r: UInt256 = "0x1234567890abcdef".parse(UInt256, 16)
return r
# Tests
suite "Server types":
@ -100,6 +108,10 @@ suite "Server types":
let r = waitfor rpcObjParam(%[%"abc", testObj])
check r == testObj
test "UInt256 param":
let r = waitFor rpcUInt256Param(%[%"0x1234567890"])
check r == %"0x1234567891"
test "Simple return types":
let
inp = %99
@ -116,6 +128,10 @@ suite "Server types":
let r = waitFor rpcTestReturns(%[])
check r == %1234
test "Return UInt256":
let r = waitFor rpcTestReturnUInt256(%[])
check r == %"0x1234567890abcdef"
test "Runtime errors":
expect ValueError:
# root param not array