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 1, 2024
1 parent bec94de commit ffac707
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 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 @@ -81,6 +81,18 @@ class PeerExplorerTest {
private static final int NETWORK_ID1 = 1;
private static final int NETWORK_ID2 = 2;

private static void assertNoHostnameFromDiscovery(ECKey key1, PeerExplorer peerExplorer) {
Node localhostNode = new Node(key1.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());
}

@Test
void sendInitialMessageToNodesNoNodes() {
Node node = new Node(new ECKey().getNodeId(), HOST_2, PORT_2);
Expand Down Expand Up @@ -265,9 +277,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(key1, peerExplorer);

peerExplorer.dispose();
}
Expand Down Expand Up @@ -432,9 +442,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(key1, peerExplorer);

peerExplorer.dispose();
}
Expand Down

0 comments on commit ffac707

Please sign in to comment.