From e41902e23abd7848287e289052f7762aabae34c1 Mon Sep 17 00:00:00 2001 From: "S. Matthew English" Date: Mon, 13 May 2019 06:56:53 -0400 Subject: [PATCH] !! --- .../acceptance/dsl/AcceptanceTestBase.java | 2 - .../tests/acceptance/dsl/jsonrpc/Admin.java | 50 ++++++++----------- .../NetServicesJsonRpcRequestFactory.java | 4 +- .../jsonrpc/NetServicesAcceptanceTest.java | 7 +-- .../tech/pegasys/pantheon/RunnerBuilder.java | 49 ++++++++++-------- 5 files changed, 53 insertions(+), 59 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java index 4bf02e1d42..3fea905eed 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java @@ -57,7 +57,6 @@ public class AcceptanceTestBase { protected final ContractVerifier contractVerifier; protected final WaitConditions wait; protected final PermissionedNodeBuilder permissionedNodeBuilder; - protected final NetServices netServices; protected AcceptanceTestBase() { @@ -81,7 +80,6 @@ protected AcceptanceTestBase() { contractVerifier = new ContractVerifier(accounts.getPrimaryBenefactor()); wait = new WaitConditions(ethTransactions, cliqueTransactions, ibftTransactions); permissionedNodeBuilder = new PermissionedNodeBuilder(); - netServices = new NetServices(); } 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 873180eb9a..773988c8ac 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,50 +13,40 @@ 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; 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.Transaction; +import java.io.IOException; import java.net.URI; import org.web3j.protocol.core.Response; public class Admin { + private Transaction addPeerTransaction(final URI enode) { + return (n) -> { + try { + final Response resp = n.admin().adminAddPeer(enode).send(); + assertThat(resp).isNotNull(); + assertThat(resp.hasError()).isFalse(); + return resp.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + }; + } public Condition addPeer(final Node node) { + if (!(node instanceof RunnableNode)) { + fail("Admin.addPeer() needs a RunnableNode instance"); + } - 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(); - } + return (n) -> { + final Boolean result = n.execute(addPeerTransaction(((RunnableNode) node).enodeUrl())); + assertThat(result).isTrue(); }; } } 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 1517f26f44..f2320946b3 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 @@ -19,9 +19,9 @@ import org.web3j.protocol.core.Request; import org.web3j.protocol.core.Response; +@SuppressWarnings({"unchecked", "rawtypes"}) public class NetServicesJsonRpcRequestFactory { - // public static class ProposalsResponse extends Response> {} public static class NetServicesResponse extends Response>> {} private final Web3jService web3jService; @@ -32,7 +32,7 @@ public NetServicesJsonRpcRequestFactory(final Web3jService web3jService) { public Request netServices() { - Request request = + final Request request = new Request<>( "net_services", Collections.EMPTY_LIST, web3jService, NetServicesResponse.class); 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 1135c3ce42..01cba828d8 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 @@ -26,6 +26,7 @@ import org.junit.Before; import org.junit.Test; +@SuppressWarnings({"unchecked", "rawtypes"}) public class NetServicesAcceptanceTest extends AcceptanceTestBase { private Cluster noDiscoveryCluster; @@ -45,9 +46,9 @@ public void setUp() throws Exception { @Test public void adminAddPeerForcesConnection() { - Map> result = netServices.addPeer(nodeA); - Map> expectation = new HashMap<>(); - Map constituentMap = + final Map> result = netServices.addPeer(nodeA); + final Map> expectation = new HashMap<>(); + final Map constituentMap = new HashMap() { { put("host", "127.0.0.1"); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 7984d9a742..765a54b619 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -21,6 +21,9 @@ 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; @@ -72,6 +75,7 @@ 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; @@ -85,6 +89,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import graphql.GraphQL; import io.vertx.core.Vertx; public class RunnerBuilder { @@ -341,28 +346,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()) {