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