diff --git a/eth/trie/nibbles.nim b/eth/trie/nibbles.nim index e1d05dc..4f8509f 100644 --- a/eth/trie/nibbles.nim +++ b/eth/trie/nibbles.nim @@ -11,8 +11,9 @@ proc initNibbleRange*(bytes: ByteRange): NibblesRange = result.ibegin = 0 result.iend = bytes.len * 2 -const - zeroNibblesRange* = initNibbleRange(zeroBytesRange) +# can't be a const: https://github.com/status-im/nim-eth/issues/6 +# we can't initialise it here, but since it's already zeroed memory, we don't need to +var zeroNibblesRange* {.threadvar.}: NibblesRange proc `{}`(r: NibblesRange, pos: int): byte {.inline.} = ## This is a helper for a more raw access to the nibbles. diff --git a/eth/trie/trie_defs.nim b/eth/trie/trie_defs.nim index 0e50f7f..4c557ed 100644 --- a/eth/trie/trie_defs.nim +++ b/eth/trie/trie_defs.nim @@ -8,8 +8,11 @@ type KeccakHash* = MDigest[256] BytesContainer* = ByteRange | Bytes | string +# can't be a const: https://github.com/status-im/nim-eth/issues/6 +# we can't initialise it here, but since it's already zeroed memory, we don't need to +var zeroBytesRange* {.threadvar.}: ByteRange + const - zeroBytesRange* = ByteRange() blankStringHash* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470".toDigest emptyRlp* = @[128.byte] emptyRlpHash* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".toDigest diff --git a/tests/trie/test_nibbles.nim b/tests/trie/test_nibbles.nim new file mode 100644 index 0000000..cf81751 --- /dev/null +++ b/tests/trie/test_nibbles.nim @@ -0,0 +1,9 @@ +import + unittest, + eth/trie/nibbles + +suite "nibbles": + test "zeroNibblesRange": + # https://github.com/status-im/nim-eth/issues/6 + check zeroNibblesRange.len == 0 +