Search in sources :

Example 1 with SyncStatus

use of org.hyperledger.besu.plugin.data.SyncStatus 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 SyncStatus

use of org.hyperledger.besu.plugin.data.SyncStatus 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 SyncStatus

use of org.hyperledger.besu.plugin.data.SyncStatus in project besu by hyperledger.

the class SyncingSubscriptionServiceTest method shouldSendNotSyncingResultWhenReceiveNonSyncingStatus.

@Test
public void shouldSendNotSyncingResultWhenReceiveNonSyncingStatus() {
    final SyncingSubscription subscription = new SyncingSubscription(9L, "conn", SubscriptionType.SYNCING);
    final List<SyncingSubscription> subscriptions = Collections.singletonList(subscription);
    final Optional<SyncStatus> syncStatus = Optional.empty();
    final JsonRpcResult expectedSyncingResult = new NotSynchronisingResult();
    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 : 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 4 with SyncStatus

use of org.hyperledger.besu.plugin.data.SyncStatus in project besu by hyperledger.

the class EthGetBlockByNumberLatestDesyncIntegrationTest method setUpOnce.

@BeforeAll
public static void setUpOnce() throws Exception {
    final String genesisJson = Resources.toString(BlockTestUtil.getTestGenesisUrl(), Charsets.UTF_8);
    BlockchainImporter importer = new BlockchainImporter(BlockTestUtil.getTestBlockchainUrl(), genesisJson);
    MutableBlockchain chain = InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock());
    WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive();
    importer.getGenesisState().writeStateTo(state.getMutable());
    ProtocolContext context = new ProtocolContext(chain, state, null);
    for (final Block block : importer.getBlocks()) {
        final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
        final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
        final BlockImporter blockImporter = protocolSpec.getBlockImporter();
        blockImporter.importBlock(context, block, HeaderValidationMode.FULL);
    }
    methodsFactorySynced = new JsonRpcTestMethodsFactory(importer, chain, state, context);
    WorldStateArchive unsynced = mock(WorldStateArchive.class);
    when(unsynced.isWorldStateAvailable(any(Hash.class), any(Hash.class))).thenReturn(false);
    methodsFactoryDesynced = new JsonRpcTestMethodsFactory(importer, chain, unsynced, context);
    WorldStateArchive midSync = mock(WorldStateArchive.class);
    when(midSync.isWorldStateAvailable(any(Hash.class), any(Hash.class))).thenReturn(true);
    Synchronizer synchronizer = mock(Synchronizer.class);
    SyncStatus status = mock(SyncStatus.class);
    when(status.getCurrentBlock()).thenReturn(// random choice for current sync state.
    ARBITRARY_SYNC_BLOCK);
    when(synchronizer.getSyncStatus()).thenReturn(Optional.of(status));
    methodsFactoryMidDownload = new JsonRpcTestMethodsFactory(importer, chain, midSync, context, synchronizer);
}
Also used : Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) BlockchainImporter(org.hyperledger.besu.ethereum.api.jsonrpc.BlockchainImporter) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Hash(org.hyperledger.besu.datatypes.Hash) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter) JsonRpcTestMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcTestMethodsFactory) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with SyncStatus

use of org.hyperledger.besu.plugin.data.SyncStatus 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)

Aggregations

SyncStatus (org.hyperledger.besu.plugin.data.SyncStatus)9 DefaultSyncStatus (org.hyperledger.besu.ethereum.core.DefaultSyncStatus)8 Test (org.junit.Test)7 List (java.util.List)3 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)3 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)3 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)3 SyncingResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult)3 JsonObject (io.vertx.core.json.JsonObject)2 RequestBody (okhttp3.RequestBody)2 Response (okhttp3.Response)2 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)2 JsonRpcResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult)2 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)2 Block (org.hyperledger.besu.ethereum.core.Block)2 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)2 Synchronizer (org.hyperledger.besu.ethereum.core.Synchronizer)2 Charsets (com.google.common.base.Charsets)1 Resources (com.google.common.io.Resources)1 GraphQL (graphql.GraphQL)1