From df83872a745089298d9ea6b9e18ec3048353a9e7 Mon Sep 17 00:00:00 2001 From: coffeepots Date: Thu, 17 May 2018 19:14:31 +0100 Subject: [PATCH] Add tests for stint return values and parameters --- tests/testrpcmacro.nim | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/testrpcmacro.nim b/tests/testrpcmacro.nim index 232282b..372ab36 100644 --- a/tests/testrpcmacro.nim +++ b/tests/testrpcmacro.nim @@ -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