Activate discovery v5.0 handshake tests again

This commit is contained in:
kdeme 2020-10-09 10:46:28 +02:00 committed by zah
parent cf586c363f
commit 65ed0c4850
2 changed files with 62 additions and 61 deletions

View File

@ -36,17 +36,6 @@ proc nodeIdInNodes*(id: NodeId, nodes: openarray[Node]): bool =
for n in nodes: for n in nodes:
if id == n.id: return true if id == n.id: return true
# proc randomPacket*(rng: var BrHmacDrbgContext, tag: PacketTag): seq[byte] =
# var
# authTag: AuthTag
# msg: array[44, byte]
# brHmacDrbgGenerate(rng, authTag)
# brHmacDrbgGenerate(rng, msg)
# result.add(tag)
# result.add(rlp.encode(authTag))
# result.add(msg)
proc generateNode*(privKey: PrivateKey, port: int = 20302, proc generateNode*(privKey: PrivateKey, port: int = 20302,
localEnrFields: openarray[FieldPair] = []): Node = localEnrFields: openarray[FieldPair] = []): Node =
let port = Port(port) let port = Port(port)

View File

@ -73,56 +73,6 @@ procSuite "Discovery v5 Tests":
await node1.closeWait() await node1.closeWait()
# asyncTest "Handshake cleanup":
# let node = initDiscoveryNode(
# rng, PrivateKey.random(rng[]), localAddress(20302))
# var tag: PacketTag
# let a = localAddress(20303)
# for i in 0 ..< 5:
# brHmacDrbgGenerate(rng[], tag)
# node.receive(a, randomPacket(rng[], tag))
# # Checking different nodeIds but same address
# check node.codec.handshakes.len == 5
# # TODO: Could get rid of the sleep by storing the timeout future of the
# # handshake
# await sleepAsync(handshakeTimeout)
# # Checking handshake cleanup
# check node.codec.handshakes.len == 0
# await node.closeWait()
# asyncTest "Handshake different address":
# let node = initDiscoveryNode(
# rng, PrivateKey.random(rng[]), localAddress(20302))
# var tag: PacketTag
# for i in 0 ..< 5:
# let a = localAddress(20303 + i)
# node.receive(a, randomPacket(rng[], tag))
# check node.codec.handshakes.len == 5
# await node.closeWait()
# asyncTest "Handshake duplicates":
# let node = initDiscoveryNode(
# rng, PrivateKey.random(rng[]), localAddress(20302))
# var tag: PacketTag
# let a = localAddress(20303)
# for i in 0 ..< 5:
# node.receive(a, randomPacket(rng[], tag))
# # Checking handshake duplicates
# check node.codec.handshakes.len == 1
# # TODO: add check that gets the Whoareyou value and checks if its authTag
# # is that of the first packet.
# await node.closeWait()
test "Distance check": test "Distance check":
const const
targetId = "0x0000" targetId = "0x0000"
@ -585,3 +535,65 @@ procSuite "Discovery v5 Tests":
records = [recordInvalidDistance] records = [recordInvalidDistance]
test = verifyNodesRecords(records, fromNode, 0'u32) test = verifyNodesRecords(records, fromNode, 0'u32)
check test.len == 0 check test.len == 0
when not UseDiscv51:
proc randomPacket(rng: var BrHmacDrbgContext, tag: PacketTag): seq[byte] =
var
authTag: AuthTag
msg: array[44, byte]
brHmacDrbgGenerate(rng, authTag)
brHmacDrbgGenerate(rng, msg)
result.add(tag)
result.add(rlp.encode(authTag))
result.add(msg)
asyncTest "Handshake cleanup":
let node = initDiscoveryNode(
rng, PrivateKey.random(rng[]), localAddress(20302))
var tag: PacketTag
let a = localAddress(20303)
for i in 0 ..< 5:
brHmacDrbgGenerate(rng[], tag)
node.receive(a, randomPacket(rng[], tag))
# Checking different nodeIds but same address
check node.codec.handshakes.len == 5
# TODO: Could get rid of the sleep by storing the timeout future of the
# handshake
await sleepAsync(handshakeTimeout)
# Checking handshake cleanup
check node.codec.handshakes.len == 0
await node.closeWait()
asyncTest "Handshake different address":
let node = initDiscoveryNode(
rng, PrivateKey.random(rng[]), localAddress(20302))
var tag: PacketTag
for i in 0 ..< 5:
let a = localAddress(20303 + i)
node.receive(a, randomPacket(rng[], tag))
check node.codec.handshakes.len == 5
await node.closeWait()
asyncTest "Handshake duplicates":
let node = initDiscoveryNode(
rng, PrivateKey.random(rng[]), localAddress(20302))
var tag: PacketTag
let a = localAddress(20303)
for i in 0 ..< 5:
node.receive(a, randomPacket(rng[], tag))
# Checking handshake duplicates
check node.codec.handshakes.len == 1
# TODO: add check that gets the Whoareyou value and checks if its authTag
# is that of the first packet.
await node.closeWait()