[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.InetSocketAddress;
import java.net.SocketException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
@ -67,13 +68,16 @@ public class JsonRpcHttpService {
private final Vertx vertx;
private final JsonRpcConfiguration config;
private final Map<String, JsonRpcMethod> jsonRpcMethods;
private final Path dataDir;
private HttpServer httpServer;
public JsonRpcHttpService(
final Vertx vertx,
final Path dataDir,
final JsonRpcConfiguration config,
final Map<String, JsonRpcMethod> methods) {
this.dataDir = dataDir;
validateConfig(config);
this.config = config;
this.vertx = vertx;
@ -102,7 +106,12 @@ public class JsonRpcHttpService {
CorsHandler.create(buildCorsRegexFromConfig())
.allowedHeader("*")
.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("/")

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

@ -24,9 +24,12 @@ import okhttp3.Request.Builder;
import okhttp3.Response;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class JsonRpcHttpServiceCorsTest {
@Rule public final TemporaryFolder folder = new TemporaryFolder();
private final Vertx vertx = Vertx.vertx();
private final OkHttpClient client = new OkHttpClient();
@ -50,7 +53,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request =
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();
}
}
@ -62,7 +65,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request =
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();
}
}
@ -75,7 +78,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request =
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();
}
}
@ -88,7 +91,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request =
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();
}
}
@ -99,7 +102,7 @@ public class JsonRpcHttpServiceCorsTest {
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();
}
}
@ -110,7 +113,7 @@ public class JsonRpcHttpServiceCorsTest {
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();
}
}
@ -122,7 +125,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request =
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();
}
}
@ -134,7 +137,7 @@ public class JsonRpcHttpServiceCorsTest {
final Request request =
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();
}
}
@ -151,13 +154,13 @@ public class JsonRpcHttpServiceCorsTest {
.header("Origin", "http://foo.io")
.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");
}
}
private JsonRpcHttpService createJsonRpcHttpServiceWithAllowedDomains(
final String... corsAllowedDomains) {
final String... corsAllowedDomains) throws Exception {
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault();
config.setPort(0);
if (corsAllowedDomains != null) {
@ -165,7 +168,7 @@ public class JsonRpcHttpServiceCorsTest {
}
final JsonRpcHttpService jsonRpcHttpService =
new JsonRpcHttpService(vertx, config, new HashMap<>());
new JsonRpcHttpService(vertx, folder.newFolder().toPath(), config, new HashMap<>());
jsonRpcHttpService.start().join();
return jsonRpcHttpService;

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

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

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

Loading…
Cancel
Save