This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAN-2577] Integration Integration test(s) on p2p of 'net_services' (#…
- Loading branch information
1 parent
1037eb5
commit 8b26d3a
Showing
10 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...theon/tests/acceptance/dsl/condition/net/ExpectNetServicesReturnsAllServicesAsActive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Arrays; | ||
import java.util.Map; | ||
|
||
import com.google.common.net.InetAddresses; | ||
|
||
public class ExpectNetServicesReturnsAllServicesAsActive implements Condition { | ||
|
||
private final NetServicesTransaction transaction; | ||
|
||
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(result.keySet()) | ||
.containsExactlyInAnyOrderElementsOf(Arrays.asList("p2p", "jsonrpc", "ws")); | ||
|
||
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(InetAddresses.isUriInetAddress(result.get("ws").get("host"))).isTrue(); | ||
final int wsPort = Integer.valueOf(result.get("ws").get("port")); | ||
// TODO: Port should not be 0-valued. Refer to PAN-2703 | ||
assertThat(NetworkUtility.isValidPort(p2pPort) || wsPort == 0).isTrue(); | ||
|
||
assertThat(InetAddresses.isUriInetAddress(result.get("jsonrpc").get("host"))).isTrue(); | ||
final int jsonRpcPort = Integer.valueOf(result.get("jsonrpc").get("port")); | ||
// TODO: Port should not be 0-valued. Refer to PAN-2703 | ||
assertThat(NetworkUtility.isValidPort(p2pPort) || jsonRpcPort == 0).isTrue(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...antheon/tests/acceptance/dsl/condition/net/ExpectNetServicesReturnsOnlyJsonRpcActive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.Collections; | ||
import java.util.Map; | ||
|
||
import com.google.common.net.InetAddresses; | ||
|
||
public class ExpectNetServicesReturnsOnlyJsonRpcActive implements Condition { | ||
|
||
private final NetServicesTransaction transaction; | ||
|
||
public ExpectNetServicesReturnsOnlyJsonRpcActive(final NetServicesTransaction transaction) { | ||
this.transaction = transaction; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
final Map<String, Map<String, String>> result = node.execute(transaction); | ||
assertThat(result.keySet()) | ||
.containsExactlyInAnyOrderElementsOf(Collections.singletonList("jsonrpc")); | ||
|
||
assertThat(InetAddresses.isUriInetAddress(result.get("jsonrpc").get("host"))).isTrue(); | ||
final int jsonrpcPort = Integer.valueOf(result.get("jsonrpc").get("port")); | ||
// TODO: Port should not be 0-valued. Refer to PAN-2703 | ||
assertThat(NetworkUtility.isValidPort(jsonrpcPort) || jsonrpcPort == 0).isTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ech/pegasys/pantheon/tests/acceptance/dsl/transaction/CustomNetJsonRpcRequestFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.web3j.protocol.Web3jService; | ||
import org.web3j.protocol.core.Request; | ||
import org.web3j.protocol.core.Response; | ||
|
||
public class CustomNetJsonRpcRequestFactory { | ||
|
||
public static class NetServicesResponse extends Response<Map<String, Map<String, String>>> {} | ||
|
||
private final Web3jService web3jService; | ||
|
||
public CustomNetJsonRpcRequestFactory(final Web3jService web3jService) { | ||
this.web3jService = web3jService; | ||
} | ||
|
||
public Request<?, NetServicesResponse> netServices() { | ||
return new Request<>( | ||
"net_services", Collections.emptyList(), web3jService, NetServicesResponse.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...va/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetServicesTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 tech.pegasys.pantheon.tests.acceptance.dsl.transaction.CustomNetJsonRpcRequestFactory; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; | ||
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() {} | ||
|
||
@Override | ||
public Map<String, Map<String, String>> execute(final JsonRequestFactories requestFactories) { | ||
CustomNetJsonRpcRequestFactory.NetServicesResponse netServicesResponse = null; | ||
try { | ||
final CustomNetJsonRpcRequestFactory netServicesJsonRpcRequestFactory = | ||
requestFactories.customNet(); | ||
final Request<?, CustomNetJsonRpcRequestFactory.NetServicesResponse> request = | ||
netServicesJsonRpcRequestFactory.netServices(); | ||
|
||
netServicesResponse = request.send(); | ||
} catch (final Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
return netServicesResponse.getResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...c/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/NetServicesAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.jsonrpc; | ||
|
||
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 org.junit.Test; | ||
|
||
public class NetServicesAcceptanceTest extends AcceptanceTestBase { | ||
|
||
private Cluster noDiscoveryCluster; | ||
|
||
private Node nodeA; | ||
private Node nodeB; | ||
|
||
@Test | ||
public void shouldIndicateNetServicesEnabled() throws Exception { | ||
final ClusterConfiguration clusterConfiguration = | ||
new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); | ||
noDiscoveryCluster = new Cluster(clusterConfiguration, net); | ||
nodeA = pantheon.createArchiveNodeNetServicesEnabled("nodeA"); | ||
nodeB = pantheon.createArchiveNodeNetServicesEnabled("nodeB"); | ||
noDiscoveryCluster.start(nodeA, nodeB); | ||
|
||
nodeA.verify(net.netServicesAllActive()); | ||
nodeB.verify(net.netServicesAllActive()); | ||
} | ||
|
||
@Test | ||
public void shouldNotDisplayDisabledServices() throws Exception { | ||
final ClusterConfiguration clusterConfiguration = | ||
new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); | ||
noDiscoveryCluster = new Cluster(clusterConfiguration, net); | ||
nodeA = pantheon.createArchiveNodeNetServicesDisabled("nodeA"); | ||
nodeB = pantheon.createArchiveNodeNetServicesDisabled("nodeB"); | ||
noDiscoveryCluster.start(nodeA, nodeB); | ||
|
||
nodeA.verify(net.netServicesOnlyJsonRpcEnabled()); | ||
nodeB.verify(net.netServicesOnlyJsonRpcEnabled()); | ||
} | ||
} |