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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations