From 0c676418b849e0eaf1ac7e5012f1a2b5826e2c19 Mon Sep 17 00:00:00 2001 From: Juraj Piar Date: Mon, 1 Apr 2024 10:31:16 +0100 Subject: [PATCH] squashme: makes safer test --- .../rsk/net/discovery/PeerExplorerTest.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/rskj-core/src/test/java/co/rsk/net/discovery/PeerExplorerTest.java b/rskj-core/src/test/java/co/rsk/net/discovery/PeerExplorerTest.java index b9e3bbf65eb..44364c36287 100644 --- a/rskj-core/src/test/java/co/rsk/net/discovery/PeerExplorerTest.java +++ b/rskj-core/src/test/java/co/rsk/net/discovery/PeerExplorerTest.java @@ -265,9 +265,15 @@ 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()); - } + Optional discoveredNode = peerExplorer.getNodes().stream().filter((Node aNode) -> { + String nodeIP = aNode.getAddress().getAddress().getHostAddress(); + Node localhostNode = new Node(key1.getNodeId(), HOST_1, PORT_1); + String localhostIP = localhostNode.getAddress().getAddress().getHostAddress(); + + return Objects.equals(nodeIP, localhostIP); + }).findFirst(); + assertTrue(discoveredNode.isPresent()); + assertNotEquals(HOST_1, discoveredNode.get().getHost()); peerExplorer.dispose(); } @@ -432,9 +438,15 @@ 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()); - } + Optional discoveredNode = peerExplorer.getNodes().stream().filter((Node aNode) -> { + String nodeIP = aNode.getAddress().getAddress().getHostAddress(); + Node localhostNode = new Node(key1.getNodeId(), HOST_1, PORT_1); + String localhostIP = localhostNode.getAddress().getAddress().getHostAddress(); + + return Objects.equals(nodeIP, localhostIP); + }).findFirst(); + assertTrue(discoveredNode.isPresent()); + assertNotEquals(HOST_1, discoveredNode.get().getHost()); peerExplorer.dispose(); }