Search in sources :

Example 1 with JsonRpcRequestContext

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext in project besu by hyperledger.

the class WebSocketRequestHandlerTest method handlerBatchRequestDeliversResponseSuccessfully.

@Test
public void handlerBatchRequestDeliversResponseSuccessfully(final TestContext context) {
    final Async async = context.async();
    final JsonObject requestJson = new JsonObject().put("id", 1).put("method", "eth_x");
    final JsonArray arrayJson = new JsonArray(List.of(requestJson, requestJson));
    final JsonRpcRequest requestBody = requestJson.mapTo(WebSocketRpcRequest.class);
    final JsonRpcRequestContext expectedRequest = new JsonRpcRequestContext(requestBody);
    final JsonRpcSuccessResponse expectedSingleResponse = new JsonRpcSuccessResponse(requestBody.getId(), null);
    final JsonArray expectedBatchResponse = new JsonArray(List.of(expectedSingleResponse, expectedSingleResponse));
    when(jsonRpcMethodMock.response(eq(expectedRequest))).thenReturn(expectedSingleResponse);
    when(websocketMock.writeFrame(argThat(this::isFinalFrame))).then(completeOnLastFrame(async));
    handler.handle(websocketMock, arrayJson.toString());
    async.awaitSuccess(WebSocketRequestHandlerTest.VERTX_AWAIT_TIMEOUT_MILLIS);
    // can verify only after async not before
    verify(websocketMock).writeFrame(argThat(isFrameWithText(Json.encode(expectedBatchResponse))));
    verify(websocketMock).writeFrame(argThat(this::isFinalFrame));
    verify(jsonRpcMethodMock, Mockito.times(2)).response(eq(expectedRequest));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 2 with JsonRpcRequestContext

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext in project besu by hyperledger.

the class EthGetBlockByHashTest method exceptionWhenHashParamInvalid.

@Test
public void exceptionWhenHashParamInvalid() {
    final JsonRpcRequestContext request = requestWithParams("hash", "true");
    thrown.expect(InvalidJsonRpcParameters.class);
    thrown.expectMessage("Invalid json rpc parameter at index 0");
    method.response(request);
    verifyNoMoreInteractions(blockchainQueries);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Test(org.junit.Test)

Example 3 with JsonRpcRequestContext

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext in project besu by hyperledger.

the class EthGetBlockByHashTest method exceptionWhenBoolParamInvalid.

@Test
public void exceptionWhenBoolParamInvalid() {
    final JsonRpcRequestContext request = requestWithParams(ZERO_HASH, "maybe");
    thrown.expect(InvalidJsonRpcParameters.class);
    thrown.expectMessage("Invalid json rpc parameter at index 1");
    method.response(request);
    verifyNoMoreInteractions(blockchainQueries);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Test(org.junit.Test)

Example 4 with JsonRpcRequestContext

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext in project besu by hyperledger.

the class IbftGetSignerMetricsTest method exceptionWhenInvalidStartBlockSupplied.

@Test
public void exceptionWhenInvalidStartBlockSupplied() {
    final JsonRpcRequestContext request = requestWithParams("INVALID");
    expectedException.expect(InvalidJsonRpcParameters.class);
    expectedException.expectMessage("Invalid json rpc parameter at index 0");
    method.response(request);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Test(org.junit.Test)

Example 5 with JsonRpcRequestContext

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext in project besu by hyperledger.

the class IbftGetSignerMetricsTest method exceptionWhenInvalidEndBlockSupplied.

@Test
public void exceptionWhenInvalidEndBlockSupplied() {
    final JsonRpcRequestContext request = requestWithParams("1", "INVALID");
    expectedException.expect(InvalidJsonRpcParameters.class);
    expectedException.expectMessage("Invalid json rpc parameter at index 1");
    method.response(request);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Test(org.junit.Test)

Aggregations

JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)527 Test (org.junit.Test)413 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)280 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)231 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)188 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)145 Test (org.junit.jupiter.api.Test)74 InvalidJsonRpcParameters (org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters)60 JsonCallParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter)33 JsonObject (io.vertx.core.json.JsonObject)29 ArrayList (java.util.ArrayList)28 Hash (org.hyperledger.besu.datatypes.Hash)26 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)25 Address (org.hyperledger.besu.datatypes.Address)25 Collection (java.util.Collection)22 FilterParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter)22 NodesAllowlistResult (org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController.NodesAllowlistResult)22 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)21 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)20 HashMap (java.util.HashMap)19