2022-09-06 14:05:06 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
stew/results,
|
|
|
|
testutils/unittests,
|
|
|
|
libp2p/multiaddress,
|
|
|
|
libp2p/peerid,
|
|
|
|
libp2p/errors
|
|
|
|
import
|
2023-08-09 17:11:50 +00:00
|
|
|
../../waku/waku_core
|
2023-04-24 14:37:54 +00:00
|
|
|
|
|
|
|
suite "Waku Core - Peers":
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "Peer info parses correctly":
|
2023-04-24 14:37:54 +00:00
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/ip4/127.0.0.1/tcp/65002/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
## When
|
2023-04-12 09:29:11 +00:00
|
|
|
let remotePeerInfoRes = parsePeerInfo(address)
|
|
|
|
require remotePeerInfoRes.isOk()
|
|
|
|
|
|
|
|
let remotePeerInfo = remotePeerInfoRes.value
|
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
$(remotePeerInfo.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
|
|
|
$(remotePeerInfo.addrs[0][0].tryGet()) == "/ip4/127.0.0.1"
|
2022-11-03 13:47:56 +00:00
|
|
|
$(remotePeerInfo.addrs[0][1].tryGet()) == "/tcp/65002"
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
test "DNS multiaddrs parsing - dns peer":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/dns/localhost/tcp/65012/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
## When
|
2023-04-12 09:29:11 +00:00
|
|
|
let dnsPeerRes = parsePeerInfo(address)
|
|
|
|
require dnsPeerRes.isOk()
|
|
|
|
|
|
|
|
let dnsPeer = dnsPeerRes.value
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
$(dnsPeer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
|
|
|
$(dnsPeer.addrs[0][0].tryGet()) == "/dns/localhost"
|
2022-11-03 13:47:56 +00:00
|
|
|
$(dnsPeer.addrs[0][1].tryGet()) == "/tcp/65012"
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "DNS multiaddrs parsing - dnsaddr peer":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/dnsaddr/localhost/tcp/65022/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
## When
|
2023-04-12 09:29:11 +00:00
|
|
|
let dnsAddrPeerRes = parsePeerInfo(address)
|
|
|
|
require dnsAddrPeerRes.isOk()
|
|
|
|
|
|
|
|
let dnsAddrPeer = dnsAddrPeerRes.value
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
$(dnsAddrPeer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
|
|
|
$(dnsAddrPeer.addrs[0][0].tryGet()) == "/dnsaddr/localhost"
|
2022-11-03 13:47:56 +00:00
|
|
|
$(dnsAddrPeer.addrs[0][1].tryGet()) == "/tcp/65022"
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "DNS multiaddrs parsing - dns4 peer":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/dns4/localhost/tcp/65032/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
## When
|
2023-04-12 09:29:11 +00:00
|
|
|
let dns4PeerRes = parsePeerInfo(address)
|
|
|
|
require dns4PeerRes.isOk()
|
|
|
|
|
|
|
|
let dns4Peer = dns4PeerRes.value
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
$(dns4Peer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
|
|
|
$(dns4Peer.addrs[0][0].tryGet()) == "/dns4/localhost"
|
2022-11-03 13:47:56 +00:00
|
|
|
$(dns4Peer.addrs[0][1].tryGet()) == "/tcp/65032"
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
test "DNS multiaddrs parsing - dns6 peer":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/dns6/localhost/tcp/65042/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
## When
|
2023-04-12 09:29:11 +00:00
|
|
|
let dns6PeerRes = parsePeerInfo(address)
|
|
|
|
require dns6PeerRes.isOk()
|
|
|
|
|
|
|
|
let dns6Peer = dns6PeerRes.value
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
$(dns6Peer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
|
|
|
$(dns6Peer.addrs[0][0].tryGet()) == "/dns6/localhost"
|
2022-11-03 13:47:56 +00:00
|
|
|
$(dns6Peer.addrs[0][1].tryGet()) == "/tcp/65042"
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "Multiaddr parsing should fail with invalid address":
|
|
|
|
## Given
|
|
|
|
let address = "/p2p/$UCH GIBBER!SH"
|
|
|
|
|
|
|
|
## Then
|
2023-04-12 09:29:11 +00:00
|
|
|
check:
|
|
|
|
parsePeerInfo(address).isErr()
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "Multiaddr parsing should fail with leading whitespace":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = " /ip4/127.0.0.1/tcp/65062/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2023-04-12 09:29:11 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
## Then
|
2023-04-12 09:29:11 +00:00
|
|
|
check:
|
|
|
|
parsePeerInfo(address).isErr()
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "Multiaddr parsing should fail with trailing whitespace":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/ip4/127.0.0.1/tcp/65072/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc "
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
## Then
|
2023-04-12 09:29:11 +00:00
|
|
|
check:
|
|
|
|
parsePeerInfo(address).isErr()
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "Multiaddress parsing should fail with invalid IP address":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/ip4/127.0.0.0.1/tcp/65082/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
## Then
|
2023-04-12 09:29:11 +00:00
|
|
|
check:
|
|
|
|
parsePeerInfo(address).isErr()
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "Multiaddress parsing should fail with no peer ID":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/ip4/127.0.0.1/tcp/65092"
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
# Then
|
2023-04-12 09:29:11 +00:00
|
|
|
check:
|
|
|
|
parsePeerInfo(address).isErr()
|
2022-09-06 14:05:06 +00:00
|
|
|
|
|
|
|
test "Multiaddress parsing should fail with unsupported transport":
|
|
|
|
## Given
|
2022-11-03 13:47:56 +00:00
|
|
|
let address = "/ip4/127.0.0.1/udp/65102/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
|
2023-04-24 14:37:54 +00:00
|
|
|
|
2022-09-06 14:05:06 +00:00
|
|
|
## Then
|
2023-04-12 09:29:11 +00:00
|
|
|
check:
|
|
|
|
parsePeerInfo(address).isErr()
|
2022-09-06 14:05:06 +00:00
|
|
|
|