Prepare for Nim 1.2

This commit is contained in:
Zahary Karadjov 2020-03-23 23:09:16 +02:00 committed by zah
parent 9c442bf65b
commit 2b7a25175b
9 changed files with 15 additions and 11 deletions

View File

@ -236,12 +236,9 @@ proc newKademliaProtocol*[Wire](thisNode: Node,
result.new() result.new()
result.thisNode = thisNode result.thisNode = thisNode
result.wire = wire result.wire = wire
result.pongFutures = initTable[seq[byte], Future[bool]]()
result.pingFutures = initTable[Node, Future[bool]]()
result.neighboursCallbacks = initTable[Node, proc(n: seq[Node])]()
result.routing.init(thisNode) result.routing.init(thisNode)
proc bond(k: KademliaProtocol, n: Node): Future[bool] {.async.} proc bond(k: KademliaProtocol, n: Node): Future[bool] {.async, gcsafe.}
proc updateRoutingTable(k: KademliaProtocol, n: Node) {.gcsafe.} = proc updateRoutingTable(k: KademliaProtocol, n: Node) {.gcsafe.} =
## Update the routing table entry for the given node. ## Update the routing table entry for the given node.

View File

@ -35,6 +35,13 @@ template asyncTest*(name, body: untyped) =
proc scenario {.async.} = body proc scenario {.async.} = body
waitFor scenario() waitFor scenario()
template procSuite*(name, body: untyped) =
proc suitePayload =
suite name:
body
suitePayload()
proc packData*(payload: openArray[byte], pk: PrivateKey): seq[byte] = proc packData*(payload: openArray[byte], pk: PrivateKey): seq[byte] =
let let
payloadSeq = @payload payloadSeq = @payload

View File

@ -34,7 +34,7 @@ proc test() {.async.} =
for i in 0 ..< nodeKeys.len: nodeAddrs.add(localAddress(20302 + i)) for i in 0 ..< nodeKeys.len: nodeAddrs.add(localAddress(20302 + i))
var nodes = await all(zip(nodeKeys, nodeAddrs).mapIt( var nodes = await all(zip(nodeKeys, nodeAddrs).mapIt(
startDiscoveryNode(it.a, it.b, @[bootENode])) startDiscoveryNode(it[0], it[1], @[bootENode]))
) )
nodes.add(bootNode) nodes.add(bootNode)

View File

@ -48,7 +48,7 @@ suite "Discovery v5 Tests":
for i in 0 ..< nodeKeys.len: nodeAddrs.add(localAddress(20302 + i)) for i in 0 ..< nodeKeys.len: nodeAddrs.add(localAddress(20302 + i))
var nodes = zip(nodeKeys, nodeAddrs).mapIt( var nodes = zip(nodeKeys, nodeAddrs).mapIt(
initDiscoveryNode(it.a, it.b, @[bootNode.localNode.record])) initDiscoveryNode(it[0], it[1], @[bootNode.localNode.record]))
nodes.add(bootNode) nodes.add(bootNode)
for node in nodes: for node in nodes:

View File

@ -19,7 +19,7 @@ proc resetMessageQueues(nodes: varargs[EthereumNode]) =
let safeTTL = 5'u32 let safeTTL = 5'u32
let waitInterval = messageInterval + 150.milliseconds let waitInterval = messageInterval + 150.milliseconds
suite "Whisper connections": procSuite "Whisper connections":
var node1 = setupTestNode(Whisper) var node1 = setupTestNode(Whisper)
var node2 = setupTestNode(Whisper) var node2 = setupTestNode(Whisper)
node2.startListening() node2.startListening()

View File

@ -17,7 +17,7 @@ import
let safeTTL = 5'u32 let safeTTL = 5'u32
let waitInterval = waku.messageInterval + 150.milliseconds let waitInterval = waku.messageInterval + 150.milliseconds
suite "Waku - Whisper bridge tests": procSuite "Waku - Whisper bridge tests":
# Waku Whisper node has both capabilities, listens to Whisper and Waku and # Waku Whisper node has both capabilities, listens to Whisper and Waku and
# relays traffic between the two. # relays traffic between the two.
var var

View File

@ -19,7 +19,7 @@ const
# check on a condition until true or return a future containing false # check on a condition until true or return a future containing false
# if timeout expires first # if timeout expires first
proc eventually(timeout: int, condition: proc(): bool): Future[bool] = proc eventually(timeout: int, condition: proc(): bool {.gcsafe.}): Future[bool] =
let wrappedCondition = proc(): Future[bool] {.async.} = let wrappedCondition = proc(): Future[bool] {.async.} =
let f = newFuture[bool]() let f = newFuture[bool]()
while not condition(): while not condition():

View File

@ -11,7 +11,7 @@ proc waitForConnected(node: EthereumNode) {.async.} =
while node.peerPool.connectedNodes.len == 0: while node.peerPool.connectedNodes.len == 0:
await sleepAsync(chronos.milliseconds(1)) await sleepAsync(chronos.milliseconds(1))
suite "Waku Mail Client": procSuite "Waku Mail Client":
var client = setupTestNode(Waku) var client = setupTestNode(Waku)
var simpleServer = setupTestNode(Waku) var simpleServer = setupTestNode(Waku)

View File

@ -53,7 +53,7 @@ template backendTests(DB) =
keyA notin db keyA notin db
keyB in db keyB in db
check db.get(keyA) == @[] check db.get(keyA).len == 0
check db.get(keyB) == value1 check db.get(keyB) == value1
db.del(keyA) db.del(keyA)