Search in sources :

Example 1 with DefaultSyncStatus

use of org.hyperledger.besu.ethereum.core.DefaultSyncStatus in project besu by hyperledger.

the class EthSyncingTest method shouldReturnExpectedValueWhenSyncStatusIsNotEmpty.

@Test
public void shouldReturnExpectedValueWhenSyncStatusIsNotEmpty() {
    final JsonRpcRequestContext request = requestWithParams();
    final SyncStatus expectedSyncStatus = new DefaultSyncStatus(0, 1, 2, Optional.empty(), Optional.empty());
    final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), new SyncingResult(expectedSyncStatus));
    final Optional<SyncStatus> optionalSyncStatus = Optional.of(expectedSyncStatus);
    when(synchronizer.getSyncStatus()).thenReturn(optionalSyncStatus);
    final JsonRpcResponse actualResponse = method.response(request);
    assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);
    verify(synchronizer).getSyncStatus();
    verifyNoMoreInteractions(synchronizer);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) SyncingResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 2 with DefaultSyncStatus

use of org.hyperledger.besu.ethereum.core.DefaultSyncStatus in project besu by hyperledger.

the class SyncingSubscriptionServiceTest method shouldSendSyncStatusWhenReceiveSyncStatus.

@Test
public void shouldSendSyncStatusWhenReceiveSyncStatus() {
    final SyncingSubscription subscription = new SyncingSubscription(9L, "conn", SubscriptionType.SYNCING);
    final List<SyncingSubscription> subscriptions = Collections.singletonList(subscription);
    final Optional<SyncStatus> syncStatus = Optional.of(new DefaultSyncStatus(0L, 1L, 3L, Optional.empty(), Optional.empty()));
    final JsonRpcResult expectedSyncingResult = new SyncingResult(syncStatus.get());
    doAnswer(invocation -> {
        Consumer<List<SyncingSubscription>> consumer = invocation.getArgument(2);
        consumer.accept(subscriptions);
        return null;
    }).when(subscriptionManager).notifySubscribersOnWorkerThread(any(), any(), any());
    syncStatusListener.onSyncStatusChanged(syncStatus);
    verify(subscriptionManager).sendMessage(ArgumentMatchers.eq(subscription.getSubscriptionId()), eq(expectedSyncingResult));
}
Also used : SyncingResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) JsonRpcResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult) List(java.util.List) Test(org.junit.Test)

Example 3 with DefaultSyncStatus

use of org.hyperledger.besu.ethereum.core.DefaultSyncStatus in project besu by hyperledger.

the class EthSyncingTest method shouldReturnExpectedValueWhenFastSyncStatusIsNotEmpty.

@Test
public void shouldReturnExpectedValueWhenFastSyncStatusIsNotEmpty() {
    final JsonRpcRequestContext request = requestWithParams();
    final SyncStatus expectedSyncStatus = new DefaultSyncStatus(0, 1, 2, Optional.of(3L), Optional.of(4L));
    final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), new SyncingResult(expectedSyncStatus));
    final Optional<SyncStatus> optionalSyncStatus = Optional.of(expectedSyncStatus);
    when(synchronizer.getSyncStatus()).thenReturn(optionalSyncStatus);
    final JsonRpcResponse actualResponse = method.response(request);
    assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);
    verify(synchronizer).getSyncStatus();
    verifyNoMoreInteractions(synchronizer);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) SyncingResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 4 with DefaultSyncStatus

use of org.hyperledger.besu.ethereum.core.DefaultSyncStatus in project besu by hyperledger.

the class JsonRpcHttpServiceTest method ethFastSyncingResultIsPresent.

@Test
public void ethFastSyncingResultIsPresent() throws Exception {
    final SyncStatus testResult = new DefaultSyncStatus(1L, 8L, 7L, Optional.of(6L), Optional.of(5L));
    when(synchronizer.getSyncStatus()).thenReturn(Optional.of(testResult));
    final String id = "999";
    final RequestBody body = RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}");
    try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
        final String respBody = resp.body().string();
        final JsonObject json = new JsonObject(respBody);
        final JsonObject result = json.getJsonObject("result");
        final long startingBlock = Long.decode(result.getString("startingBlock"));
        assertThat(startingBlock).isEqualTo(1L);
        final long currentBlock = Long.decode(result.getString("currentBlock"));
        assertThat(currentBlock).isEqualTo(8L);
        final long highestBlock = Long.decode(result.getString("highestBlock"));
        assertThat(highestBlock).isEqualTo(7L);
        final long pulledStates = Long.decode(result.getString("pulledStates"));
        assertThat(pulledStates).isEqualTo(6L);
        final long knownStates = Long.decode(result.getString("knownStates"));
        assertThat(knownStates).isEqualTo(5L);
    }
}
Also used : Response(okhttp3.Response) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) JsonObject(io.vertx.core.json.JsonObject) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Example 5 with DefaultSyncStatus

use of org.hyperledger.besu.ethereum.core.DefaultSyncStatus in project besu by hyperledger.

the class JsonRpcHttpServiceTest method ethSyncingResultIsPresent.

@Test
public void ethSyncingResultIsPresent() throws Exception {
    final SyncStatus testResult = new DefaultSyncStatus(1L, 8L, 7L, Optional.empty(), Optional.empty());
    when(synchronizer.getSyncStatus()).thenReturn(Optional.of(testResult));
    final String id = "999";
    final RequestBody body = RequestBody.create(JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}");
    try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
        final String respBody = resp.body().string();
        final JsonObject json = new JsonObject(respBody);
        final JsonObject result = json.getJsonObject("result");
        final long startingBlock = Long.decode(result.getString("startingBlock"));
        assertThat(startingBlock).isEqualTo(1L);
        final long currentBlock = Long.decode(result.getString("currentBlock"));
        assertThat(currentBlock).isEqualTo(8L);
        final long highestBlock = Long.decode(result.getString("highestBlock"));
        assertThat(highestBlock).isEqualTo(7L);
    }
}
Also used : Response(okhttp3.Response) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) JsonObject(io.vertx.core.json.JsonObject) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Aggregations

DefaultSyncStatus (org.hyperledger.besu.ethereum.core.DefaultSyncStatus)6 SyncStatus (org.hyperledger.besu.plugin.data.SyncStatus)6 Test (org.junit.Test)5 SyncingResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult)3 JsonObject (io.vertx.core.json.JsonObject)2 List (java.util.List)2 RequestBody (okhttp3.RequestBody)2 Response (okhttp3.Response)2 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)2 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)2 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 Charsets (com.google.common.base.Charsets)1 Resources (com.google.common.io.Resources)1 GraphQL (graphql.GraphQL)1 Vertx (io.vertx.core.Vertx)1 URL (java.net.URL)1 Paths (java.nio.file.Paths)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1