mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-27 12:35:00 +00:00
Fix bugs in lookup and add test case (#820)
This commit is contained in:
parent
832a50df6e
commit
2c620c007d
@ -252,6 +252,7 @@ proc lookupDistances(target, dest: NodeId): seq[uint16] =
|
||||
if td - i > 0'u16:
|
||||
distances.add(td - i)
|
||||
inc i
|
||||
distances
|
||||
|
||||
proc lookupWorker(p: PortalProtocol, destNode: Node, target: NodeId):
|
||||
Future[seq[Node]] {.async.} =
|
||||
@ -261,7 +262,7 @@ proc lookupWorker(p: PortalProtocol, destNode: Node, target: NodeId):
|
||||
let nodesMessage = await p.findNode(destNode, List[uint16, 256](distances))
|
||||
if nodesMessage.isOk():
|
||||
let records = recordsFromBytes(nodesMessage.get().enrs)
|
||||
let verifiedNodes = verifyNodesRecords(records, destNode, @[0'u16])
|
||||
let verifiedNodes = verifyNodesRecords(records, destNode, distances)
|
||||
nodes.add(verifiedNodes)
|
||||
|
||||
# Attempt to add all nodes discovered
|
||||
|
@ -130,6 +130,36 @@ procSuite "Portal Tests":
|
||||
|
||||
await test.stopTest()
|
||||
|
||||
asyncTest "Portal lookup nodes":
|
||||
let
|
||||
node1 = initDiscoveryNode(
|
||||
rng, PrivateKey.random(rng[]), localAddress(20302))
|
||||
node2 = initDiscoveryNode(
|
||||
rng, PrivateKey.random(rng[]), localAddress(20303))
|
||||
node3 = initDiscoveryNode(
|
||||
rng, PrivateKey.random(rng[]), localAddress(20304))
|
||||
|
||||
proto1 = PortalProtocol.new(node1, testHandler)
|
||||
proto2 = PortalProtocol.new(node2, testHandler)
|
||||
proto3 = PortalProtocol.new(node3, testHandler)
|
||||
|
||||
# Node1 knows about Node2, and Node2 knows about Node3 which hold all content
|
||||
check proto1.addNode(node2.localNode) == Added
|
||||
check proto2.addNode(node3.localNode) == Added
|
||||
|
||||
check (await proto2.ping(node3.localNode)).isOk()
|
||||
|
||||
let lookuResult = await proto1.lookup(node3.localNode.id)
|
||||
|
||||
check:
|
||||
# returned result should contain node3 as it is in node2 routing table
|
||||
lookuResult.contains(node3.localNode)
|
||||
|
||||
await node1.closeWait()
|
||||
await node2.closeWait()
|
||||
await node3.closeWait()
|
||||
|
||||
|
||||
asyncTest "Portal FindContent/FoundContent - send enrs":
|
||||
let test = defaultTestCase(rng)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user