From a064a6750ac3f54f64dc908877a526eed5028117 Mon Sep 17 00:00:00 2001 From: "S. Matthew English" Date: Mon, 13 May 2019 06:53:09 -0400 Subject: [PATCH] ~ --- .../tests/acceptance/dsl/jsonrpc/Admin.java | 68 +++++++------ .../acceptance/dsl/jsonrpc/NetServices.java | 98 +++++++------------ .../acceptance/dsl/node/PantheonNode.java | 2 +- .../NetServicesJsonRpcRequestFactory.java | 47 +++++---- .../jsonrpc/NetServicesAcceptanceTest.java | 74 +++++++++----- .../tech/pegasys/pantheon/RunnerBuilder.java | 49 +++++----- 6 files changed, 169 insertions(+), 169 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java index 6fa77f4c0d..873180eb9a 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java @@ -13,7 +13,6 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; @@ -21,44 +20,43 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; -import java.io.IOException; import java.net.URI; import org.web3j.protocol.core.Response; public class Admin { - public Condition addPeer(final Node node) { - - System.out.println("999"); - - return new Condition() { - @Override - public void verify(Node x) { - - System.out.println("888"); - - final Boolean result = - node.execute( - new Transaction() { - @Override - public Boolean execute(JsonRequestFactories requestFactories) { - - System.out.println("777"); - - Response resp = null; - try { - URI enodeUrl = ((RunnableNode) x).enodeUrl(); - resp = requestFactories.admin().adminAddPeer(enodeUrl).send(); - assertThat(resp).isNotNull(); - assertThat(resp.hasError()).isFalse(); - } catch (final Exception ignored) { - } - return resp.getResult(); - } - }); - assertThat(result).isTrue(); - } - }; - } + public Condition addPeer(final Node node) { + + System.out.println("999"); + + return new Condition() { + @Override + public void verify(Node x) { + + System.out.println("888"); + + final Boolean result = + node.execute( + new Transaction() { + @Override + public Boolean execute(JsonRequestFactories requestFactories) { + + System.out.println("777"); + + Response resp = null; + try { + URI enodeUrl = ((RunnableNode) x).enodeUrl(); + resp = requestFactories.admin().adminAddPeer(enodeUrl).send(); + assertThat(resp).isNotNull(); + assertThat(resp.hasError()).isFalse(); + } catch (final Exception ignored) { + } + return resp.getResult(); + } + }); + assertThat(result).isTrue(); + } + }; + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/NetServices.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/NetServices.java index 3b3f4cbdf4..0f1e377154 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/NetServices.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/NetServices.java @@ -1,76 +1,48 @@ +/* + * 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.jsonrpc; -import org.web3j.protocol.core.Request; -import org.web3j.protocol.core.Response; -import org.web3j.protocol.core.methods.response.NetVersion; -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.node.RunnableNode; 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.net.URI; import java.util.Map; -import static org.assertj.core.api.Assertions.assertThat; +import org.web3j.protocol.core.Request; public class NetServices { - public Condition addPeer(final Node node) { - - System.out.println("999"); - - return new Condition() { - @Override - public void verify(Node x) { - - System.out.println("888"); - - final Map> result = - node.execute( - new Transaction>>() { - @Override - public Map> execute(JsonRequestFactories requestFactories) { - - System.out.println("777"); - - NetServicesJsonRpcRequestFactory.NetServicesResponse c = null; - try { - - //System.out.println("netVersion: " + requestFactories.net().netVersion().send().getNetVersion()); - - //System.out.println("netVersion: " + requestFactories.net().netListening().send().isListening()); - - URI enodeUrl = ((RunnableNode) x).enodeUrl(); - - System.out.println("xxx"); - - NetServicesJsonRpcRequestFactory s = requestFactories.netServices(); - - System.out.println("yyy"); - - Request t = s.netServices(enodeUrl); - - System.out.println("zzz"); - - c = t.send(); - - //System.out.println("--> " + c.getResult()); - - System.out.println("aaa"); - - //resp = requestFactories.admin().adminAddPeer(enodeUrl).send(); - //assertThat(resp).isNotNull(); - //assertThat(resp.hasError()).isFalse(); - } catch (final Exception ignored) { - } - return c.getResult(); - } - }); - //assertThat(result).isTrue(); - System.out.println("--> " + result); - } - }; - } + public Map> addPeer(final Node node) { + + final Map> result = + node.execute( + new Transaction>>() { + @Override + public Map> execute( + JsonRequestFactories requestFactories) { + NetServicesJsonRpcRequestFactory.NetServicesResponse c = null; + try { + NetServicesJsonRpcRequestFactory s = requestFactories.netServices(); + Request t = + s.netServices(); + c = t.send(); + } catch (final Exception ignored) { + } + return c.getResult(); + } + }); + + return result; + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java index 81d91cfcab..d666d170a9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java @@ -266,7 +266,7 @@ private JsonRequestFactories jsonRequestFactories() { new PermissioningJsonRpcRequestFactory(web3jService), new AdminJsonRpcRequestFactory(web3jService), new EeaJsonRpcRequestFactory(web3jService), - new NetServicesJsonRpcRequestFactory(web3jService), + new NetServicesJsonRpcRequestFactory(web3jService), websocketService); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/NetServicesJsonRpcRequestFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/NetServicesJsonRpcRequestFactory.java index 66e04bc244..1517f26f44 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/NetServicesJsonRpcRequestFactory.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/NetServicesJsonRpcRequestFactory.java @@ -1,34 +1,41 @@ +/* + * 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; -import java.net.URI; -import java.util.Collections; -import java.util.Map; - public class NetServicesJsonRpcRequestFactory { - //public static class ProposalsResponse extends Response> {} - public static class NetServicesResponse extends Response>> { - - } + // public static class ProposalsResponse extends Response> {} + public static class NetServicesResponse extends Response>> {} - private final Web3jService web3jService; + private final Web3jService web3jService; - public NetServicesJsonRpcRequestFactory(final Web3jService web3jService) { - this.web3jService = web3jService; - } + public NetServicesJsonRpcRequestFactory(final Web3jService web3jService) { + this.web3jService = web3jService; + } - public Request netServices(final URI enodeAddress) { + public Request netServices() { - Request request = new Request<>( - "net_services", - Collections.EMPTY_LIST, - web3jService, - NetServicesResponse.class); + Request request = + new Request<>( + "net_services", Collections.EMPTY_LIST, web3jService, NetServicesResponse.class); - return request; - } + return request; + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/NetServicesAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/NetServicesAcceptanceTest.java index 5a56e6ef54..1135c3ce42 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/NetServicesAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/NetServicesAcceptanceTest.java @@ -1,38 +1,66 @@ +/* + * 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 org.junit.After; -import org.junit.Before; -import org.junit.Test; +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; -public class NetServicesAcceptanceTest extends AcceptanceTestBase { - - private Cluster noDiscoveryCluster; +import java.util.HashMap; +import java.util.Map; - private Node nodeA; - private Node nodeB; +import org.junit.Before; +import org.junit.Test; - @Before - public void setUp() throws Exception { - final ClusterConfiguration clusterConfiguration = - new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build(); - noDiscoveryCluster = new Cluster(clusterConfiguration, net); - nodeA = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeA"); - nodeB = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeB"); - noDiscoveryCluster.start(nodeA, nodeB); - } +public class NetServicesAcceptanceTest extends AcceptanceTestBase { - @Test - public void adminAddPeerForcesConnection() { + private Cluster noDiscoveryCluster; - System.out.println("AAA"); + private Node nodeA; + private Node nodeB; - nodeA.verify(netServices.addPeer(nodeA)); + @Before + public void setUp() throws Exception { + final ClusterConfiguration clusterConfiguration = + new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build(); + noDiscoveryCluster = new Cluster(clusterConfiguration, net); + nodeA = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeA"); + nodeB = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeB"); + noDiscoveryCluster.start(nodeA, nodeB); + } - System.out.println("ZZZ"); - } + @Test + public void adminAddPeerForcesConnection() { + Map> result = netServices.addPeer(nodeA); + Map> expectation = new HashMap<>(); + Map 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")); + } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 6ad7d475bd..7984d9a742 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -21,9 +21,6 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; -import tech.pegasys.pantheon.ethereum.graphqlrpc.GraphQLDataFetcherContext; -import tech.pegasys.pantheon.ethereum.graphqlrpc.GraphQLDataFetchers; -import tech.pegasys.pantheon.ethereum.graphqlrpc.GraphQLProvider; import tech.pegasys.pantheon.ethereum.graphqlrpc.GraphQLRpcConfiguration; import tech.pegasys.pantheon.ethereum.graphqlrpc.GraphQLRpcHttpService; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; @@ -75,7 +72,6 @@ import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; -import java.io.IOException; import java.net.URI; import java.nio.file.Path; import java.util.ArrayList; @@ -89,7 +85,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import graphql.GraphQL; import io.vertx.core.Vertx; public class RunnerBuilder { @@ -346,28 +341,28 @@ public Runner build() { } Optional graphQLRpcHttpService = Optional.empty(); -// if (graphQLRpcConfiguration.isEnabled()) { -// final GraphQLDataFetchers fetchers = new GraphQLDataFetchers(supportedCapabilities); -// final GraphQLDataFetcherContext dataFetcherContext = -// new GraphQLDataFetcherContext( -// context.getBlockchain(), -// context.getWorldStateArchive(), -// protocolSchedule, -// transactionPool, -// miningCoordinator, -// synchronizer); -// GraphQL graphQL = null; -// try { -// graphQL = GraphQLProvider.buildGraphQL(fetchers); -// } catch (final IOException ioe) { -// throw new RuntimeException(ioe); -// } -// -// graphQLRpcHttpService = -// Optional.of( -// new GraphQLRpcHttpService( -// vertx, dataDir, graphQLRpcConfiguration, graphQL, dataFetcherContext)); -// } + // if (graphQLRpcConfiguration.isEnabled()) { + // final GraphQLDataFetchers fetchers = new GraphQLDataFetchers(supportedCapabilities); + // final GraphQLDataFetcherContext dataFetcherContext = + // new GraphQLDataFetcherContext( + // context.getBlockchain(), + // context.getWorldStateArchive(), + // protocolSchedule, + // transactionPool, + // miningCoordinator, + // synchronizer); + // GraphQL graphQL = null; + // try { + // graphQL = GraphQLProvider.buildGraphQL(fetchers); + // } catch (final IOException ioe) { + // throw new RuntimeException(ioe); + // } + // + // graphQLRpcHttpService = + // Optional.of( + // new GraphQLRpcHttpService( + // vertx, dataDir, graphQLRpcConfiguration, graphQL, dataFetcherContext)); + // } Optional webSocketService = Optional.empty(); if (webSocketConfiguration.isEnabled()) {