use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest 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.JsonRpcRequest in project besu by hyperledger.
the class QbftGetValidatorsByBlockNumberTest method blockParameterIsParameter0.
@Test
public void blockParameterIsParameter0() {
request = new JsonRpcRequestContext(new JsonRpcRequest("?", "ignore", new String[] { "0x1245" }));
BlockParameter blockParameter = method.blockParameter(request);
assertThat(blockParameter.getNumber()).isPresent();
assertThat(blockParameter.getNumber().get()).isEqualTo(0x1245);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest in project besu by hyperledger.
the class CliqueGetSignersAtHashTest method failsWhenNoParam.
@Test
@SuppressWarnings("unchecked")
public void failsWhenNoParam() {
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "clique_getSignersAtHash", new Object[] {}));
final Throwable thrown = AssertionsForClassTypes.catchThrowable(() -> method.response(request));
assertThat(thrown).isInstanceOf(InvalidJsonRpcParameters.class).hasMessage("Missing required json rpc parameter at index 0");
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest in project besu by hyperledger.
the class CliqueGetSignersAtHashTest method returnsValidatorsForBlockHash.
@Test
@SuppressWarnings("unchecked")
public void returnsValidatorsForBlockHash() {
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "clique_getSignersAtHash", new Object[] { BLOCK_HASH }));
when(blockchainQueries.blockByHash(Hash.fromHexString(BLOCK_HASH))).thenReturn(Optional.of(blockWithMetadata));
when(blockWithMetadata.getHeader()).thenReturn(blockHeader);
when(validatorProvider.getValidatorsAfterBlock(blockHeader)).thenReturn(validators);
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
assertThat(response.getResult()).isEqualTo(validatorsAsStrings);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest in project besu by hyperledger.
the class CliqueGetSignersTest method returnsValidatorsForBlockNumber.
@Test
@SuppressWarnings("unchecked")
public void returnsValidatorsForBlockNumber() {
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "clique_getSigners", new Object[] { "0x2EC88B" }));
when(blockchainQueries.blockByNumber(3065995L)).thenReturn(Optional.of(blockWithMetadata));
when(blockWithMetadata.getHeader()).thenReturn(blockHeader);
when(validatorProvider.getValidatorsAfterBlock(blockHeader)).thenReturn(validators);
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
assertThat(response.getResult()).isEqualTo(validatorAsStrings);
}
Aggregations