Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
InetAddresses
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed May 14, 2019
1 parent 65fbfc0 commit 2370100
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.net.InetAddresses;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetServicesTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions;
import tech.pegasys.pantheon.util.NetworkUtility;
import tech.pegasys.pantheon.util.enode.EnodeURL;

import java.util.Map;
import java.util.regex.Pattern;

public class ExpectNetServicesReturnsAllServicesAsActive implements Condition {

private final NetServicesTransaction transaction;
private final Pattern PATTERN =
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");

public ExpectNetServicesReturnsAllServicesAsActive(final NetServicesTransaction transaction) {
this.transaction = transaction;
Expand All @@ -37,23 +37,19 @@ public ExpectNetServicesReturnsAllServicesAsActive(final NetServicesTransaction
public void verify(final Node node) {
final Map<String, Map<String, String>> result = node.execute(transaction);

assertThat(validateHost(result.get("p2p").get("host"))).isTrue();
assertThat(InetAddresses.isUriInetAddress(result.get("p2p").get("host"))).isTrue();
final int p2pPort = Integer.valueOf(result.get("p2p").get("port"));
assertThat(NetworkUtility.isValidPort(p2pPort)).isTrue();

assertThat(validateHost(result.get("ws").get("host"))).isTrue();
assertThat(InetAddresses.isUriInetAddress(result.get("ws").get("host"))).isTrue();
final int wsPort = Integer.valueOf(result.get("ws").get("port"));
assertThat(NetworkUtility.isValidPort(wsPort) || wsPort == 0).isTrue();

assertThat(validateHost(result.get("jsonrpc").get("host"))).isTrue();
assertThat(InetAddresses.isUriInetAddress(result.get("jsonrpc").get("host"))).isTrue();
final int jsonRpcPort = Integer.valueOf(result.get("jsonrpc").get("port"));
assertThat(NetworkUtility.isValidPort(jsonRpcPort) || jsonRpcPort == 0).isTrue();
}

private boolean validateHost(final String ip) {
return PATTERN.matcher(ip).matches();
}

public static class ExpectNetServicesReturnsNoServicesAsActive implements Condition {

private final NetTransactions transaction;
Expand Down

0 comments on commit 2370100

Please sign in to comment.