2020-08-31 03:32:41 +00:00
|
|
|
|
{.used.}
|
|
|
|
|
|
|
|
|
|
import
|
2023-09-27 13:02:24 +00:00
|
|
|
|
std/[sequtils,strutils],
|
2022-11-04 09:52:08 +00:00
|
|
|
|
stew/byteutils,
|
|
|
|
|
stew/shims/net as stewNet,
|
2021-03-26 09:52:04 +00:00
|
|
|
|
testutils/unittests,
|
2023-01-26 10:18:30 +00:00
|
|
|
|
chronicles,
|
|
|
|
|
chronos,
|
2020-08-31 03:32:41 +00:00
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
|
libp2p/crypto/secp,
|
2021-01-25 11:03:52 +00:00
|
|
|
|
libp2p/multiaddress,
|
2020-09-02 03:15:25 +00:00
|
|
|
|
libp2p/switch,
|
2021-03-11 23:42:26 +00:00
|
|
|
|
libp2p/protocols/pubsub/rpc/messages,
|
|
|
|
|
libp2p/protocols/pubsub/pubsub,
|
2021-04-01 09:37:14 +00:00
|
|
|
|
libp2p/protocols/pubsub/gossipsub,
|
2023-02-09 15:59:29 +00:00
|
|
|
|
libp2p/nameresolving/mockresolver,
|
|
|
|
|
eth/p2p/discoveryv5/enr
|
2022-11-04 09:52:08 +00:00
|
|
|
|
import
|
2023-08-09 17:11:50 +00:00
|
|
|
|
../../waku/waku_core,
|
|
|
|
|
../../waku/waku_node,
|
|
|
|
|
../../waku/node/peer_manager,
|
|
|
|
|
../../waku/waku_relay,
|
|
|
|
|
../../waku/waku_peer_exchange,
|
2023-04-05 14:01:51 +00:00
|
|
|
|
./testlib/wakucore,
|
|
|
|
|
./testlib/wakunode
|
2020-07-29 13:24:01 +00:00
|
|
|
|
|
2022-08-01 16:21:11 +00:00
|
|
|
|
|
2023-02-13 10:43:49 +00:00
|
|
|
|
suite "WakuNode":
|
2023-01-26 10:18:30 +00:00
|
|
|
|
|
2021-06-29 14:29:04 +00:00
|
|
|
|
asyncTest "Protocol matcher works as expected":
|
|
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(61000))
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(61002))
|
2021-06-29 14:29:04 +00:00
|
|
|
|
pubSubTopic = "/waku/2/default-waku/proto"
|
|
|
|
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
|
|
|
|
payload = "hello world".toBytes()
|
|
|
|
|
message = WakuMessage(payload: payload, contentTopic: contentTopic)
|
|
|
|
|
|
|
|
|
|
# Setup node 1 with stable codec "/vac/waku/relay/2.0.0"
|
|
|
|
|
|
|
|
|
|
await node1.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
|
await node1.mountRelay(@[pubSubTopic])
|
2021-06-29 14:29:04 +00:00
|
|
|
|
node1.wakuRelay.codec = "/vac/waku/relay/2.0.0"
|
|
|
|
|
|
|
|
|
|
# Setup node 2 with beta codec "/vac/waku/relay/2.0.0-beta2"
|
|
|
|
|
|
|
|
|
|
await node2.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
|
await node2.mountRelay(@[pubSubTopic])
|
2021-06-29 14:29:04 +00:00
|
|
|
|
node2.wakuRelay.codec = "/vac/waku/relay/2.0.0-beta2"
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
# Check that mounted codecs are actually different
|
|
|
|
|
node1.wakuRelay.codec == "/vac/waku/relay/2.0.0"
|
|
|
|
|
node2.wakuRelay.codec == "/vac/waku/relay/2.0.0-beta2"
|
|
|
|
|
|
|
|
|
|
# Now verify that protocol matcher returns `true` and relay works
|
2022-01-10 15:07:35 +00:00
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
2021-06-29 14:29:04 +00:00
|
|
|
|
|
|
|
|
|
var completionFut = newFuture[bool]()
|
2023-06-06 17:28:47 +00:00
|
|
|
|
proc relayHandler(topic: PubsubTopic, msg: WakuMessage): Future[void] {.async, gcsafe.} =
|
|
|
|
|
check:
|
|
|
|
|
topic == pubSubTopic
|
|
|
|
|
msg.contentTopic == contentTopic
|
|
|
|
|
msg.payload == payload
|
2021-06-29 14:29:04 +00:00
|
|
|
|
completionFut.complete(true)
|
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
|
node2.subscribe((kind: PubsubSub, topic: pubsubTopic), some(relayHandler))
|
2021-06-29 14:29:04 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
|
await node1.publish(some(pubSubTopic), message)
|
2021-06-29 14:29:04 +00:00
|
|
|
|
await sleepAsync(2000.millis)
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
(await completionFut.withTimeout(5.seconds)) == true
|
2022-09-12 12:51:52 +00:00
|
|
|
|
|
|
|
|
|
await allFutures(node1.stop(), node2.stop())
|
2021-01-25 11:03:52 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
asyncTest "resolve and connect to dns multiaddrs":
|
|
|
|
|
let resolver = MockResolver.new()
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
resolver.ipResponses[("localhost", false)] = @["127.0.0.1"]
|
|
|
|
|
|
|
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(61020), nameResolver = resolver)
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(61022))
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
# Construct DNS multiaddr for node2
|
|
|
|
|
let
|
|
|
|
|
node2PeerId = $(node2.switch.peerInfo.peerId)
|
2022-11-03 13:47:56 +00:00
|
|
|
|
node2Dns4Addr = "/dns4/localhost/tcp/61022/p2p/" & node2PeerId
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-09-07 15:31:27 +00:00
|
|
|
|
await node1.mountRelay()
|
|
|
|
|
await node2.mountRelay()
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
await allFutures([node1.start(), node2.start()])
|
|
|
|
|
|
|
|
|
|
await node1.connectToNodes(@[node2Dns4Addr])
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
node1.switch.connManager.connCount(node2.switch.peerInfo.peerId) == 1
|
|
|
|
|
|
|
|
|
|
await allFutures([node1.stop(), node2.stop()])
|
|
|
|
|
|
2021-10-12 12:48:48 +00:00
|
|
|
|
asyncTest "Maximum connections can be configured":
|
|
|
|
|
let
|
|
|
|
|
maxConnections = 2
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"),
|
2021-10-12 12:48:48 +00:00
|
|
|
|
Port(60010), maxConnections = maxConnections)
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"),
|
2021-10-12 12:48:48 +00:00
|
|
|
|
Port(60012))
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey3 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node3 = newTestWakuNode(nodeKey3, parseIpAddress("0.0.0.0"),
|
2021-10-12 12:48:48 +00:00
|
|
|
|
Port(60013))
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2021-10-12 12:48:48 +00:00
|
|
|
|
check:
|
|
|
|
|
# Sanity check, to verify config was applied
|
|
|
|
|
node1.switch.connManager.inSema.size == maxConnections
|
|
|
|
|
|
|
|
|
|
# Node with connection limit set to 1
|
|
|
|
|
await node1.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
|
await node1.mountRelay()
|
2021-10-12 12:48:48 +00:00
|
|
|
|
|
|
|
|
|
# Remote node 1
|
|
|
|
|
await node2.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
|
await node2.mountRelay()
|
2021-10-12 12:48:48 +00:00
|
|
|
|
|
|
|
|
|
# Remote node 2
|
|
|
|
|
await node3.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
|
await node3.mountRelay()
|
2021-10-12 12:48:48 +00:00
|
|
|
|
|
2023-03-28 11:29:48 +00:00
|
|
|
|
discard await node1.peerManager.connectRelay(node2.switch.peerInfo.toRemotePeerInfo())
|
2021-10-12 12:48:48 +00:00
|
|
|
|
await sleepAsync(3.seconds)
|
2023-03-28 11:29:48 +00:00
|
|
|
|
discard await node1.peerManager.connectRelay(node3.switch.peerInfo.toRemotePeerInfo())
|
2021-10-12 12:48:48 +00:00
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
# Verify that only the first connection succeeded
|
2022-01-10 15:07:35 +00:00
|
|
|
|
node1.switch.isConnected(node2.switch.peerInfo.peerId)
|
|
|
|
|
node1.switch.isConnected(node3.switch.peerInfo.peerId) == false
|
2021-10-12 12:48:48 +00:00
|
|
|
|
|
|
|
|
|
await allFutures([node1.stop(), node2.stop(), node3.stop()])
|
2021-11-02 10:29:11 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
asyncTest "Messages fails with wrong key path":
|
2023-04-05 14:01:51 +00:00
|
|
|
|
let nodeKey1 = generateSecp256k1Key()
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2023-04-05 14:01:51 +00:00
|
|
|
|
expect ResultDefect:
|
2021-11-10 12:05:36 +00:00
|
|
|
|
# gibberish
|
2023-12-14 06:16:39 +00:00
|
|
|
|
discard newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"),
|
2023-01-26 10:18:30 +00:00
|
|
|
|
bindPort = Port(61004),
|
|
|
|
|
wsBindPort = Port(8000),
|
|
|
|
|
wssEnabled = true,
|
2023-08-09 17:11:50 +00:00
|
|
|
|
secureKey = "../../waku/node/key_dummy.txt")
|
2021-11-10 12:05:36 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
asyncTest "Peer info updates with correct announced addresses":
|
|
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
2022-11-03 13:47:56 +00:00
|
|
|
|
bindPort = Port(61006)
|
2023-12-14 06:16:39 +00:00
|
|
|
|
extIp = some(parseIpAddress("127.0.0.1"))
|
2022-11-03 13:47:56 +00:00
|
|
|
|
extPort = some(Port(61008))
|
2023-04-05 14:01:51 +00:00
|
|
|
|
node = newTestWakuNode(
|
2022-02-16 16:12:09 +00:00
|
|
|
|
nodeKey,
|
|
|
|
|
bindIp, bindPort,
|
|
|
|
|
extIp, extPort)
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
let
|
|
|
|
|
bindEndpoint = MultiAddress.init(bindIp, tcpProtocol, bindPort)
|
|
|
|
|
announcedEndpoint = MultiAddress.init(extIp.get(), tcpProtocol, extPort.get())
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
# Check that underlying peer info contains only bindIp before starting
|
2022-10-28 09:51:46 +00:00
|
|
|
|
node.switch.peerInfo.listenAddrs.len == 1
|
|
|
|
|
node.switch.peerInfo.listenAddrs.contains(bindEndpoint)
|
|
|
|
|
# Underlying peer info has not updated addrs before starting
|
|
|
|
|
node.switch.peerInfo.addrs.len == 0
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
node.announcedAddresses.len == 1
|
|
|
|
|
node.announcedAddresses.contains(announcedEndpoint)
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
await node.start()
|
2021-11-30 09:12:09 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
check:
|
|
|
|
|
node.started
|
2022-10-28 09:51:46 +00:00
|
|
|
|
# Underlying peer info listenAddrs has not changed
|
|
|
|
|
node.switch.peerInfo.listenAddrs.len == 1
|
|
|
|
|
node.switch.peerInfo.listenAddrs.contains(bindEndpoint)
|
|
|
|
|
# Check that underlying peer info is updated with announced address
|
2022-02-16 16:12:09 +00:00
|
|
|
|
node.switch.peerInfo.addrs.len == 1
|
|
|
|
|
node.switch.peerInfo.addrs.contains(announcedEndpoint)
|
2021-11-30 09:12:09 +00:00
|
|
|
|
|
2022-02-16 16:12:09 +00:00
|
|
|
|
await node.stop()
|
2022-02-18 11:10:38 +00:00
|
|
|
|
|
|
|
|
|
asyncTest "Node can use dns4 in announced addresses":
|
|
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
2022-11-03 13:47:56 +00:00
|
|
|
|
bindPort = Port(61010)
|
2023-12-14 06:16:39 +00:00
|
|
|
|
extIp = some(parseIpAddress("127.0.0.1"))
|
2022-11-03 13:47:56 +00:00
|
|
|
|
extPort = some(Port(61012))
|
2022-02-18 11:10:38 +00:00
|
|
|
|
domainName = "example.com"
|
|
|
|
|
expectedDns4Addr = MultiAddress.init("/dns4/" & domainName & "/tcp/" & $(extPort.get())).get()
|
2023-04-05 14:01:51 +00:00
|
|
|
|
node = newTestWakuNode(
|
2022-02-18 11:10:38 +00:00
|
|
|
|
nodeKey,
|
|
|
|
|
bindIp, bindPort,
|
|
|
|
|
extIp, extPort,
|
|
|
|
|
dns4DomainName = some(domainName))
|
2022-05-16 10:51:10 +00:00
|
|
|
|
|
2022-02-18 11:10:38 +00:00
|
|
|
|
check:
|
|
|
|
|
node.announcedAddresses.len == 1
|
|
|
|
|
node.announcedAddresses.contains(expectedDns4Addr)
|
2022-10-28 13:12:06 +00:00
|
|
|
|
|
2023-09-27 13:02:24 +00:00
|
|
|
|
asyncTest "Node uses dns4 resolved ip in announced addresses if no extIp is provided":
|
|
|
|
|
let
|
|
|
|
|
nodeKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
2023-09-27 13:02:24 +00:00
|
|
|
|
bindPort = Port(0)
|
|
|
|
|
|
|
|
|
|
domainName = "status.im"
|
|
|
|
|
node = newTestWakuNode(
|
|
|
|
|
nodeKey,
|
|
|
|
|
bindIp, bindPort,
|
|
|
|
|
dns4DomainName = some(domainName))
|
|
|
|
|
|
|
|
|
|
var ipStr = ""
|
|
|
|
|
var enrIp = node.enr.tryGet("ip", array[4, byte])
|
|
|
|
|
|
|
|
|
|
if enrIp.isSome():
|
|
|
|
|
ipStr &= $ipv4(enrIp.get())
|
|
|
|
|
|
|
|
|
|
# Check that the IP filled is the one received by the DNS lookup
|
|
|
|
|
# As IPs may change, we check that it's not empty, not the 0 IP and not localhost
|
|
|
|
|
check:
|
|
|
|
|
ipStr.len() > 0
|
|
|
|
|
not ipStr.contains("0.0.0.0")
|
|
|
|
|
not ipStr.contains("127.0.0.1")
|
|
|
|
|
|
|
|
|
|
asyncTest "Node creation fails when invalid dns4 address is provided":
|
|
|
|
|
let
|
|
|
|
|
nodeKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
2023-09-27 13:02:24 +00:00
|
|
|
|
bindPort = Port(0)
|
|
|
|
|
|
|
|
|
|
inexistentDomain = "thisdomain.doesnot.exist"
|
|
|
|
|
invalidDomain = ""
|
|
|
|
|
expectedError = "Could not resolve IP from DNS: empty response"
|
|
|
|
|
|
|
|
|
|
var inexistentDomainErr, invalidDomainErr: string = ""
|
|
|
|
|
|
|
|
|
|
# Create node with inexistent domain
|
|
|
|
|
try:
|
|
|
|
|
let node = newTestWakuNode(
|
|
|
|
|
nodeKey,
|
|
|
|
|
bindIp, bindPort,
|
|
|
|
|
dns4DomainName = some(inexistentDomain))
|
|
|
|
|
except Exception as e:
|
|
|
|
|
inexistentDomainErr = e.msg
|
|
|
|
|
|
|
|
|
|
# Create node with invalid domain
|
|
|
|
|
try:
|
|
|
|
|
let node = newTestWakuNode(
|
|
|
|
|
nodeKey,
|
|
|
|
|
bindIp, bindPort,
|
|
|
|
|
dns4DomainName = some(invalidDomain))
|
|
|
|
|
except Exception as e:
|
|
|
|
|
invalidDomainErr = e.msg
|
|
|
|
|
|
|
|
|
|
# Check that exceptions were raised in both cases
|
|
|
|
|
check:
|
|
|
|
|
inexistentDomainErr == expectedError
|
|
|
|
|
invalidDomainErr == expectedError
|
2023-01-26 10:18:30 +00:00
|
|
|
|
|
2022-10-28 13:12:06 +00:00
|
|
|
|
asyncTest "Agent string is set and advertised correctly":
|
|
|
|
|
let
|
|
|
|
|
# custom agent string
|
|
|
|
|
expectedAgentString1 = "node1-agent-string"
|
|
|
|
|
|
|
|
|
|
# bump when updating nim-libp2p
|
|
|
|
|
expectedAgentString2 = "nim-libp2p/0.0.1"
|
|
|
|
|
let
|
|
|
|
|
# node with custom agent string
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(61014),
|
2022-10-28 13:12:06 +00:00
|
|
|
|
agentString = some(expectedAgentString1))
|
|
|
|
|
|
|
|
|
|
# node with default agent string from libp2p
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(61016))
|
2022-10-28 13:12:06 +00:00
|
|
|
|
|
|
|
|
|
await node1.start()
|
|
|
|
|
await node1.mountRelay()
|
|
|
|
|
|
|
|
|
|
await node2.start()
|
|
|
|
|
await node2.mountRelay()
|
|
|
|
|
|
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
await node2.connectToNodes(@[node1.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
|
|
|
|
|
let node1Agent = node2.switch.peerStore[AgentBook][node1.switch.peerInfo.toRemotePeerInfo().peerId]
|
|
|
|
|
let node2Agent = node1.switch.peerStore[AgentBook][node2.switch.peerInfo.toRemotePeerInfo().peerId]
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
node1Agent == expectedAgentString1
|
|
|
|
|
node2Agent == expectedAgentString2
|
|
|
|
|
|
2023-01-26 10:18:30 +00:00
|
|
|
|
await allFutures(node1.stop(), node2.stop())
|
|
|
|
|
|
|
|
|
|
asyncTest "Custom multiaddresses are set and advertised correctly":
|
|
|
|
|
let
|
|
|
|
|
# custom multiaddress
|
|
|
|
|
expectedMultiaddress1 = MultiAddress.init("/ip4/200.200.200.200/tcp/1234").get()
|
|
|
|
|
|
|
|
|
|
# Note: this could have been done with a single node, but it is useful to
|
|
|
|
|
# have two nodes to check that the multiaddress is advertised correctly
|
|
|
|
|
let
|
|
|
|
|
# node with custom multiaddress
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey1 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(61018),
|
2023-01-26 10:18:30 +00:00
|
|
|
|
extMultiAddrs = @[expectedMultiaddress1])
|
|
|
|
|
|
|
|
|
|
# node with default multiaddress
|
2023-02-13 10:43:49 +00:00
|
|
|
|
nodeKey2 = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(61020))
|
2023-01-26 10:18:30 +00:00
|
|
|
|
|
|
|
|
|
await node1.start()
|
|
|
|
|
await node1.mountRelay()
|
|
|
|
|
|
|
|
|
|
await node2.start()
|
|
|
|
|
await node2.mountRelay()
|
|
|
|
|
|
|
|
|
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
await node2.connectToNodes(@[node1.switch.peerInfo.toRemotePeerInfo()])
|
|
|
|
|
|
|
|
|
|
let node1MultiAddrs = node2.switch.peerStore[AddressBook][node1.switch.peerInfo.toRemotePeerInfo().peerId]
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
node1MultiAddrs.contains(expectedMultiaddress1)
|
|
|
|
|
|
|
|
|
|
await allFutures(node1.stop(), node2.stop())
|
2023-02-09 15:59:29 +00:00
|
|
|
|
|
|
|
|
|
asyncTest "Function fetchPeerExchangePeers succesfully exchanges px peers":
|
|
|
|
|
let
|
2023-12-14 06:16:39 +00:00
|
|
|
|
node1 = newTestWakuNode(generateSecp256k1Key(), parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
|
node2 = newTestWakuNode(generateSecp256k1Key(), parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-09 15:59:29 +00:00
|
|
|
|
|
|
|
|
|
# Start and mount peer exchange
|
|
|
|
|
await allFutures([node1.start(), node2.start()])
|
|
|
|
|
await allFutures([node1.mountPeerExchange(), node2.mountPeerExchange()])
|
|
|
|
|
|
|
|
|
|
# Mock that we discovered a node (to avoid running discv5)
|
|
|
|
|
var enr = enr.Record()
|
|
|
|
|
require enr.fromUri("enr:-Iu4QGNuTvNRulF3A4Kb9YHiIXLr0z_CpvWkWjWKU-o95zUPR_In02AWek4nsSk7G_-YDcaT4bDRPzt5JIWvFqkXSNcBgmlkgnY0gmlwhE0WsGeJc2VjcDI1NmsxoQKp9VzU2FAh7fwOwSpg1M_Ekz4zzl0Fpbg6po2ZwgVwQYN0Y3CC6mCFd2FrdTIB")
|
|
|
|
|
node2.wakuPeerExchange.enrCache.add(enr)
|
|
|
|
|
|
|
|
|
|
# Set node2 as service peer (default one) for px protocol
|
|
|
|
|
node1.peerManager.addServicePeer(node2.peerInfo.toRemotePeerInfo(), WakuPeerExchangeCodec)
|
|
|
|
|
|
|
|
|
|
# Request 1 peer from peer exchange protocol
|
|
|
|
|
await node1.fetchPeerExchangePeers(1)
|
|
|
|
|
|
|
|
|
|
# Check that the peer ended up in the peerstore
|
|
|
|
|
let rpInfo = enr.toRemotePeerInfo.get()
|
|
|
|
|
check:
|
|
|
|
|
node1.peerManager.peerStore.peers.anyIt(it.peerId == rpInfo.peerId)
|
|
|
|
|
node1.peerManager.peerStore.peers.anyIt(it.addrs == rpInfo.addrs)
|