Add tests for JSON RPC hex strings
This commit is contained in:
parent
d4571c01dd
commit
c5514155ee
|
@ -0,0 +1,67 @@
|
|||
# Separated from main tests for brevity
|
||||
|
||||
import unittest, ../../nimbus/rpc/hexstrings, json
|
||||
|
||||
proc doHexStrTests* =
|
||||
suite "Hex quantity":
|
||||
test "Empty string":
|
||||
expect ValueError:
|
||||
let
|
||||
source = ""
|
||||
x = hexQuantityStr source
|
||||
check %x == %source
|
||||
test "Even length":
|
||||
let
|
||||
source = "0x123"
|
||||
x = hexQuantityStr source
|
||||
check %x == %source
|
||||
test "Odd length":
|
||||
let
|
||||
source = "0x123"
|
||||
x = hexQuantityStr"0x123"
|
||||
check %x == %source
|
||||
test "Missing header":
|
||||
expect ValueError:
|
||||
let
|
||||
source = "1234"
|
||||
x = hexQuantityStr source
|
||||
check %x != %source
|
||||
expect ValueError:
|
||||
let
|
||||
source = "01234"
|
||||
x = hexQuantityStr source
|
||||
check %x != %source
|
||||
expect ValueError:
|
||||
let
|
||||
source = "x1234"
|
||||
x = hexQuantityStr source
|
||||
check %x != %source
|
||||
|
||||
suite "Hex data":
|
||||
test "Even length":
|
||||
let
|
||||
source = "0x1234"
|
||||
x = hexDataStr source
|
||||
check %x == %source
|
||||
test "Odd length":
|
||||
expect ValueError:
|
||||
let
|
||||
source = "0x123"
|
||||
x = hexDataStr source
|
||||
check %x != %source
|
||||
test "Missing header":
|
||||
expect ValueError:
|
||||
let
|
||||
source = "1234"
|
||||
x = hexDataStr source
|
||||
check %x != %source
|
||||
expect ValueError:
|
||||
let
|
||||
source = "01234"
|
||||
x = hexDataStr source
|
||||
check %x != %source
|
||||
expect ValueError:
|
||||
let
|
||||
source = "x1234"
|
||||
x = hexDataStr source
|
||||
check %x != %source
|
|
@ -3,6 +3,9 @@ import
|
|||
json_rpc/[rpcserver, rpcclient],
|
||||
../nimbus/rpc/common, ../nimbus/constants, ../nimbus/nimbus/account,
|
||||
eth_common
|
||||
import rpcclient/test_hexstrings
|
||||
|
||||
doHexStrTests()
|
||||
|
||||
from os import getCurrentDir, DirSep
|
||||
from strutils import rsplit
|
||||
|
|
Loading…
Reference in New Issue