|
|
|
@ -131,13 +131,13 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
baseUrl = service.url(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfiguration config) |
|
|
|
|
private static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfiguration config) |
|
|
|
|
throws Exception { |
|
|
|
|
return new JsonRpcHttpService( |
|
|
|
|
vertx, folder.newFolder().toPath(), config, new NoOpMetricsSystem(), rpcMethods); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected static JsonRpcHttpService createJsonRpcHttpService() throws Exception { |
|
|
|
|
private static JsonRpcHttpService createJsonRpcHttpService() throws Exception { |
|
|
|
|
return new JsonRpcHttpService( |
|
|
|
|
vertx, |
|
|
|
|
folder.newFolder().toPath(), |
|
|
|
@ -146,9 +146,10 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
rpcMethods); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected static JsonRpcConfiguration createJsonRpcConfig() { |
|
|
|
|
private static JsonRpcConfiguration createJsonRpcConfig() { |
|
|
|
|
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault(); |
|
|
|
|
config.setPort(0); |
|
|
|
|
config.setHostsWhitelist(Collections.singletonList("*")); |
|
|
|
|
return config; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -170,18 +171,14 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void http404() throws Exception { |
|
|
|
|
final Request request = new Request.Builder().get().url(baseUrl + "/foo").build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildGetRequest("/foo")).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(404); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void handleEmptyRequest() throws Exception { |
|
|
|
|
final Request request = new Request.Builder().get().url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildGetRequest("")).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(201); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -229,9 +226,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.header("Content-Type")).isEqualTo("application/json"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -245,9 +241,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -265,9 +260,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -285,9 +279,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_accounts\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -307,9 +300,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_peerCount\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -336,9 +328,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockHash\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String jsonStr = resp.body().string(); |
|
|
|
@ -365,9 +356,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockHash\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String jsonStr = resp.body().string(); |
|
|
|
@ -395,9 +385,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -424,9 +413,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -452,9 +440,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -481,9 +468,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -506,9 +492,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -530,9 +515,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "," |
|
|
|
|
+ params |
|
|
|
|
+ ",\"method\":\"eth_getUncleCountByBlockNumber\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -551,9 +535,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_peerCount\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -583,9 +566,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBalance\", \"params\": [\"" |
|
|
|
|
+ address |
|
|
|
|
+ "\",\"latest\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -616,9 +598,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBalance\", \"params\": [\"" |
|
|
|
|
+ address |
|
|
|
|
+ "\",\"latest\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -648,9 +629,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBalance\", \"params\": [\"" |
|
|
|
|
+ address |
|
|
|
|
+ "\",\"earliest\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -683,9 +663,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "\",\"0x" |
|
|
|
|
+ Long.toString(blockNumber, 16) |
|
|
|
|
+ "\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -711,12 +690,11 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" |
|
|
|
|
+ blockHashString |
|
|
|
|
+ "\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
// Setup mocks
|
|
|
|
|
when(blockchainQueries.blockByHash(eq(blockHash))).thenReturn(Optional.empty()); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -747,9 +725,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" |
|
|
|
|
+ blockHash |
|
|
|
|
+ "\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -780,9 +757,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" |
|
|
|
|
+ blockHash |
|
|
|
|
+ "\",false]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -803,13 +779,12 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
// Setup mocks
|
|
|
|
|
when(blockchainQueries.blockByHash(ArgumentMatchers.isA(Hash.class))) |
|
|
|
|
.thenReturn(Optional.empty()); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -832,9 +807,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" |
|
|
|
|
+ blockHashString |
|
|
|
|
+ "\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -856,9 +830,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" |
|
|
|
|
+ blockHashString |
|
|
|
|
+ "\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -880,9 +853,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" |
|
|
|
|
+ blockHashString |
|
|
|
|
+ "\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -905,9 +877,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" |
|
|
|
|
+ blockHashString |
|
|
|
|
+ "\",{}]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -926,9 +897,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\", \"params\": []}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -947,9 +917,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByHash\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -978,9 +947,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"0x" |
|
|
|
|
+ Long.toString(number, 16) |
|
|
|
|
+ "\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1011,9 +979,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"0x" |
|
|
|
|
+ Long.toString(number, 16) |
|
|
|
|
+ "\",false]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1035,9 +1002,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"bla\",false]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1065,9 +1031,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"earliest\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1088,7 +1053,6 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"0x0\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
// Setup mocks to return a block
|
|
|
|
|
final BlockDataGenerator gen = new BlockDataGenerator(); |
|
|
|
@ -1097,7 +1061,7 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
blockWithMetadata(block); |
|
|
|
|
when(blockchainQueries.blockByNumber(eq(0L))).thenReturn(Optional.of(blockWithMetadata)); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1118,7 +1082,6 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"latest\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
// Setup mocks to return a block
|
|
|
|
|
final BlockDataGenerator gen = new BlockDataGenerator(); |
|
|
|
@ -1128,7 +1091,7 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
when(blockchainQueries.headBlockNumber()).thenReturn(0L); |
|
|
|
|
when(blockchainQueries.blockByNumber(eq(0L))).thenReturn(Optional.of(blockWithMetadata)); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1149,9 +1112,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"eth_getBlockByNumber\", \"params\": [\"pending\",true]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1172,9 +1134,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\", \"params\": [1,2,3]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -1191,9 +1152,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, "{\"id\":" + Json.encode(id) + ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
testHelper.assertValidJsonRpcResult(json, id); |
|
|
|
@ -1207,9 +1167,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
// No id field is present - marking this as a notification
|
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
// Notifications return an empty response
|
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
final String resBody = resp.body().string(); |
|
|
|
@ -1223,9 +1182,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, "{\"jsonrpc\":\"2.0\",\"id\":null,\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -1245,9 +1203,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
// An empty string is still a string, so should be a valid id
|
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
@ -1268,9 +1225,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -1293,9 +1249,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -1320,9 +1275,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -1342,9 +1296,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -1360,9 +1313,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, "{\"jsonrpc\":\"2.0\",\"id\":{},\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; |
|
|
|
@ -1376,9 +1328,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, "{\"jsonrpc\":\"2.0\",\"id\":[],\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; |
|
|
|
@ -1392,9 +1343,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
final Integer id = 2; |
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + "}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; |
|
|
|
@ -1406,9 +1356,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
@Test |
|
|
|
|
public void invalidJson() throws Exception { |
|
|
|
|
final RequestBody body = RequestBody.create(JSON, "{bla"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR; |
|
|
|
@ -1420,9 +1369,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
@Test |
|
|
|
|
public void wrongJsonType() throws Exception { |
|
|
|
|
final RequestBody body = RequestBody.create(JSON, "\"a string\""); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR; |
|
|
|
@ -1440,9 +1388,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"{\"jsonrpc\":\"1.0\",\"id\":" |
|
|
|
|
+ Json.encode(id) |
|
|
|
|
+ ",\"method\":\"web3_clientVersion\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
testHelper.assertValidJsonRpcResult(json, id); |
|
|
|
@ -1457,9 +1404,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"bla\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.METHOD_NOT_FOUND; |
|
|
|
@ -1479,9 +1425,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
|
|
|
|
|
final RequestBody body = |
|
|
|
|
RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":\"666\",\"method\":\"foo\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(500); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1500,9 +1445,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
"[{\"jsonrpc\":\"2.0\",\"id\":\"000\",\"method\":\"web3_clientVersion\"}," |
|
|
|
|
+ "{\"jsonrpc\":\"2.0\",\"id\":\"111\",\"method\":\"foo\"}," |
|
|
|
|
+ "{\"jsonrpc\":\"2.0\",\"id\":\"222\",\"method\":\"net_version\"}]"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(500); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1524,9 +1468,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(netVersionRequestId) |
|
|
|
|
+ ",\"method\":\"net_version\"}]"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonArray json = new JsonArray(resp.body().string()); |
|
|
|
@ -1573,9 +1516,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ ",\"method\":\"net_version\"}"; |
|
|
|
|
final String batchRequest = "[" + String.join(", ", reqs) + "]"; |
|
|
|
|
final RequestBody body = RequestBody.create(JSON, batchRequest); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String jsonStr = resp.body().string(); |
|
|
|
@ -1621,9 +1563,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "]"; |
|
|
|
|
|
|
|
|
|
final RequestBody body = RequestBody.create(JSON, req); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.PARSE_ERROR; |
|
|
|
@ -1646,9 +1587,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "{\"jsonrpc\":\"2.0\",\"id\":" |
|
|
|
|
+ Json.encode(netVersionRequestId) |
|
|
|
|
+ ",\"method\":\"net_version\"}]"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonArray json = new JsonArray(resp.body().string()); |
|
|
|
@ -1680,9 +1620,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
@Test |
|
|
|
|
public void emptyBatchRequest() throws Exception { |
|
|
|
|
final RequestBody body = RequestBody.create(JSON, "[]"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
|
final JsonRpcError expectedError = JsonRpcError.INVALID_REQUEST; |
|
|
|
@ -1812,10 +1751,9 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
when(synchronizer.getSyncStatus()).thenReturn(Optional.empty()); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Verify general result format.
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -1834,9 +1772,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
RequestBody.create( |
|
|
|
|
JSON, |
|
|
|
|
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
|
final JsonObject json = new JsonObject(respBody); |
|
|
|
|
final JsonObject result = json.getJsonObject("result"); |
|
|
|
@ -1902,9 +1839,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "\",\"" |
|
|
|
|
+ UInt256.ZERO |
|
|
|
|
+ "\",\"latest\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1938,9 +1874,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "\",\"" |
|
|
|
|
+ UInt256.ONE |
|
|
|
|
+ "\",\"latest\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -1973,9 +1908,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "\",\"" |
|
|
|
|
+ UInt256.ONE |
|
|
|
|
+ "\",\"earliest\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -2010,9 +1944,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "\",\"" |
|
|
|
|
+ 0L |
|
|
|
|
+ "\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(200); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final String respBody = resp.body().string(); |
|
|
|
@ -2043,9 +1976,8 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
+ "\",\"" |
|
|
|
|
+ "blah" |
|
|
|
|
+ "\",\"latest\"]}"); |
|
|
|
|
final Request request = new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
|
|
|
|
|
try (final Response resp = client.newCall(request).execute()) { |
|
|
|
|
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { |
|
|
|
|
assertThat(resp.code()).isEqualTo(400); |
|
|
|
|
// Check general format of result
|
|
|
|
|
final JsonObject json = new JsonObject(resp.body().string()); |
|
|
|
@ -2054,4 +1986,12 @@ public class JsonRpcHttpServiceTest { |
|
|
|
|
json, id, expectedError.getCode(), expectedError.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Request buildPostRequest(final RequestBody body) { |
|
|
|
|
return new Request.Builder().post(body).url(baseUrl).build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Request buildGetRequest(final String path) { |
|
|
|
|
return new Request.Builder().get().url(baseUrl + path).build(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|