use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse 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.response.JsonRpcSuccessResponse in project besu by hyperledger.
the class PrivGetEeaTransactionCountTest method validRequestProducesExpectedNonce.
@Test
public void validRequestProducesExpectedNonce() {
final long reportedNonce = 8L;
final PrivGetEeaTransactionCount method = new PrivGetEeaTransactionCount(privacyController, privacyIdProvider);
when(privacyController.determineNonce(any(), any(), eq(ENCLAVE_PUBLIC_KEY))).thenReturn(reportedNonce);
final JsonRpcResponse response = method.response(request);
assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);
final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response;
final int returnedValue = Integer.decode((String) successResponse.getResult());
assertThat(returnedValue).isEqualTo(reportedNonce);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse in project besu by hyperledger.
the class QbftDiscardValidatorVoteTest method discardValidator.
@Test
public void discardValidator() {
final Address parameterAddress = Address.fromHexString("1");
final JsonRpcRequestContext request = requestWithParams(parameterAddress);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), true);
final JsonRpcResponse response = method.response(request);
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
verify(voteProvider).discardVote(parameterAddress);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse in project besu by hyperledger.
the class QbftGetSignerMetricsTest method getSignerMetricsWithEarliest.
@Test
@SuppressWarnings("unchecked")
public void getSignerMetricsWithEarliest() {
final long startBlock = 0L;
final long endBlock = 3L;
final List<SignerMetricResult> signerMetricResultList = new ArrayList<>();
when(blockchainQueries.headBlockNumber()).thenReturn(endBlock);
LongStream.range(startBlock, endBlock).forEach(value -> signerMetricResultList.add(generateBlock(value)));
final JsonRpcRequestContext request = requestWithParams("earliest", String.valueOf(endBlock));
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
assertThat((Collection<SignerMetricResult>) response.getResult()).containsExactlyInAnyOrderElementsOf(signerMetricResultList);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse in project besu by hyperledger.
the class QbftGetSignerMetricsTest method getSignerMetricsWhenNoParams.
@Test
@SuppressWarnings("unchecked")
public void getSignerMetricsWhenNoParams() {
final long startBlock = 1L;
final long endBlock = 3L;
when(blockchainQueries.headBlockNumber()).thenReturn(endBlock);
final List<SignerMetricResult> signerMetricResultList = new ArrayList<>();
LongStream.range(startBlock, endBlock).forEach(value -> signerMetricResultList.add(generateBlock(value)));
// missing validator
signerMetricResultList.add(new SignerMetricResult(VALIDATORS[0]));
final JsonRpcRequestContext request = requestWithParams();
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
assertThat((Collection<SignerMetricResult>) response.getResult()).containsExactlyInAnyOrderElementsOf(signerMetricResultList);
}
Aggregations