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

Commit

Permalink
paradigm
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed May 6, 2019
1 parent de08b81 commit 97227aa
Showing 1 changed file with 32 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, JsonRpcMethod> 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());
}

}

0 comments on commit 97227aa

Please sign in to comment.