Clean-up of several compiler warnings (#519)

This commit is contained in:
Kim De Mey 2022-07-09 10:55:15 +02:00 committed by GitHub
parent 7cc3c59ff1
commit 9d7e4b031a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 31 deletions

View File

@ -5,7 +5,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
std/[options, math, sugar] std/[options, math]
export options export options
@ -64,8 +64,8 @@ proc calculateNextMask(currentMask: uint32, index:uint32): uint32 =
# Increase mask,so that index will fit in buffer size i.e mask + 1 # Increase mask,so that index will fit in buffer size i.e mask + 1
if currentMask == uint32.high: if currentMask == uint32.high:
return currentMask return currentMask
var newSize = currentMask + 1 var newSize = currentMask + 1
while true: while true:
newSize = newSize * 2 newSize = newSize * 2
if newSize == 0 or index < newSize: if newSize == 0 or index < newSize:

View File

@ -7,10 +7,9 @@
{.push raises: [Defect].} {.push raises: [Defect].}
import import
std/[monotimes],
faststreams, faststreams,
chronos, chronos,
stew/[endians2, results, objects, arrayops], stew/[endians2, results, objects],
../p2p/discoveryv5/random2 ../p2p/discoveryv5/random2
export results, random2 export results, random2

View File

@ -48,7 +48,7 @@ proc hash(x: UtpSocketKey[NodeAddress]): Hash =
func `$`*(x: UtpSocketKey[NodeAddress]): string = func `$`*(x: UtpSocketKey[NodeAddress]): string =
"(remoteId: " & $x.remoteAddress.nodeId & "(remoteId: " & $x.remoteAddress.nodeId &
", remoteAddress: " & $x.remoteAddress.address & ", remoteAddress: " & $x.remoteAddress.address &
", rcvId: "& $x.rcvId & ", rcvId: " & $x.rcvId &
")" ")"
proc talkReqDirect(p: protocol.Protocol, n: NodeAddress, protocol, request: seq[byte]): Future[void] = proc talkReqDirect(p: protocol.Protocol, n: NodeAddress, protocol, request: seq[byte]): Future[void] =

View File

@ -7,7 +7,7 @@
{.push raises: [Defect].} {.push raises: [Defect].}
import import
std/[tables, options, hashes, sugar, math], std/[tables, options, hashes, math],
chronos, chronicles, chronos, chronicles,
./utp_router, ./utp_router,
../keys ../keys

View File

@ -120,10 +120,10 @@ suite "Routing Table Tests":
table.replaceNode(table.nodeToRevalidate()) table.replaceNode(table.nodeToRevalidate())
block: block:
# Should return the last node of the replacement cache successfully. # Should return the last node of the replacement cache successfully.
let result = table.getNode(lastNode.id) let res = table.getNode(lastNode.id)
check: check:
result.isSome() res.isSome()
result.get() == lastNode res.get() == lastNode
block: block:
# This node should be removed # This node should be removed
check (table.getNode(bucketNodes[bucketNodes.high].id)).isNone() check (table.getNode(bucketNodes[bucketNodes.high].id)).isNone()
@ -186,10 +186,10 @@ suite "Routing Table Tests":
for n in 0..<BUCKET_SIZE: for n in 0..<BUCKET_SIZE:
table.replaceNode(table.nodeToRevalidate()) table.replaceNode(table.nodeToRevalidate())
let result = table.getNode(doubleNode.id) let res = table.getNode(doubleNode.id)
check: check:
result.isSome() res.isSome()
result.get() == doubleNode res.get() == doubleNode
table.len == 1 table.len == 1
test "Double replacement add": test "Double replacement add":
@ -212,10 +212,10 @@ suite "Routing Table Tests":
table.replaceNode(table.nodeToRevalidate()) table.replaceNode(table.nodeToRevalidate())
block: block:
# Should return the last node of the replacement cache successfully. # Should return the last node of the replacement cache successfully.
let result = table.getNode(replacementNodes[0].id) let res = table.getNode(replacementNodes[0].id)
check: check:
result.isSome() res.isSome()
result.get() == replacementNodes[0] res.get() == replacementNodes[0]
block: block:
# This node should be removed # This node should be removed
check (table.getNode(bucketNodes[bucketNodes.high].id)).isNone() check (table.getNode(bucketNodes[bucketNodes.high].id)).isNone()
@ -258,16 +258,16 @@ suite "Routing Table Tests":
table.setJustSeen(replacementNodes[i]) table.setJustSeen(replacementNodes[i])
for n in replacementNodes: for n in replacementNodes:
let result = table.getNode(n.id) let res = table.getNode(n.id)
check: check:
result.isSome() res.isSome()
result.get() == n res.get() == n
for i in 0..<int(BUCKET_SIZE/2): for i in 0..<int(BUCKET_SIZE/2):
let result = table.getNode(bucketNodes[i].id) let res = table.getNode(bucketNodes[i].id)
check: check:
result.isSome() res.isSome()
result.get() == bucketNodes[i] res.get() == bucketNodes[i]
test "Ip limits on bucket": test "Ip limits on bucket":
let node = generateNode(PrivateKey.random(rng[])) let node = generateNode(PrivateKey.random(rng[]))

View File

@ -12,7 +12,7 @@ suite "binary trie":
test "different order insert": test "different order insert":
randomize() randomize()
var kv_pairs = randKVPair() var kv_pairs = randKVPair()
var result = zeroHash var res = zeroHash
for _ in 0..<1: # repeat 3 times for _ in 0..<1: # repeat 3 times
var db = newMemoryDB() var db = newMemoryDB()
var trie = initBinaryTrie(db) var trie = initBinaryTrie(db)
@ -24,12 +24,12 @@ suite "binary trie":
let y = c.value let y = c.value
check y == x check y == x
check result == zeroHash or trie.getRootHash() == result check res == zeroHash or trie.getRootHash() == res
result = trie.getRootHash() res = trie.getRootHash()
# insert already exist key/value # insert already exist key/value
trie.set(kv_pairs[0].key, kv_pairs[0].value) trie.set(kv_pairs[0].key, kv_pairs[0].value)
check trie.getRootHash() == result check trie.getRootHash() == res
# Delete all key/value # Delete all key/value
random.shuffle(kv_pairs) random.shuffle(kv_pairs)

View File

@ -7,10 +7,9 @@
{.used.} {.used.}
import import
std/[sequtils, tables, options, sugar], std/[tables, options],
chronos, chronos,
testutils/unittests, testutils/unittests,
./test_utils,
../../eth/utp/utp_router, ../../eth/utp/utp_router,
../../eth/utp/utp_protocol, ../../eth/utp/utp_protocol,
../../eth/keys, ../../eth/keys,

View File

@ -8,7 +8,7 @@
import import
std/options, std/options,
stew/[byteutils, bitops2], stew/byteutils,
unittest2, unittest2,
../../eth/utp/packets, ../../eth/utp/packets,
../../eth/keys ../../eth/keys
@ -32,7 +32,7 @@ suite "Utp packets test vectors":
) )
let encodedSyn = encodePacket(synPacket) let encodedSyn = encodePacket(synPacket)
let synBytes = hexToSeqByte("0x41002741c9b699ba00000000001000002e6c0000") let synBytes = hexToSeqByte("0x41002741c9b699ba00000000001000002e6c0000")
check: check:
@ -109,7 +109,7 @@ suite "Utp packets test vectors":
) )
let encodedData = encodePacket(dataPacket) let encodedData = encodePacket(dataPacket)
let dataBytes = hexToSeqByte("0x0100667d0f0cbacf0e710cbf00100000208e41a600010203040506070809") let dataBytes = hexToSeqByte("0x0100667d0f0cbacf0e710cbf00100000208e41a600010203040506070809")
check: check: