2018-07-27 17:02:59 +00:00
|
|
|
# Separated from main tests for brevity
|
|
|
|
|
|
|
|
import unittest, ../../nimbus/rpc/hexstrings, json
|
|
|
|
|
|
|
|
proc doHexStrTests* =
|
2018-08-06 16:18:56 +00:00
|
|
|
suite "[RPC] Hex quantity":
|
2018-08-06 17:08:50 +00:00
|
|
|
test "Zero values":
|
2018-07-27 17:02:59 +00:00
|
|
|
expect ValueError:
|
|
|
|
let
|
|
|
|
source = ""
|
|
|
|
x = hexQuantityStr source
|
|
|
|
check %x == %source
|
2018-08-06 17:08:50 +00:00
|
|
|
expect ValueError:
|
|
|
|
# must have '0' for zero quantities
|
|
|
|
let
|
|
|
|
source = "0x"
|
|
|
|
x = hexQuantityStr source
|
|
|
|
check %x == %source
|
|
|
|
let
|
|
|
|
source = "0x0"
|
|
|
|
x = hexQuantityStr source
|
|
|
|
check %x == %source
|
2018-07-27 17:02:59 +00:00
|
|
|
test "Even length":
|
|
|
|
let
|
2018-08-06 17:08:50 +00:00
|
|
|
source = "0x1234"
|
2018-07-27 17:02:59 +00:00
|
|
|
x = hexQuantityStr source
|
|
|
|
check %x == %source
|
|
|
|
test "Odd length":
|
|
|
|
let
|
|
|
|
source = "0x123"
|
2018-08-06 17:08:50 +00:00
|
|
|
x = hexQuantityStr source
|
2018-07-27 17:02:59 +00:00
|
|
|
check %x == %source
|
2018-08-06 17:08:50 +00:00
|
|
|
test "\"0x\" header":
|
2018-07-27 17:02:59 +00:00
|
|
|
expect ValueError:
|
|
|
|
let
|
|
|
|
source = "1234"
|
|
|
|
x = hexQuantityStr source
|
|
|
|
check %x != %source
|
|
|
|
expect ValueError:
|
|
|
|
let
|
|
|
|
source = "01234"
|
|
|
|
x = hexQuantityStr source
|
|
|
|
check %x != %source
|
|
|
|
expect ValueError:
|
2018-08-06 17:08:50 +00:00
|
|
|
# leading zeros not allowed
|
2018-07-27 17:02:59 +00:00
|
|
|
let
|
2018-08-06 17:08:50 +00:00
|
|
|
source = "0x0123"
|
2018-07-27 17:02:59 +00:00
|
|
|
x = hexQuantityStr source
|
|
|
|
check %x != %source
|
|
|
|
|
2018-08-06 17:08:50 +00:00
|
|
|
suite "[RPC] Hex data":
|
|
|
|
test "Zero value":
|
|
|
|
expect ValueError:
|
|
|
|
let
|
|
|
|
source = ""
|
|
|
|
x = hexDataStr source
|
|
|
|
check %x != %source
|
|
|
|
expect ValueError:
|
|
|
|
# not even length
|
|
|
|
let
|
|
|
|
source = "0x0"
|
|
|
|
x = hexDataStr source
|
|
|
|
check %x == %source
|
|
|
|
let
|
|
|
|
source = "0x"
|
|
|
|
x = hexDataStr source
|
|
|
|
check %x == %source
|
2018-07-27 17:02:59 +00:00
|
|
|
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
|
2018-08-06 17:08:50 +00:00
|
|
|
test "\"0x\" header":
|
2018-07-27 17:02:59 +00:00
|
|
|
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
|
2018-08-06 17:08:50 +00:00
|
|
|
let
|
|
|
|
# leading zeros allowed
|
|
|
|
source = "0x0123"
|
|
|
|
x = hexDataStr source
|
|
|
|
check %x == %source
|