Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Jul 30, 2024
1 parent 8d45331 commit 09a4e81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 2 additions & 3 deletions tests/node/test_wakunode_lightpush.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ suite "Waku Lightpush - End To End":
server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0))
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))

await allFutures(server.start(), client.start())
await server.start()

await server.mountRelay()
await server.mountLightpush() # without rln-relay
client.mountLightpushClient()

await allFutures(server.start(), client.start())

serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
pubsubTopic = DefaultPubsubTopic
contentTopic = DefaultContentTopic
Expand Down
24 changes: 14 additions & 10 deletions tests/node/test_wakunode_peer_exchange.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,31 @@ suite "Waku Peer Exchange":

suite "fetchPeerExchangePeers":
var node2 {.threadvar.}: WakuNode
var node3 {.threadvar.}: WakuNode

asyncSetup:
# node and node2 have Peer Exchange mounted, node3 doesn't
node = newTestWakuNode(generateSecp256k1Key(), bindIp, bindPort)
node2 = newTestWakuNode(generateSecp256k1Key(), bindIp, bindPort)
node3 = newTestWakuNode(generateSecp256k1Key(), bindIp, bindPort)

await allFutures(node.start(), node2.start())
await allFutures([node.mountPeerExchange(), node2.mountPeerExchange()])
await allFutures(node.start(), node2.start(), node3.start())

asyncTeardown:
await allFutures(node.stop(), node2.stop())

asyncTest "Node fetches without mounting peer exchange":
# When a node, without peer exchange mounted, fetches peers
let res = await node.fetchPeerExchangePeers(1)
let res = await node3.fetchPeerExchangePeers(1)

# Then no peers are fetched
check:
node.peerManager.peerStore.peers.len == 0
node3.peerManager.peerStore.peers.len == 0
res.error == "PeerExchange is not mounted"

asyncTest "Node fetches with mounted peer exchange, but no peers":
# Given a node with peer exchange mounted
await node.mountPeerExchange()

# When a node fetches peers
let res = await node.fetchPeerExchangePeers(1)
check res.error == "Peer exchange failure: peer_not_found_failure"
Expand All @@ -99,7 +101,6 @@ suite "Waku Peer Exchange":

asyncTest "Node succesfully exchanges px peers with faked discv5":
# Given both nodes mount peer exchange
await allFutures([node.mountPeerExchange(), node2.mountPeerExchange()])
check node.peerManager.peerStore.peers.len == 0

# Mock that we discovered a node (to avoid running discv5)
Expand Down Expand Up @@ -254,6 +255,13 @@ suite "Waku Peer Exchange with discv5":
let disc2 =
WakuDiscoveryV5.new(node2.rng, conf2, some(node2.enr), some(node2.peerManager))

# Mount peer exchange
await node1.mountPeerExchange()
await node3.mountPeerExchange()

# Mount relay in order to accept connections
await node2.mountRelay()

await allFutures(node1.start(), node2.start(), node3.start())
let resultDisc1StartRes = await disc1.start()
assert resultDisc1StartRes.isOk(), resultDisc1StartRes.error
Expand All @@ -272,10 +280,6 @@ suite "Waku Peer Exchange with discv5":
await node1.peerManager.connectRelay(node2.switch.peerInfo.toRemotePeerInfo())
)

# Mount peer exchange
await node1.mountPeerExchange()
await node3.mountPeerExchange()

let dialResponse =
await node3.dialForPeerExchange(node1.switch.peerInfo.toRemotePeerInfo())

Expand Down

0 comments on commit 09a4e81

Please sign in to comment.