Search in sources :

Example 1 with JsonRpcSuccessResponse

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

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 3 with JsonRpcSuccessResponse

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) Address(org.hyperledger.besu.datatypes.Address) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 4 with JsonRpcSuccessResponse

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);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult) Test(org.junit.Test)

Example 5 with JsonRpcSuccessResponse

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);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult) Test(org.junit.Test)

Aggregations

JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)352 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)227 Test (org.junit.Test)219 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)186 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)83 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)56 Address (org.hyperledger.besu.datatypes.Address)42 Test (org.junit.jupiter.api.Test)37 Hash (org.hyperledger.besu.datatypes.Hash)33 ArrayList (java.util.ArrayList)27 Collection (java.util.Collection)22 JsonCallParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter)22 JsonObject (io.vertx.core.json.JsonObject)19 SignerMetricResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult)19 HashMap (java.util.HashMap)17 List (java.util.List)16 LogsResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogsResult)16 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)16 Transaction (org.hyperledger.besu.ethereum.core.Transaction)15 PrivacyGroup (org.hyperledger.besu.enclave.types.PrivacyGroup)13