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

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed May 14, 2019
1 parent 78b2c93 commit d3372f0
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.net;

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

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.util.NetworkUtility;

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;
}

@Override
public void verify(final Node node) {
final Map<String, Map<String, String>> result = node.execute(transaction);

assertThat(validateHost(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();
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();
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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.AwaitNetPeerCount;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.AwaitNetPeerCountException;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetServicesReturnsAllServicesAsActive;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionConnectionException;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionConnectionExceptionWithCause;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionIsNotBlank;
Expand All @@ -32,9 +33,8 @@ public Net(final NetTransactions transactions) {
this.transactions = transactions;
}

public Condition netServices() {

return transactions.netServices();
public Condition netServicesAllActive() {
return new ExpectNetServicesReturnsAllServicesAsActive(transactions.netServices());
}

public Condition netVersion() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net;

import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.response.NetVersion;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NetServicesJsonRpcRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;

import java.util.Map;

import org.web3j.protocol.core.Request;

public class NetServicesTransaction implements Transaction<Map<String, Map<String, String>>> {

NetServicesTransaction() {}
NetServicesTransaction() {}

@Override
public Map<String, Map<String, String>> execute(
final JsonRequestFactories requestFactories) {
NetServicesJsonRpcRequestFactory.NetServicesResponse netServicesResponse = null;
try {
NetServicesJsonRpcRequestFactory netServicesJsonRpcRequestFactory = requestFactories.netServices();
Request<?, NetServicesJsonRpcRequestFactory.NetServicesResponse> request =
netServicesJsonRpcRequestFactory.netServices();
netServicesResponse = request.send();
} catch (final Exception ignored) {
}
return netServicesResponse.getResult();
@Override
public Map<String, Map<String, String>> execute(final JsonRequestFactories requestFactories) {
NetServicesJsonRpcRequestFactory.NetServicesResponse netServicesResponse = null;
try {
NetServicesJsonRpcRequestFactory netServicesJsonRpcRequestFactory =
requestFactories.netServices();
Request<?, NetServicesJsonRpcRequestFactory.NetServicesResponse> request =
netServicesJsonRpcRequestFactory.netServices();
netServicesResponse = request.send();
} catch (final Exception ignored) {
}
return netServicesResponse.getResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public NetVersionTransaction netVersion() {
public NetServicesTransaction netServices() {
return new NetServicesTransaction();
}

public NetPeerCountTransaction peerCount() {
return new NetPeerCountTransaction();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@
*/
package tech.pegasys.pantheon.tests.acceptance.jsonrpc;

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

import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.Cluster;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder;

import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

Expand All @@ -46,23 +41,8 @@ public void setUp() throws Exception {

@Test
public void shouldIndicateNetServicesEnabled() {
final Map<String, Map<String, String>> result = netServices.addPeer(nodeA);
final Map<String, Map<String, String>> expectation = new HashMap<>();
final Map<String, String> constituentMap =
new HashMap() {
{
put("host", "127.0.0.1");
put("port", "0");
}
};
expectation.put("jsonrpc", constituentMap);
expectation.put("ws", constituentMap);
expectation.put("p2p", constituentMap);
assertThat(expectation.get("jsonrpc").get("host")).isEqualTo(result.get("jsonrpc").get("host"));
assertThat(expectation.get("jsonrpc").get("port")).isEqualTo(result.get("jsonrpc").get("port"));
assertThat(expectation.get("ws").get("host")).isEqualTo(result.get("ws").get("host"));
assertThat(expectation.get("ws").get("port")).isEqualTo(result.get("ws").get("port"));
assertThat(expectation.get("p2p").get("host")).isEqualTo(result.get("p2p").get("host"));
nodeA.verify(net.netServicesAllActive());
nodeB.verify(net.netServicesAllActive());
}

@Test
Expand Down

0 comments on commit d3372f0

Please sign in to comment.