-
Notifications
You must be signed in to change notification settings - Fork 847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handling IllegalArgumentException caused by Discovery Disabled Nodes in Endpoint.fromEnode #7937
base: main
Are you sure you want to change the base?
Changes from 6 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
|
@@ -45,6 +47,8 @@ | |
import org.hyperledger.besu.ethereum.p2p.permissions.PeerPermissionsDenylist; | ||
import org.hyperledger.besu.plugin.data.EnodeURL; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
@@ -57,12 +61,15 @@ | |
import org.apache.tuweni.units.bigints.UInt64; | ||
import org.ethereum.beacon.discovery.schema.NodeRecord; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class PeerDiscoveryAgentTest { | ||
|
||
private static final int BROADCAST_TCP_PORT = 30303; | ||
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM = | ||
Suppliers.memoize(SignatureAlgorithmFactory::getInstance); | ||
private static final Logger log = LoggerFactory.getLogger(PeerDiscoveryAgentTest.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generally don't need loggers in tests |
||
private final PeerDiscoveryTestHelper helper = new PeerDiscoveryTestHelper(); | ||
|
||
@Test | ||
|
@@ -898,6 +905,27 @@ public void assertHostCorrectlyRevertsOnIgnoredPacketFrom() { | |
assertThat(PeerDiscoveryAgent.deriveHost(source, mockWellFormed)).isEqualTo(routableHost); | ||
} | ||
|
||
@Test | ||
void testFromEnodeWithDiscoveryDisabled() { | ||
EnodeURL enodeWithNoDiscovery = mock(EnodeURL.class); | ||
when(enodeWithNoDiscovery.getDiscoveryPort()).thenReturn(Optional.empty()); | ||
when(enodeWithNoDiscovery.getListeningPort()).thenReturn(Optional.of(8545)); | ||
try { | ||
when(enodeWithNoDiscovery.getIp()).thenReturn(InetAddress.getByName("127.0.0.1")); | ||
} | ||
catch (UnknownHostException e) { | ||
log.debug("Failed to resolve the Host Address "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prob wouldn't catch this exception in the test, you can mark the test method throws that ex. (what would happen if this exception occurred? would the test pass or fail? should it pass or fail?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe this will significantly impact the test's primary function. Should I proceed with Throws it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes I would keep this logic out of the test altogether |
||
} | ||
Endpoint result = Endpoint.fromEnode(enodeWithNoDiscovery); | ||
|
||
assertEquals("127.0.0.1", result.getHost()); | ||
|
||
assertEquals(30303, result.getUdpPort()); | ||
|
||
assertEquals(Optional.empty(), result.getTcpPort()); | ||
} | ||
|
||
|
||
protected void bondViaIncomingPing( | ||
final MockPeerDiscoveryAgent agent, final MockPeerDiscoveryAgent otherNode) { | ||
final Packet pingPacket = helper.createPingPacket(otherNode, agent); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all upper case field names convention for statics