Skip to content

Commit

Permalink
squashme: makes safer test
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajpiar committed Apr 2, 2024
1 parent bec94de commit 1354af3
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions rskj-core/src/test/java/co/rsk/net/discovery/PeerExplorerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ void handlePongMessage() throws Exception {
assertEquals(1, peerExplorer.getNodes().size());

// Verify that only IP is being sent, not hostname
for (Node discoveredNode : peerExplorer.getNodes()) {
assertNotEquals(HOST_1, discoveredNode.getHost());
}
assertNoHostnameFromDiscovery(peerExplorer);

peerExplorer.dispose();
}
Expand Down Expand Up @@ -432,9 +430,7 @@ void handleFindNodeMessage() throws Exception {
assertEquals(1, neighborsPeerMessage.getNodes().size());

// Verify that only IP is being sent, not hostname
for (Node discoveredNode : neighborsPeerMessage.getNodes()) {
assertNotEquals(HOST_1, discoveredNode.getHost());
}
assertNoHostnameFromDiscovery(peerExplorer);

peerExplorer.dispose();
}
Expand Down Expand Up @@ -737,4 +733,17 @@ private static InetAddress parseAddress(String host) {
throw new IllegalArgumentException(e);
}
}

private static void assertNoHostnameFromDiscovery(PeerExplorer peerExplorer) {
ECKey key = ECKey.fromPrivate(Hex.decode(KEY_1)).decompress();
Node localhostNode = new Node(key.getNodeId(), HOST_1, PORT_1); // more stable if loopback address overrides
String localhostIP = localhostNode.getAddress().getAddress().getHostAddress();
Optional<Node> discoveredNode = peerExplorer.getNodes()
.stream().filter((Node node) -> Objects.equals(
node.getAddress().getAddress().getHostAddress(),
localhostIP))
.findFirst();
assertTrue(discoveredNode.isPresent());
assertNotEquals(HOST_1, discoveredNode.get().getHost());
}
}

0 comments on commit 1354af3

Please sign in to comment.