|
|
|
@ -26,14 +26,14 @@ public class EnodeURLTest { |
|
|
|
|
private final String VALID_NODE_ID = |
|
|
|
|
"6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"; |
|
|
|
|
private final String IPV4_ADDRESS = "192.168.0.1"; |
|
|
|
|
private final String IPV6_FULL_ADDRESS = "[2001:db8:85a3:0:0:8a2e:0370:7334]"; |
|
|
|
|
private final String IPV6_COMPACT_ADDRESS = "[2001:db8:85a3::8a2e:0370:7334]"; |
|
|
|
|
private final String IPV6_FULL_ADDRESS = "[2001:db8:85a3:0:0:8a2e:370:7334]"; |
|
|
|
|
private final String IPV6_COMPACT_ADDRESS = "[2001:db8:85a3::8a2e:370:7334]"; |
|
|
|
|
private final int P2P_PORT = 30303; |
|
|
|
|
private final int DISCOVERY_PORT = 30301; |
|
|
|
|
private final String DISCOVERY_QUERY = "discport=" + DISCOVERY_PORT; |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void new_withMatchingDiscoveryAndListeningPorts() { |
|
|
|
|
public void build_withMatchingDiscoveryAndListeningPorts() { |
|
|
|
|
final EnodeURL enode = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
@ -41,13 +41,12 @@ public class EnodeURLTest { |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(OptionalInt.of(P2P_PORT)) |
|
|
|
|
.build(); |
|
|
|
|
assertThat(enode.getListeningPort()).isEqualTo(P2P_PORT); |
|
|
|
|
// A discovery port matching the listening port should not be explicitly specified
|
|
|
|
|
assertThat(enode.getDiscoveryPort()).isEmpty(); |
|
|
|
|
assertThat(enode.getListeningPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enode.getDiscoveryPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void new_withNonMatchingDiscoveryAndListeningPorts() { |
|
|
|
|
public void build_withNonMatchingDiscoveryAndListeningPorts() { |
|
|
|
|
final EnodeURL enode = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
@ -55,9 +54,8 @@ public class EnodeURLTest { |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(OptionalInt.of(DISCOVERY_PORT)) |
|
|
|
|
.build(); |
|
|
|
|
assertThat(enode.getListeningPort()).isEqualTo(P2P_PORT); |
|
|
|
|
// A discovery port matching the listening port should not be explicitly specified
|
|
|
|
|
assertThat(enode.getDiscoveryPort()).isEqualTo(OptionalInt.of(DISCOVERY_PORT)); |
|
|
|
|
assertThat(enode.getListeningPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enode.getDiscoveryPortOrZero()).isEqualTo(DISCOVERY_PORT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -75,6 +73,7 @@ public class EnodeURLTest { |
|
|
|
|
final EnodeURL enodeURL = EnodeURL.fromString(enodeURLString); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL).isEqualTo(expectedEnodeURL); |
|
|
|
|
assertThat(enodeURL.toString()).isEqualTo(enodeURLString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -83,13 +82,14 @@ public class EnodeURLTest { |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryAndListeningPorts(P2P_PORT) |
|
|
|
|
.build(); |
|
|
|
|
final String enodeURLString = "enode://" + VALID_NODE_ID + "@" + IPV4_ADDRESS + ":" + P2P_PORT; |
|
|
|
|
|
|
|
|
|
final EnodeURL enodeURL = EnodeURL.fromString(enodeURLString); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL).isEqualTo(expectedEnodeURL); |
|
|
|
|
assertThat(enodeURL.toString()).isEqualTo(enodeURLString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -117,7 +117,7 @@ public class EnodeURLTest { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromString_ithIPV6InCompactFormShouldBuildExpectedEnodeURLObject() { |
|
|
|
|
public void fromString_withIPV6InCompactFormShouldBuildExpectedEnodeURLObject() { |
|
|
|
|
final EnodeURL expectedEnodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
@ -138,6 +138,54 @@ public class EnodeURLTest { |
|
|
|
|
final EnodeURL enodeURL = EnodeURL.fromString(enodeURLString); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL).isEqualTo(expectedEnodeURL); |
|
|
|
|
assertThat(enodeURL.toString()).isEqualTo(enodeURLString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromString_with0ValuedDiscoveryPort() { |
|
|
|
|
final String query = "discport=0"; |
|
|
|
|
final String enodeURLString = |
|
|
|
|
"enode://" + VALID_NODE_ID + "@" + IPV6_COMPACT_ADDRESS + ":" + P2P_PORT + "?" + query; |
|
|
|
|
|
|
|
|
|
EnodeURL enodeURL = EnodeURL.fromString(enodeURLString); |
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat("[" + enodeURL.getIpAsString() + "]").isEqualTo(IPV6_FULL_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPort()).isEqualTo(OptionalInt.of(P2P_PORT)); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isTrue(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.toString()).isEqualTo(enodeURLString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromString_with0ValuedListeningPort() { |
|
|
|
|
final String enodeURLString = "enode://" + VALID_NODE_ID + "@" + IPV4_ADDRESS + ":" + 0; |
|
|
|
|
|
|
|
|
|
EnodeURL enodeURL = EnodeURL.fromString(enodeURLString); |
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isFalse(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.toString()).isEqualTo(enodeURLString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromString_with0ValuedListeningPortAndExplicit0ValuedDiscPort() { |
|
|
|
|
final String query = "discport=0"; |
|
|
|
|
final String enodeURLString = |
|
|
|
|
"enode://" + VALID_NODE_ID + "@" + IPV4_ADDRESS + ":" + 0 + "?" + query; |
|
|
|
|
|
|
|
|
|
EnodeURL enodeURL = EnodeURL.fromString(enodeURLString); |
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isFalse(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -318,6 +366,15 @@ public class EnodeURLTest { |
|
|
|
|
.hasMessageContaining("Invalid empty value."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromStringInvalidNodeIdLengthHasDescriptiveMessage() { |
|
|
|
|
String invalidEnodeURL = |
|
|
|
|
String.format("enode://%s@%s:%d", VALID_NODE_ID.substring(1), IPV4_ADDRESS, P2P_PORT); |
|
|
|
|
assertThatThrownBy(() -> EnodeURL.fromString(invalidEnodeURL)) |
|
|
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
|
|
.hasMessageContaining("node ID must have exactly 128 hexadecimal"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void toURI_WithDiscoveryPortCreateExpectedURI() { |
|
|
|
|
final String enodeURLString = |
|
|
|
@ -338,41 +395,333 @@ public class EnodeURLTest { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void getEffectiveDiscoveryPort_withMatchingDiscoveryAndListeningPorts() { |
|
|
|
|
final EnodeURL enode = |
|
|
|
|
public void builder_setEachPortExplicitly() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(OptionalInt.of(P2P_PORT)) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
assertThat(enode.getListeningPort()).isEqualTo(P2P_PORT); |
|
|
|
|
// A discovery port matching the listening port should not be explicitly specified
|
|
|
|
|
assertThat(enode.getDiscoveryPort()).isEmpty(); |
|
|
|
|
assertThat(enode.getEffectiveDiscoveryPort()).isEqualTo(P2P_PORT); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(DISCOVERY_PORT); |
|
|
|
|
assertThat(enodeURL.isListening()).isTrue(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void getEffectiveDiscoveryPort_withDistinctDiscoveryAndListeningPorts() { |
|
|
|
|
final EnodeURL enode = |
|
|
|
|
public void builder_setPortsTogether() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.discoveryAndListeningPorts(P2P_PORT) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.isListening()).isTrue(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_setDefaultPorts() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder().nodeId(VALID_NODE_ID).ipAddress(IPV4_ADDRESS).useDefaultPorts().build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(EnodeURL.DEFAULT_LISTENING_PORT); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(EnodeURL.DEFAULT_LISTENING_PORT); |
|
|
|
|
assertThat(enodeURL.isListening()).isTrue(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_discoveryDisabled() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(OptionalInt.of(DISCOVERY_PORT)) |
|
|
|
|
.disableDiscovery() |
|
|
|
|
.build(); |
|
|
|
|
assertThat(enode.getListeningPort()).isEqualTo(P2P_PORT); |
|
|
|
|
// A discovery port matching the listening port should not be explicitly specified
|
|
|
|
|
assertThat(enode.getDiscoveryPort()).isEqualTo(OptionalInt.of(DISCOVERY_PORT)); |
|
|
|
|
assertThat(enode.getEffectiveDiscoveryPort()).isEqualTo(DISCOVERY_PORT); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isTrue(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromStringInvalidNodeIdLengthHasDescriptiveMessage() { |
|
|
|
|
String invalidEnodeURL = |
|
|
|
|
String.format("enode://%s@%s:%d", VALID_NODE_ID.substring(1), IPV4_ADDRESS, P2P_PORT); |
|
|
|
|
assertThatThrownBy(() -> EnodeURL.fromString(invalidEnodeURL)) |
|
|
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
|
|
.hasMessageContaining("node ID must have exactly 128 hexadecimal"); |
|
|
|
|
public void builder_listeningDisabled() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.discoveryPort(P2P_PORT) |
|
|
|
|
.disableListening() |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.isListening()).isFalse(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_listeningAndDiscoveryDisabled() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.disableDiscovery() |
|
|
|
|
.disableListening() |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isFalse(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_setPortsTo0() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.discoveryAndListeningPorts(0) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isFalse(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_setDiscoveryPortTo0() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.discoveryPort(0) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isTrue(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_setListeningPortTo0() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.discoveryPort(P2P_PORT) |
|
|
|
|
.listeningPort(0) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.isListening()).isFalse(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_setDiscoveryPortToEmptyValue() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.discoveryPort(OptionalInt.empty()) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.isListening()).isTrue(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_setListeningPortToEmptyValue() { |
|
|
|
|
final EnodeURL enodeURL = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.discoveryPort(P2P_PORT) |
|
|
|
|
.listeningPort(OptionalInt.empty()) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(enodeURL.getNodeId().toUnprefixedString()).isEqualTo(VALID_NODE_ID); |
|
|
|
|
assertThat(enodeURL.getIpAsString()).isEqualTo(IPV4_ADDRESS); |
|
|
|
|
assertThat(enodeURL.getListeningPortOrZero()).isEqualTo(0); |
|
|
|
|
assertThat(enodeURL.getDiscoveryPortOrZero()).isEqualTo(P2P_PORT); |
|
|
|
|
assertThat(enodeURL.isListening()).isFalse(); |
|
|
|
|
assertThat(enodeURL.isRunningDiscovery()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_discoveryNotSpecified() { |
|
|
|
|
final EnodeURL.Builder builder = |
|
|
|
|
EnodeURL.builder().nodeId(VALID_NODE_ID).ipAddress(IPV4_ADDRESS).listeningPort(P2P_PORT); |
|
|
|
|
|
|
|
|
|
assertThatThrownBy(builder::build) |
|
|
|
|
.isInstanceOf(IllegalStateException.class) |
|
|
|
|
.hasMessageContaining("Discovery port must be configured"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_listeningPortNotSpecified() { |
|
|
|
|
final EnodeURL.Builder builder = |
|
|
|
|
EnodeURL.builder().nodeId(VALID_NODE_ID).ipAddress(IPV4_ADDRESS).discoveryPort(P2P_PORT); |
|
|
|
|
|
|
|
|
|
assertThatThrownBy(builder::build) |
|
|
|
|
.isInstanceOf(IllegalStateException.class) |
|
|
|
|
.hasMessageContaining("Listening port must be configured"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_nodeIdNotSpecified() { |
|
|
|
|
final EnodeURL.Builder builder = |
|
|
|
|
EnodeURL.builder().ipAddress(IPV4_ADDRESS).discoveryAndListeningPorts(P2P_PORT); |
|
|
|
|
|
|
|
|
|
assertThatThrownBy(builder::build) |
|
|
|
|
.isInstanceOf(IllegalStateException.class) |
|
|
|
|
.hasMessageContaining("Node id must be configured"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void builder_ipNotSpecified() { |
|
|
|
|
final EnodeURL.Builder builder = |
|
|
|
|
EnodeURL.builder().nodeId(VALID_NODE_ID).discoveryAndListeningPorts(P2P_PORT); |
|
|
|
|
|
|
|
|
|
assertThatThrownBy(builder::build) |
|
|
|
|
.isInstanceOf(IllegalStateException.class) |
|
|
|
|
.hasMessageContaining("Ip address must be configured"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void sameListeningEndpoint_forMatchingEnodes() { |
|
|
|
|
final EnodeURL enodeA = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
final EnodeURL enodeB = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT + 1) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(EnodeURL.sameListeningEndpoint(enodeA, enodeB)).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void sameListeningEndpoint_differentListeningPorts() { |
|
|
|
|
final EnodeURL enodeA = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
final EnodeURL enodeB = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT + 1) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(EnodeURL.sameListeningEndpoint(enodeA, enodeB)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void sameListeningEndpoint_differentIps() { |
|
|
|
|
final EnodeURL enodeA = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV6_COMPACT_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
final EnodeURL enodeB = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(EnodeURL.sameListeningEndpoint(enodeA, enodeB)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void sameListeningEndpoint_listeningDisabledForOne() { |
|
|
|
|
final EnodeURL enodeA = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.disableListening() |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
final EnodeURL enodeB = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.listeningPort(P2P_PORT) |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(EnodeURL.sameListeningEndpoint(enodeA, enodeB)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void sameListeningEndpoint_listeningDisabledForBoth() { |
|
|
|
|
final EnodeURL enodeA = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.disableListening() |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
final EnodeURL enodeB = |
|
|
|
|
EnodeURL.builder() |
|
|
|
|
.nodeId(VALID_NODE_ID) |
|
|
|
|
.ipAddress(IPV4_ADDRESS) |
|
|
|
|
.disableListening() |
|
|
|
|
.discoveryPort(DISCOVERY_PORT) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
assertThat(EnodeURL.sameListeningEndpoint(enodeA, enodeB)).isTrue(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|