Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 29, 2024
1 parent 486e22e commit a58fb41
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions tests/test_peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ import
./testlib/wakunode

procSuite "Peer Manager":
asyncTest "connectRelay() works":
asyncTest "connect() works":
# Create 2 nodes
let nodes = toSeq(0 ..< 2).mapIt(
newTestWakuNode(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
)
await allFutures(nodes.mapIt(it.start()))

let connOk =
await nodes[0].peerManager.connectRelay(nodes[1].peerInfo.toRemotePeerInfo())
await nodes[0].peerManager.connect(nodes[1].peerInfo.toRemotePeerInfo())
await sleepAsync(chronos.milliseconds(500))

check:
Expand Down Expand Up @@ -178,7 +178,7 @@ procSuite "Peer Manager":

let nonExistentPeer = nonExistentPeerRes.value
require:
(await nodes[0].peerManager.connectRelay(nonExistentPeer)) == false
(await nodes[0].peerManager.connect(nonExistentPeer)) == false
await sleepAsync(chronos.milliseconds(500))

check:
Expand All @@ -188,8 +188,7 @@ procSuite "Peer Manager":

# Successful connection
require:
(await nodes[0].peerManager.connectRelay(nodes[1].peerInfo.toRemotePeerInfo())) ==
true
(await nodes[0].peerManager.connect(nodes[1].peerInfo.toRemotePeerInfo())) == true
await sleepAsync(chronos.milliseconds(500))

check:
Expand Down Expand Up @@ -229,7 +228,7 @@ procSuite "Peer Manager":
nodes[0].peerManager.backoffFactor = 2

# try to connect to peer that doesnt exist
let conn1Ok = await nodes[0].peerManager.connectRelay(nonExistentPeer)
let conn1Ok = await nodes[0].peerManager.connect(nonExistentPeer)
check:
# Cannot connect to node2
nodes[0].peerManager.wakuPeerStore.connectedness(nonExistentPeer.peerId) ==
Expand All @@ -256,7 +255,7 @@ procSuite "Peer Manager":
nodes[0].peerManager.wakuPeerStore[NumberFailedConnBook][nodes[1].peerInfo.peerId] =
4
let conn2Ok =
await nodes[0].peerManager.connectRelay(nodes[1].peerInfo.toRemotePeerInfo())
await nodes[0].peerManager.connect(nodes[1].peerInfo.toRemotePeerInfo())
check:
conn2Ok == true
nodes[0].peerManager.wakuPeerStore[NumberFailedConnBook][nodes[1].peerInfo.peerId] ==
Expand Down Expand Up @@ -286,7 +285,7 @@ procSuite "Peer Manager":
var remotePeerInfo2 = peerInfo2.toRemotePeerInfo()
remotePeerInfo2.enr = some(node2.enr)

let is12Connected = await node1.peerManager.connectRelay(remotePeerInfo2)
let is12Connected = await node1.peerManager.connect(remotePeerInfo2)
assert is12Connected == true, "Node 1 and 2 not connected"

check:
Expand Down Expand Up @@ -356,7 +355,7 @@ procSuite "Peer Manager":
var remotePeerInfo2 = peerInfo2.toRemotePeerInfo()
remotePeerInfo2.enr = some(node2.enr)

let is12Connected = await node1.peerManager.connectRelay(remotePeerInfo2)
let is12Connected = await node1.peerManager.connect(remotePeerInfo2)
assert is12Connected == true, "Node 1 and 2 not connected"

check:
Expand Down Expand Up @@ -485,7 +484,7 @@ procSuite "Peer Manager":
node2.wakuRelay.codec = betaCodec

require:
(await node1.peerManager.connectRelay(peerInfo2.toRemotePeerInfo())) == true
(await node1.peerManager.connect(peerInfo2.toRemotePeerInfo())) == true
check:
# Currently connected to node2
node1.peerManager.wakuPeerStore.peers().len == 1
Expand Down Expand Up @@ -682,9 +681,9 @@ procSuite "Peer Manager":

# all nodes connect to peer 0
require:
(await nodes[1].peerManager.connectRelay(peerInfos[0])) == true
(await nodes[2].peerManager.connectRelay(peerInfos[0])) == true
(await nodes[3].peerManager.connectRelay(peerInfos[0])) == true
(await nodes[1].peerManager.connect(peerInfos[0])) == true
(await nodes[2].peerManager.connect(peerInfos[0])) == true
(await nodes[3].peerManager.connect(peerInfos[0])) == true

await sleepAsync(chronos.milliseconds(500))

Expand Down Expand Up @@ -810,9 +809,9 @@ procSuite "Peer Manager":
# create some connections/streams
check:
# some relay connections
(await nodes[0].peerManager.connectRelay(pInfos[1])) == true
(await nodes[0].peerManager.connectRelay(pInfos[2])) == true
(await nodes[1].peerManager.connectRelay(pInfos[2])) == true
(await nodes[0].peerManager.connect(pInfos[1])) == true
(await nodes[0].peerManager.connect(pInfos[2])) == true
(await nodes[1].peerManager.connect(pInfos[2])) == true

(await nodes[0].peerManager.dialPeer(pInfos[1], WakuFilterSubscribeCodec)).isSome() ==
true
Expand Down Expand Up @@ -1129,16 +1128,16 @@ procSuite "Peer Manager":
nodes[0].peerManager.colocationLimit = 1

# 2 in connections
discard await nodes[1].peerManager.connectRelay(pInfos[0])
discard await nodes[2].peerManager.connectRelay(pInfos[0])
discard await nodes[1].peerManager.connect(pInfos[0])
discard await nodes[2].peerManager.connect(pInfos[0])
await sleepAsync(chronos.milliseconds(500))

# but one is pruned
check nodes[0].peerManager.switch.connManager.getConnections().len == 1

# 2 out connections
discard await nodes[0].peerManager.connectRelay(pInfos[3])
discard await nodes[0].peerManager.connectRelay(pInfos[4])
discard await nodes[0].peerManager.connect(pInfos[3])
discard await nodes[0].peerManager.connect(pInfos[4])
await sleepAsync(chronos.milliseconds(500))

# they are also prunned
Expand Down

0 comments on commit a58fb41

Please sign in to comment.