use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError in project besu by hyperledger.
the class JsonRpcHttpServiceTest method ethGetStorageAtInvalidParameterStorageIndex.
@Test
public void ethGetStorageAtInvalidParameterStorageIndex() throws Exception {
// Setup mocks to return a block
final BlockDataGenerator gen = new BlockDataGenerator();
final Address address = gen.address();
final String id = "88";
final RequestBody body = RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_getStorageAt\", \"params\": [\"" + address + "\",\"" + "blah" + "\",\"latest\"]}");
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());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
testHelper.assertValidJsonRpcError(json, id, expectedError.getCode(), expectedError.getMessage());
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError in project besu by hyperledger.
the class JsonRpcHttpServiceTest method getBlockByHashWithMissingBooleanParameter.
@Test
public void getBlockByHashWithMissingBooleanParameter() throws Exception {
final String id = "123";
final String blockHashString = "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273321";
final RequestBody body = RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_getBlockByHash\", \"params\": [\"" + blockHashString + "\"]}");
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());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
testHelper.assertValidJsonRpcError(json, id, expectedError.getCode(), expectedError.getMessage());
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError in project besu by hyperledger.
the class JsonRpcHttpServiceTest method getBlockByHashWithMissingHashParameter.
@Test
public void getBlockByHashWithMissingHashParameter() throws Exception {
final String id = "123";
final RequestBody body = RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_getBlockByHash\", \"params\": [true]}");
// Setup mocks
when(blockchainQueries.blockByHash(ArgumentMatchers.isA(Hash.class))).thenReturn(Optional.empty());
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());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
testHelper.assertValidJsonRpcError(json, id, expectedError.getCode(), expectedError.getMessage());
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError in project besu by hyperledger.
the class JsonRpcHttpServiceTest method batchRequest.
@Test
public void batchRequest() throws Exception {
final int clientVersionRequestId = 2;
final int brokenRequestId = 3;
final int netVersionRequestId = 4;
final RequestBody body = RequestBody.create(JSON, "[{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(clientVersionRequestId) + ",\"method\":\"web3_clientVersion\"}," + "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(brokenRequestId) + ",\"method\":\"bla\"}," + "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(netVersionRequestId) + ",\"method\":\"net_version\"}]");
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());
final int requestCount = 3;
assertThat(json.size()).isEqualTo(requestCount);
final Map<Integer, JsonObject> responses = new HashMap<>();
for (int i = 0; i < requestCount; ++i) {
final JsonObject response = json.getJsonObject(i);
responses.put(response.getInteger("id"), response);
}
// Check result web3_clientVersion
final JsonObject jsonClientVersion = responses.get(clientVersionRequestId);
testHelper.assertValidJsonRpcResult(jsonClientVersion, clientVersionRequestId);
assertThat(jsonClientVersion.getString("result")).isEqualTo(CLIENT_VERSION);
// Check result unknown method
final JsonObject jsonError = responses.get(brokenRequestId);
final JsonRpcError expectedError = JsonRpcError.METHOD_NOT_FOUND;
testHelper.assertValidJsonRpcError(jsonError, brokenRequestId, expectedError.getCode(), expectedError.getMessage());
// Check result net_version
final JsonObject jsonNetVersion = responses.get(netVersionRequestId);
testHelper.assertValidJsonRpcResult(jsonNetVersion, netVersionRequestId);
assertThat(jsonNetVersion.getString("result")).isEqualTo(String.valueOf(CHAIN_ID));
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError in project besu by hyperledger.
the class JsonRpcHttpServiceTest method missingMethodField.
@Test
public void missingMethodField() throws Exception {
final Integer id = 2;
final RequestBody body = RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + "}");
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;
testHelper.assertValidJsonRpcError(json, id, expectedError.getCode(), expectedError.getMessage());
}
}
Aggregations