From f301e5dc7f78d6c75e65ced6f3fd56753bcdb773 Mon Sep 17 00:00:00 2001 From: "S. Matthew English" Date: Mon, 6 May 2019 05:38:02 -0400 Subject: [PATCH] paradigm --- .../methods/NetServicesIntegrationTest.java | 85 +++++++------------ 1 file changed, 32 insertions(+), 53 deletions(-) diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/NetServicesIntegrationTest.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/NetServicesIntegrationTest.java index 26c07cf477..6418677a4e 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/NetServicesIntegrationTest.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/NetServicesIntegrationTest.java @@ -12,72 +12,51 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc.methods; -import static org.mockito.Mockito.mock; - import com.google.common.base.Charsets; import com.google.common.io.Resources; +import org.junit.Before; +import org.junit.Test; import tech.pegasys.pantheon.ethereum.jsonrpc.BlockchainImporter; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; -import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcHttpService; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcResponseUtils; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcTestMethodsFactory; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; -import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.NetServices; -import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; -import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; -import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import java.net.URL; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; - -import io.vertx.core.Vertx; -import org.junit.Before; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; public class NetServicesIntegrationTest { - - - - private JsonRpcHttpService jsonRpcHttpService; - - @Before - public void setUp() { - final Vertx vertx = Vertx.vertx(); - final TemporaryFolder folder = new TemporaryFolder(); - Path dataDir = null; - try { - dataDir = folder.newFolder().toPath(); - } catch (Exception ignored) { + //private final JsonRpcResponseUtils jsonRpcResponseUtils = new JsonRpcResponseUtils(); + private JsonRpcTestMethodsFactory jsonRpcTestMethodsFactory; + private JsonRpcMethod jsonRpcMethod; + + @Before + public void setUp() throws Exception { + final URL blocksUrl = + NetServicesIntegrationTest.class + .getClassLoader() + .getResource("tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestBlockchain.blocks"); + final URL genesisJsonUrl = + NetServicesIntegrationTest.class + .getClassLoader() + .getResource("tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestGenesis.json"); + final String genesisJson = Resources.toString(genesisJsonUrl, Charsets.UTF_8); + final BlockchainImporter blockchainImporter = new BlockchainImporter(blocksUrl, genesisJson); + jsonRpcTestMethodsFactory = new JsonRpcTestMethodsFactory(blockchainImporter); + + jsonRpcMethod = jsonRpcTestMethodsFactory.methods().get("net_services"); } - final JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); - final MetricsSystem metricsSystem = new NoOpMetricsSystem(); - - final Map jsonRpcMethod = new HashMap<>(); - /* * */ - final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); - final P2PNetwork p2pNetwork = mock(P2PNetwork.class); - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); - final NetServices netServices = - new NetServices( - jsonRpcConfiguration, webSocketConfiguration, p2pNetwork, metricsConfiguration); - /* * */ - jsonRpcMethod.put("net_services", netServices); - - jsonRpcHttpService = new JsonRpcHttpService(vertx, dataDir, jsonRpcConfiguration, metricsSystem, jsonRpcMethod); - } - @Test - public void test() { + @Test + public void test() { + final JsonRpcRequest jsonRpcRequest = new JsonRpcRequest("2.0", "net_services", new Object[]{}); + final JsonRpcSuccessResponse jsonRpcSuccessResponse = (JsonRpcSuccessResponse) jsonRpcMethod.response(jsonRpcRequest); - jsonRpcHttpService.start(); + System.out.println("getType: " + jsonRpcSuccessResponse.getType()); + System.out.println("hashCode: " + jsonRpcSuccessResponse.hashCode()); + System.out.println("getId: " + jsonRpcSuccessResponse.getId()); - - - } + System.out.println("getResult: " + jsonRpcSuccessResponse.getResult()); + } }