[NC-1679] Set vertx upload directory to be under the pantheon data dir. (#115)

Adrian Sutton 6 years ago committed by GitHub
parent 9e74b7b73e
commit 725cdb34c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java
  2. 7
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java
  3. 25
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceCorsTest.java
  4. 21
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java
  5. 159
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java
  6. 2
      pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java

@ -30,6 +30,7 @@ import tech.pegasys.pantheon.util.NetworkUtility;
import java.net.BindException; import java.net.BindException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketException; import java.net.SocketException;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringJoiner; import java.util.StringJoiner;
@ -67,13 +68,16 @@ public class JsonRpcHttpService {
private final Vertx vertx; private final Vertx vertx;
private final JsonRpcConfiguration config; private final JsonRpcConfiguration config;
private final Map<String, JsonRpcMethod> jsonRpcMethods; private final Map<String, JsonRpcMethod> jsonRpcMethods;
private final Path dataDir;
private HttpServer httpServer; private HttpServer httpServer;
public JsonRpcHttpService( public JsonRpcHttpService(
final Vertx vertx, final Vertx vertx,
final Path dataDir,
final JsonRpcConfiguration config, final JsonRpcConfiguration config,
final Map<String, JsonRpcMethod> methods) { final Map<String, JsonRpcMethod> methods) {
this.dataDir = dataDir;
validateConfig(config); validateConfig(config);
this.config = config; this.config = config;
this.vertx = vertx; this.vertx = vertx;
@ -102,7 +106,12 @@ public class JsonRpcHttpService {
CorsHandler.create(buildCorsRegexFromConfig()) CorsHandler.create(buildCorsRegexFromConfig())
.allowedHeader("*") .allowedHeader("*")
.allowedHeader("content-type")); .allowedHeader("content-type"));
router.route().handler(BodyHandler.create()); router
.route()
.handler(
BodyHandler.create()
.setUploadsDirectory(dataDir.resolve("uploads").toString())
.setDeleteUploadedFilesOnEnd(true));
router.route("/").method(HttpMethod.GET).handler(this::handleEmptyRequest); router.route("/").method(HttpMethod.GET).handler(this::handleEmptyRequest);
router router
.route("/") .route("/")

@ -68,8 +68,11 @@ import okhttp3.OkHttpClient;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
public abstract class AbstractEthJsonRpcHttpServiceTest { public abstract class AbstractEthJsonRpcHttpServiceTest {
@Rule public final TemporaryFolder folder = new TemporaryFolder();
protected static ProtocolSchedule<Void> PROTOCOL_SCHEDULE; protected static ProtocolSchedule<Void> PROTOCOL_SCHEDULE;
@ -138,7 +141,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
} }
@Before @Before
public void setupTest() { public void setupTest() throws Exception {
final Synchronizer synchronizerMock = mock(Synchronizer.class); final Synchronizer synchronizerMock = mock(Synchronizer.class);
final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class); final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class);
final TransactionPool transactionPoolMock = mock(TransactionPool.class); final TransactionPool transactionPoolMock = mock(TransactionPool.class);
@ -184,7 +187,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
JSON_RPC_APIS); JSON_RPC_APIS);
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault(); final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault();
config.setPort(0); config.setPort(0);
service = new JsonRpcHttpService(vertx, config, methods); service = new JsonRpcHttpService(vertx, folder.newFolder().toPath(), config, methods);
service.start().join(); service.start().join();
client = new OkHttpClient(); client = new OkHttpClient();

@ -24,9 +24,12 @@ import okhttp3.Request.Builder;
import okhttp3.Response; import okhttp3.Response;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class JsonRpcHttpServiceCorsTest { public class JsonRpcHttpServiceCorsTest {
@Rule public final TemporaryFolder folder = new TemporaryFolder();
private final Vertx vertx = Vertx.vertx(); private final Vertx vertx = Vertx.vertx();
private final OkHttpClient client = new OkHttpClient(); private final OkHttpClient client = new OkHttpClient();
@ -50,7 +53,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = final Request request =
new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build(); new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isFalse(); assertThat(response.isSuccessful()).isFalse();
} }
} }
@ -62,7 +65,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = final Request request =
new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://foo.io").build(); new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://foo.io").build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
} }
} }
@ -75,7 +78,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = final Request request =
new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build(); new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
} }
} }
@ -88,7 +91,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = final Request request =
new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://hel.lo").build(); new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://hel.lo").build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isFalse(); assertThat(response.isSuccessful()).isFalse();
} }
} }
@ -99,7 +102,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = new Builder().url(jsonRpcHttpService.url()).build(); final Request request = new Builder().url(jsonRpcHttpService.url()).build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
} }
} }
@ -110,7 +113,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = new Builder().url(jsonRpcHttpService.url()).build(); final Request request = new Builder().url(jsonRpcHttpService.url()).build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
} }
} }
@ -122,7 +125,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = final Request request =
new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build(); new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isFalse(); assertThat(response.isSuccessful()).isFalse();
} }
} }
@ -134,7 +137,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request = final Request request =
new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build(); new Builder().url(jsonRpcHttpService.url()).header("Origin", "http://bar.me").build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
} }
} }
@ -151,13 +154,13 @@ public class JsonRpcHttpServiceCorsTest {
.header("Origin", "http://foo.io") .header("Origin", "http://foo.io")
.build(); .build();
try (Response response = client.newCall(request).execute()) { try (final Response response = client.newCall(request).execute()) {
assertThat(response.header("Access-Control-Allow-Headers")).contains("*", "content-type"); assertThat(response.header("Access-Control-Allow-Headers")).contains("*", "content-type");
} }
} }
private JsonRpcHttpService createJsonRpcHttpServiceWithAllowedDomains( private JsonRpcHttpService createJsonRpcHttpServiceWithAllowedDomains(
final String... corsAllowedDomains) { final String... corsAllowedDomains) throws Exception {
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault(); final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault();
config.setPort(0); config.setPort(0);
if (corsAllowedDomains != null) { if (corsAllowedDomains != null) {
@ -165,7 +168,7 @@ public class JsonRpcHttpServiceCorsTest {
} }
final JsonRpcHttpService jsonRpcHttpService = final JsonRpcHttpService jsonRpcHttpService =
new JsonRpcHttpService(vertx, config, new HashMap<>()); new JsonRpcHttpService(vertx, folder.newFolder().toPath(), config, new HashMap<>());
jsonRpcHttpService.start().join(); jsonRpcHttpService.start().join();
return jsonRpcHttpService; return jsonRpcHttpService;

@ -44,13 +44,16 @@ import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class JsonRpcHttpServiceRpcApisTest { public class JsonRpcHttpServiceRpcApisTest {
@Rule public final TemporaryFolder folder = new TemporaryFolder();
private final Vertx vertx = Vertx.vertx(); private final Vertx vertx = Vertx.vertx();
private final OkHttpClient client = new OkHttpClient(); private final OkHttpClient client = new OkHttpClient();
@ -86,7 +89,7 @@ public class JsonRpcHttpServiceRpcApisTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
} }
} }
@ -101,7 +104,7 @@ public class JsonRpcHttpServiceRpcApisTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
} }
} }
@ -116,7 +119,7 @@ public class JsonRpcHttpServiceRpcApisTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -136,7 +139,7 @@ public class JsonRpcHttpServiceRpcApisTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
} }
} }
@ -151,12 +154,13 @@ public class JsonRpcHttpServiceRpcApisTest {
return config; return config;
} }
private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final RpcApi... rpcApis) { private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final RpcApi... rpcApis)
throws Exception {
return createJsonRpcHttpServiceWithRpcApis(createJsonRpcConfigurationWithRpcApis(rpcApis)); return createJsonRpcHttpServiceWithRpcApis(createJsonRpcConfigurationWithRpcApis(rpcApis));
} }
private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis( private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final JsonRpcConfiguration config)
final JsonRpcConfiguration config) { throws Exception {
final Set<Capability> supportedCapabilities = new HashSet<>(); final Set<Capability> supportedCapabilities = new HashSet<>();
supportedCapabilities.add(EthProtocol.ETH62); supportedCapabilities.add(EthProtocol.ETH62);
supportedCapabilities.add(EthProtocol.ETH63); supportedCapabilities.add(EthProtocol.ETH63);
@ -176,7 +180,8 @@ public class JsonRpcHttpServiceRpcApisTest {
mock(EthHashMiningCoordinator.class), mock(EthHashMiningCoordinator.class),
supportedCapabilities, supportedCapabilities,
config.getRpcApis())); config.getRpcApis()));
final JsonRpcHttpService jsonRpcHttpService = new JsonRpcHttpService(vertx, config, rpcMethods); final JsonRpcHttpService jsonRpcHttpService =
new JsonRpcHttpService(vertx, folder.newFolder().toPath(), config, rpcMethods);
jsonRpcHttpService.start().join(); jsonRpcHttpService.start().join();
baseUrl = jsonRpcHttpService.url(); baseUrl = jsonRpcHttpService.url();

@ -70,11 +70,15 @@ import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
public class JsonRpcHttpServiceTest { public class JsonRpcHttpServiceTest {
@ClassRule public static final TemporaryFolder folder = new TemporaryFolder();
private static final Vertx vertx = Vertx.vertx(); private static final Vertx vertx = Vertx.vertx();
protected static Map<String, JsonRpcMethod> rpcMethods; protected static Map<String, JsonRpcMethod> rpcMethods;
@ -92,7 +96,7 @@ public class JsonRpcHttpServiceTest {
protected final JsonRpcTestHelper testHelper = new JsonRpcTestHelper(); protected final JsonRpcTestHelper testHelper = new JsonRpcTestHelper();
@BeforeClass @BeforeClass
public static void initServerAndClient() { public static void initServerAndClient() throws Exception {
peerDiscoveryMock = mock(P2PNetwork.class); peerDiscoveryMock = mock(P2PNetwork.class);
blockchainQueries = mock(BlockchainQueries.class); blockchainQueries = mock(BlockchainQueries.class);
synchronizer = mock(Synchronizer.class); synchronizer = mock(Synchronizer.class);
@ -124,12 +128,14 @@ public class JsonRpcHttpServiceTest {
baseUrl = service.url(); baseUrl = service.url();
} }
protected static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfiguration config) { protected static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfiguration config)
return new JsonRpcHttpService(vertx, config, rpcMethods); throws Exception {
return new JsonRpcHttpService(vertx, folder.newFolder().toPath(), config, rpcMethods);
} }
protected static JsonRpcHttpService createJsonRpcHttpService() { protected static JsonRpcHttpService createJsonRpcHttpService() throws Exception {
return new JsonRpcHttpService(vertx, createJsonRpcConfig(), rpcMethods); return new JsonRpcHttpService(
vertx, folder.newFolder().toPath(), createJsonRpcConfig(), rpcMethods);
} }
protected static JsonRpcConfiguration createJsonRpcConfig() { protected static JsonRpcConfiguration createJsonRpcConfig() {
@ -158,7 +164,7 @@ public class JsonRpcHttpServiceTest {
public void http404() throws Exception { public void http404() throws Exception {
final Request request = new Request.Builder().get().url(baseUrl + "/foo").build(); final Request request = new Request.Builder().get().url(baseUrl + "/foo").build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(404); assertThat(resp.code()).isEqualTo(404);
} }
} }
@ -167,7 +173,7 @@ public class JsonRpcHttpServiceTest {
public void handleEmptyRequest() throws Exception { public void handleEmptyRequest() throws Exception {
final Request request = new Request.Builder().get().url(baseUrl).build(); final Request request = new Request.Builder().get().url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(201); assertThat(resp.code()).isEqualTo(201);
} }
} }
@ -180,7 +186,7 @@ public class JsonRpcHttpServiceTest {
} }
@Test @Test
public void getSocketAddressWhenStoppedIsEmpty() { public void getSocketAddressWhenStoppedIsEmpty() throws Exception {
final JsonRpcHttpService service = createJsonRpcHttpService(); final JsonRpcHttpService service = createJsonRpcHttpService();
final InetSocketAddress socketAddress = service.socketAddress(); final InetSocketAddress socketAddress = service.socketAddress();
@ -190,7 +196,7 @@ public class JsonRpcHttpServiceTest {
} }
@Test @Test
public void getSocketAddressWhenBindingToAllInterfaces() { public void getSocketAddressWhenBindingToAllInterfaces() throws Exception {
final JsonRpcConfiguration config = createJsonRpcConfig(); final JsonRpcConfiguration config = createJsonRpcConfig();
config.setHost("0.0.0.0"); config.setHost("0.0.0.0");
final JsonRpcHttpService service = createJsonRpcHttpService(config); final JsonRpcHttpService service = createJsonRpcHttpService(config);
@ -217,7 +223,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.header("Content-Type")).isEqualTo("application/json"); assertThat(resp.header("Content-Type")).isEqualTo("application/json");
} }
} }
@ -233,7 +239,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -253,7 +259,7 @@ public class JsonRpcHttpServiceTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -273,7 +279,7 @@ public class JsonRpcHttpServiceTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_accounts\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_accounts\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -295,7 +301,7 @@ public class JsonRpcHttpServiceTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_peerCount\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_peerCount\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -309,7 +315,6 @@ public class JsonRpcHttpServiceTest {
@Test @Test
public void ethGetUncleCountByBlockHash() throws Exception { public void ethGetUncleCountByBlockHash() throws Exception {
final int uncleCount = 2; final int uncleCount = 2;
final String number = "0x567";
final Hash blockHash = Hash.hash(BytesValue.of(1)); final Hash blockHash = Hash.hash(BytesValue.of(1));
when(blockchainQueries.getOmmerCount(eq(blockHash))).thenReturn(Optional.of(uncleCount)); when(blockchainQueries.getOmmerCount(eq(blockHash))).thenReturn(Optional.of(uncleCount));
@ -325,7 +330,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockHash\"}"); + ",\"method\":\"eth_getUncleCountByBlockHash\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String jsonStr = resp.body().string(); final String jsonStr = resp.body().string();
@ -339,7 +344,6 @@ public class JsonRpcHttpServiceTest {
@Test @Test
public void ethGetUncleCountByBlockHashNoData() throws Exception { public void ethGetUncleCountByBlockHashNoData() throws Exception {
final String number = "0x567";
final Hash blockHash = Hash.hash(BytesValue.of(1)); final Hash blockHash = Hash.hash(BytesValue.of(1));
when(blockchainQueries.getOmmerCount(eq(blockHash))).thenReturn(Optional.empty()); when(blockchainQueries.getOmmerCount(eq(blockHash))).thenReturn(Optional.empty());
@ -355,7 +359,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockHash\"}"); + ",\"method\":\"eth_getUncleCountByBlockHash\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String jsonStr = resp.body().string(); final String jsonStr = resp.body().string();
@ -385,7 +389,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); + ",\"method\":\"eth_getUncleCountByBlockNumber\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -414,7 +418,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); + ",\"method\":\"eth_getUncleCountByBlockNumber\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -442,7 +446,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); + ",\"method\":\"eth_getUncleCountByBlockNumber\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -471,7 +475,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); + ",\"method\":\"eth_getUncleCountByBlockNumber\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -484,9 +488,6 @@ public class JsonRpcHttpServiceTest {
@Test @Test
public void ethGetUncleCountByBlockNumberPending() throws Exception { public void ethGetUncleCountByBlockNumberPending() throws Exception {
final BlockDataGenerator gen = new BlockDataGenerator();
final Block pending = gen.block();
final String id = "123"; final String id = "123";
final String params = "\"params\": [\"pending\"]"; final String params = "\"params\": [\"pending\"]";
final RequestBody body = final RequestBody body =
@ -499,7 +500,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); + ",\"method\":\"eth_getUncleCountByBlockNumber\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -523,7 +524,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); + ",\"method\":\"eth_getUncleCountByBlockNumber\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -544,7 +545,7 @@ public class JsonRpcHttpServiceTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_peerCount\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_peerCount\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -576,7 +577,7 @@ public class JsonRpcHttpServiceTest {
+ "\",\"latest\"]}"); + "\",\"latest\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -609,7 +610,7 @@ public class JsonRpcHttpServiceTest {
+ "\",\"latest\"]}"); + "\",\"latest\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -641,7 +642,7 @@ public class JsonRpcHttpServiceTest {
+ "\",\"earliest\"]}"); + "\",\"earliest\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -676,7 +677,7 @@ public class JsonRpcHttpServiceTest {
+ "\"]}"); + "\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -707,7 +708,7 @@ public class JsonRpcHttpServiceTest {
// Setup mocks // Setup mocks
when(blockchainQueries.blockByHash(eq(blockHash))).thenReturn(Optional.empty()); when(blockchainQueries.blockByHash(eq(blockHash))).thenReturn(Optional.empty());
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -740,7 +741,7 @@ public class JsonRpcHttpServiceTest {
+ "\",true]}"); + "\",true]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -773,7 +774,7 @@ public class JsonRpcHttpServiceTest {
+ "\",false]}"); + "\",false]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -800,7 +801,7 @@ public class JsonRpcHttpServiceTest {
when(blockchainQueries.blockByHash(ArgumentMatchers.isA(Hash.class))) when(blockchainQueries.blockByHash(ArgumentMatchers.isA(Hash.class)))
.thenReturn(Optional.empty()); .thenReturn(Optional.empty());
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -825,7 +826,7 @@ public class JsonRpcHttpServiceTest {
+ "\"]}"); + "\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -849,7 +850,7 @@ public class JsonRpcHttpServiceTest {
+ "\",true]}"); + "\",true]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -873,7 +874,7 @@ public class JsonRpcHttpServiceTest {
+ "\",true]}"); + "\",true]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -898,7 +899,7 @@ public class JsonRpcHttpServiceTest {
+ "\",{}]}"); + "\",{}]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -919,7 +920,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getBlockByHash\", \"params\": []}"); + ",\"method\":\"eth_getBlockByHash\", \"params\": []}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -940,7 +941,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getBlockByHash\"}"); + ",\"method\":\"eth_getBlockByHash\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -971,7 +972,7 @@ public class JsonRpcHttpServiceTest {
+ "\",true]}"); + "\",true]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1004,7 +1005,7 @@ public class JsonRpcHttpServiceTest {
+ "\",false]}"); + "\",false]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1028,7 +1029,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"bla\",false]}"); + ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"bla\",false]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1058,7 +1059,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"earliest\",true]}"); + ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"earliest\",true]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1088,7 +1089,7 @@ public class JsonRpcHttpServiceTest {
blockWithMetadata(block); blockWithMetadata(block);
when(blockchainQueries.blockByNumber(eq(0L))).thenReturn(Optional.of(blockWithMetadata)); when(blockchainQueries.blockByNumber(eq(0L))).thenReturn(Optional.of(blockWithMetadata));
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1119,7 +1120,7 @@ public class JsonRpcHttpServiceTest {
when(blockchainQueries.headBlockNumber()).thenReturn(0L); when(blockchainQueries.headBlockNumber()).thenReturn(0L);
when(blockchainQueries.blockByNumber(eq(0L))).thenReturn(Optional.of(blockWithMetadata)); when(blockchainQueries.blockByNumber(eq(0L))).thenReturn(Optional.of(blockWithMetadata));
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1142,7 +1143,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"pending\",true]}"); + ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"pending\",true]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1165,7 +1166,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\", \"params\": [1,2,3]}"); + ",\"method\":\"web3_clientVersion\", \"params\": [1,2,3]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -1184,7 +1185,7 @@ public class JsonRpcHttpServiceTest {
JSON, "{\"id\":" + Json.encode(id) + ",\"method\":\"web3_clientVersion\"}"); JSON, "{\"id\":" + Json.encode(id) + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidJsonRpcResult(json, id); testHelper.assertValidJsonRpcResult(json, id);
@ -1200,7 +1201,7 @@ public class JsonRpcHttpServiceTest {
RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\"}"); RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
// Notifications return an empty response // Notifications return an empty response
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
final String resBody = resp.body().string(); final String resBody = resp.body().string();
@ -1216,7 +1217,7 @@ public class JsonRpcHttpServiceTest {
JSON, "{\"jsonrpc\":\"2.0\",\"id\":null,\"method\":\"web3_clientVersion\"}"); JSON, "{\"jsonrpc\":\"2.0\",\"id\":null,\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -1238,7 +1239,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
// An empty string is still a string, so should be a valid id // An empty string is still a string, so should be a valid id
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
@ -1261,7 +1262,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -1286,7 +1287,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -1313,7 +1314,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -1335,7 +1336,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -1353,7 +1354,7 @@ public class JsonRpcHttpServiceTest {
JSON, "{\"jsonrpc\":\"2.0\",\"id\":{},\"method\":\"web3_clientVersion\"}"); JSON, "{\"jsonrpc\":\"2.0\",\"id\":{},\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST;
@ -1369,7 +1370,7 @@ public class JsonRpcHttpServiceTest {
JSON, "{\"jsonrpc\":\"2.0\",\"id\":[],\"method\":\"web3_clientVersion\"}"); JSON, "{\"jsonrpc\":\"2.0\",\"id\":[],\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST;
@ -1385,7 +1386,7 @@ public class JsonRpcHttpServiceTest {
RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + "}"); RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + "}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST;
@ -1399,7 +1400,7 @@ public class JsonRpcHttpServiceTest {
final RequestBody body = RequestBody.create(JSON, "{bla"); final RequestBody body = RequestBody.create(JSON, "{bla");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR; final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR;
@ -1413,7 +1414,7 @@ public class JsonRpcHttpServiceTest {
final RequestBody body = RequestBody.create(JSON, "\"a string\""); final RequestBody body = RequestBody.create(JSON, "\"a string\"");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR; final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR;
@ -1433,7 +1434,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"web3_clientVersion\"}"); + ",\"method\":\"web3_clientVersion\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidJsonRpcResult(json, id); testHelper.assertValidJsonRpcResult(json, id);
@ -1450,7 +1451,7 @@ public class JsonRpcHttpServiceTest {
JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"bla\"}"); JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"bla\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.METHOD_NOT_FOUND; final JsonRpcError expectedError = JsonRpcError.METHOD_NOT_FOUND;
@ -1472,7 +1473,7 @@ public class JsonRpcHttpServiceTest {
RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":\"666\",\"method\":\"foo\"}"); RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":\"666\",\"method\":\"foo\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(500); assertThat(resp.code()).isEqualTo(500);
} }
} }
@ -1493,7 +1494,7 @@ public class JsonRpcHttpServiceTest {
+ "{\"jsonrpc\":\"2.0\",\"id\":\"222\",\"method\":\"net_version\"}]"); + "{\"jsonrpc\":\"2.0\",\"id\":\"222\",\"method\":\"net_version\"}]");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(500); assertThat(resp.code()).isEqualTo(500);
} }
} }
@ -1517,7 +1518,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"net_version\"}]"); + ",\"method\":\"net_version\"}]");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonArray json = new JsonArray(resp.body().string()); final JsonArray json = new JsonArray(resp.body().string());
@ -1566,7 +1567,7 @@ public class JsonRpcHttpServiceTest {
final RequestBody body = RequestBody.create(JSON, batchRequest); final RequestBody body = RequestBody.create(JSON, batchRequest);
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String jsonStr = resp.body().string(); final String jsonStr = resp.body().string();
@ -1614,7 +1615,7 @@ public class JsonRpcHttpServiceTest {
final RequestBody body = RequestBody.create(JSON, req); final RequestBody body = RequestBody.create(JSON, req);
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR; final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR;
@ -1639,7 +1640,7 @@ public class JsonRpcHttpServiceTest {
+ ",\"method\":\"net_version\"}]"); + ",\"method\":\"net_version\"}]");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final JsonArray json = new JsonArray(resp.body().string()); final JsonArray json = new JsonArray(resp.body().string());
@ -1673,7 +1674,7 @@ public class JsonRpcHttpServiceTest {
final RequestBody body = RequestBody.create(JSON, "[]"); final RequestBody body = RequestBody.create(JSON, "[]");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST;
@ -1806,7 +1807,7 @@ public class JsonRpcHttpServiceTest {
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
when(synchronizer.getSyncStatus()).thenReturn(Optional.empty()); when(synchronizer.getSyncStatus()).thenReturn(Optional.empty());
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Verify general result format. // Verify general result format.
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());
@ -1827,7 +1828,7 @@ public class JsonRpcHttpServiceTest {
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}"); "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
final String respBody = resp.body().string(); final String respBody = resp.body().string();
final JsonObject json = new JsonObject(respBody); final JsonObject json = new JsonObject(respBody);
final JsonObject result = json.getJsonObject("result"); final JsonObject result = json.getJsonObject("result");
@ -1895,7 +1896,7 @@ public class JsonRpcHttpServiceTest {
+ "\",\"latest\"]}"); + "\",\"latest\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1931,7 +1932,7 @@ public class JsonRpcHttpServiceTest {
+ "\",\"latest\"]}"); + "\",\"latest\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -1966,7 +1967,7 @@ public class JsonRpcHttpServiceTest {
+ "\",\"earliest\"]}"); + "\",\"earliest\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -2003,7 +2004,7 @@ public class JsonRpcHttpServiceTest {
+ "\"]}"); + "\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200); assertThat(resp.code()).isEqualTo(200);
// Check general format of result // Check general format of result
final String respBody = resp.body().string(); final String respBody = resp.body().string();
@ -2036,7 +2037,7 @@ public class JsonRpcHttpServiceTest {
+ "\",\"latest\"]}"); + "\",\"latest\"]}");
final Request request = new Request.Builder().post(body).url(baseUrl).build(); final Request request = new Request.Builder().post(body).url(baseUrl).build();
try (Response resp = client.newCall(request).execute()) { try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(400); assertThat(resp.code()).isEqualTo(400);
// Check general format of result // Check general format of result
final JsonObject json = new JsonObject(resp.body().string()); final JsonObject json = new JsonObject(resp.body().string());

@ -159,7 +159,7 @@ public class RunnerBuilder {
jsonRpcConfiguration.getRpcApis(), jsonRpcConfiguration.getRpcApis(),
filterManager); filterManager);
jsonRpcHttpService = jsonRpcHttpService =
Optional.of(new JsonRpcHttpService(vertx, jsonRpcConfiguration, jsonRpcMethods)); Optional.of(new JsonRpcHttpService(vertx, dataDir, jsonRpcConfiguration, jsonRpcMethods));
} }
Optional<WebSocketService> webSocketService = Optional.empty(); Optional<WebSocketService> webSocketService = Optional.empty();

Loading…
Cancel
Save