Fix nim v1.0.2 compile issues

This commit is contained in:
kdeme 2019-10-29 12:45:57 +01:00 committed by zah
parent aa1f7f2c06
commit 44400ee549
8 changed files with 12 additions and 18 deletions

View File

@ -230,7 +230,7 @@ proc kdfParams(kdfkind: KdfKind, salt: string, workfactor: int,
proc decodeHex(m: string): seq[byte] = proc decodeHex(m: string): seq[byte] =
if len(m) > 0: if len(m) > 0:
try: try:
result = fromHex(m) result = utils.fromHex(m)
except: except:
result = newSeq[byte]() result = newSeq[byte]()
else: else:
@ -240,7 +240,7 @@ proc decodeSalt(m: string): string =
var sarr: seq[byte] var sarr: seq[byte]
if len(m) > 0: if len(m) > 0:
try: try:
sarr = fromHex(m) sarr = utils.fromHex(m)
result = newString(len(sarr)) result = newString(len(sarr))
copyMem(addr result[0], addr sarr[0], len(sarr)) copyMem(addr result[0], addr sarr[0], len(sarr))
except: except:

View File

@ -130,8 +130,6 @@ proc setAux(self: BinaryTrie, nodeHash: TrieNodeKey, keyPath: TrieBitRange,
of BRANCH_TYPE: # node is a branch node of BRANCH_TYPE: # node is a branch node
checkBadKeyPath() checkBadKeyPath()
return self.setBranchNode(keyPath, node, value, deleteSubtrie) return self.setBranchNode(keyPath, node, value, deleteSubtrie)
else:
raise newException(Exception, "Invariant: This shouldn't ever happen")
proc set*(self: var BinaryTrie, key, value: distinct BytesContainer) {.inline.} = proc set*(self: var BinaryTrie, key, value: distinct BytesContainer) {.inline.} =
## Sets the value at the given keyPath from the given node ## Sets the value at the given keyPath from the given node

View File

@ -34,8 +34,6 @@ proc checkIfBranchExistImpl(db: DB; nodeHash: TrieNodeKey; keyPrefix: TrieBitRan
return checkIfBranchExistImpl(db, node.leftChild, keyPrefix.sliceToEnd(1)) return checkIfBranchExistImpl(db, node.leftChild, keyPrefix.sliceToEnd(1))
else: else:
return checkIfBranchExistImpl(db, node.rightChild, keyPrefix.sliceToEnd(1)) return checkIfBranchExistImpl(db, node.rightChild, keyPrefix.sliceToEnd(1))
else:
raise newException(Exception, "Invariant: unreachable code path")
proc checkIfBranchExist*(db: DB; rootHash: BytesContainer | KeccakHash, keyPrefix: BytesContainer): bool = proc checkIfBranchExist*(db: DB; rootHash: BytesContainer | KeccakHash, keyPrefix: BytesContainer): bool =
## Given a key prefix, return whether this prefix is ## Given a key prefix, return whether this prefix is
@ -76,9 +74,6 @@ proc getBranchImpl(db: DB; nodeHash: TrieNodeKey, keyPath: TrieBitRange, output:
else: else:
getBranchImpl(db, node.rightChild, keyPath.sliceToEnd(1), output) getBranchImpl(db, node.rightChild, keyPath.sliceToEnd(1), output)
else:
raise newException(Exception, "Invariant: unreachable code path")
proc getBranch*(db: DB; rootHash: BytesContainer | KeccakHash; key: BytesContainer): seq[BytesRange] = proc getBranch*(db: DB; rootHash: BytesContainer | KeccakHash; key: BytesContainer): seq[BytesRange] =
## Get a long-format Merkle branch ## Get a long-format Merkle branch
checkValidHashZ(rootHash) checkValidHashZ(rootHash)
@ -123,8 +118,6 @@ proc getTrieNodesImpl(db: DB; nodeHash: TrieNodeKey, output: var seq[BytesRange]
result = getTrieNodesImpl(db, node.rightChild, output) result = getTrieNodesImpl(db, node.rightChild, output)
of LEAF_TYPE: of LEAF_TYPE:
output.add nodeVal output.add nodeVal
else:
raise newException(Exception, "Invariant: unreachable code path")
proc getTrieNodes*(db: DB; nodeHash: BytesContainer | KeccakHash): seq[BytesRange] = proc getTrieNodes*(db: DB; nodeHash: BytesContainer | KeccakHash): seq[BytesRange] =
checkValidHashZ(nodeHash) checkValidHashZ(nodeHash)
@ -161,8 +154,6 @@ proc getWitnessImpl*(db: DB; nodeHash: TrieNodeKey; keyPath: TrieBitRange; outpu
getWitnessImpl(db, node.leftChild, keyPath.sliceToEnd(1), output) getWitnessImpl(db, node.leftChild, keyPath.sliceToEnd(1), output)
else: else:
getWitnessImpl(db, node.rightChild, keyPath.sliceToEnd(1), output) getWitnessImpl(db, node.rightChild, keyPath.sliceToEnd(1), output)
else:
raise newException(Exception, "Invariant: unreachable code path")
proc getWitness*(db: DB; nodeHash: BytesContainer | KeccakHash; key: BytesContainer): seq[BytesRange] = proc getWitness*(db: DB; nodeHash: BytesContainer | KeccakHash; key: BytesContainer): seq[BytesRange] =
## Get all witness given a keyPath prefix. ## Get all witness given a keyPath prefix.

View File

@ -1,3 +1,5 @@
--threads:on --threads:on
--path:"$projectDir/.." --path:"$projectDir/.."
# rocksdb_backend newChainDB fails compiling without nimOldCaseObjects as
# rocksdb init does this type of assignment
--define:nimOldCaseObjects

View File

@ -7,9 +7,10 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
import unittest, strutils import unittest
import eth/keys import eth/keys
import nimcrypto/hash, nimcrypto/keccak, nimcrypto/utils import nimcrypto/hash, nimcrypto/keccak, nimcrypto/utils
from strutils import toLowerAscii
proc compare(x: openarray[byte], y: openarray[byte]): bool = proc compare(x: openarray[byte], y: openarray[byte]): bool =
result = len(x) == len(y) result = len(x) == len(y)

View File

@ -90,7 +90,8 @@ suite "ENode":
test "isCorrect() tests": test "isCorrect() tests":
var node: ENode var node: ENode
check isCorrect(node) == false check isCorrect(node) == false
node.address.ip.family = IpAddressFamily.IPv4 let ip = IpAddress(family:IpAddressFamily.IPv4)
node = Enode(address: Address(ip: ip))
check isCorrect(node) == false check isCorrect(node) == false
node.address.tcpPort = Port(25) node.address.tcpPort = Port(25)
check isCorrect(node) == false check isCorrect(node) == false

View File

@ -1,3 +1,2 @@
--threads:on --threads:on
--path:"$projectDir/../.." --path:"$projectDir/../.."

View File

@ -1,8 +1,10 @@
import import
unittest, strutils, sequtils, os, unittest, sequtils, os,
stew/ranges/typedranges, eth/trie/[hexary, db, trie_defs], nimcrypto/utils, stew/ranges/typedranges, eth/trie/[hexary, db, trie_defs], nimcrypto/utils,
./testutils, algorithm, eth/rlp/types as rlpTypes, random ./testutils, algorithm, eth/rlp/types as rlpTypes, random
from strutils import split
template put(t: HexaryTrie|SecureHexaryTrie, key, val: string) = template put(t: HexaryTrie|SecureHexaryTrie, key, val: string) =
t.put(key.toBytesRange, val.toBytesRange) t.put(key.toBytesRange, val.toBytesRange)