30 lines
1.1 KiB
Nim
30 lines
1.1 KiB
Nim
# Nim Eth-keys
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
# Licensed under either of
|
|
#
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
#
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
import ../src/private/lowlevel_types
|
|
import unittest, ttmath, strutils
|
|
|
|
|
|
suite "Testing conversion functions: Hex, Bytes, Endianness":
|
|
let
|
|
SECPK1_N_HEX = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141".toLowerAscii
|
|
SECPK1_N = "115792089237316195423570985008687907852837564279074904382605163141518161494337".u256
|
|
|
|
test "hex -> uint256":
|
|
check: SECPK1_N_HEX.hexToUInt256 == SECPK1_N
|
|
|
|
test "uint256 -> hex":
|
|
check: SECPK1_N.toHex == SECPK1_N_HEX
|
|
|
|
test "hex -> big-endian array -> uint256":
|
|
check: hexToByteArrayBE[32](SECPK1_N_HEX).readUint256BE == SECPK1_N
|
|
|
|
test "uint256 -> big-endian array -> hex":
|
|
check: SECPK1_N.toByteArrayBE.toHex == SECPK1_N_HEX
|