use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult 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.api.jsonrpc.internal.results.JsonRpcResult 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));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult in project besu by hyperledger.
the class SubscriptionManagerSendMessageTest method shouldSendMessageOnTheConnectionIdEventBusAddressForExistingSubscription.
@Test
@Ignore
public void shouldSendMessageOnTheConnectionIdEventBusAddressForExistingSubscription(final TestContext context) {
final String connectionId = UUID.randomUUID().toString();
final SubscribeRequest subscribeRequest = new SubscribeRequest(SubscriptionType.SYNCING, null, null, connectionId);
final JsonRpcResult expectedResult = mock(JsonRpcResult.class);
final Subscription subscription = new Subscription(1L, connectionId, SubscriptionType.SYNCING, false);
final SubscriptionResponse expectedResponse = new SubscriptionResponse(subscription, expectedResult);
final Long subscriptionId = subscriptionManager.subscribe(subscribeRequest);
final Async async = context.async();
vertx.eventBus().consumer(connectionId).handler(msg -> {
context.assertEquals(Json.encode(expectedResponse), msg.body());
async.complete();
}).completionHandler(v -> subscriptionManager.sendMessage(subscriptionId, expectedResult));
async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult in project besu by hyperledger.
the class NewBlockHeadersSubscriptionServiceTest method shouldNotSendMessageWhenBlockAddedIsNotOnCanonicalChain.
@Test
public void shouldNotSendMessageWhenBlockAddedIsNotOnCanonicalChain() {
final NewBlockHeadersSubscription subscription = createSubscription(false);
mockSubscriptionManagerNotifyMethod(subscription);
final Block canonicalBlock = appendBlockWithParent(blockchain, genesisBlock);
final BlockOptions options = new BlockOptions().setBlockNumber(genesisBlock.getHeader().getNumber() + 1).setParentHash(genesisBlock.getHash()).setDifficulty(genesisBlock.getHeader().getDifficulty().divide(100L));
appendBlockWithParent(blockchain, options);
final BlockResult expectedNewBlock = blockResultFactory.transactionHash(blockchainQueriesSpy.blockByHashWithTxHashes(canonicalBlock.getHash()).orElse(null));
verify(subscriptionManagerSpy, times(1)).notifySubscribersOnWorkerThread(any(), any(), any());
verify(subscriptionManagerSpy, times(1)).sendMessage(subscriptionIdCaptor.capture(), responseCaptor.capture());
assertThat(subscriptionIdCaptor.getValue()).isEqualTo(subscription.getSubscriptionId());
List<JsonRpcResult> capturedNewBlocks = responseCaptor.getAllValues();
assertThat(capturedNewBlocks.size()).isEqualTo(1);
assertThat(capturedNewBlocks.get(0)).usingRecursiveComparison().isEqualTo(expectedNewBlock);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult in project besu by hyperledger.
the class NewBlockHeadersSubscriptionServiceTest method shouldSendMessagesWhenReorgBlockAdded.
@Test
public void shouldSendMessagesWhenReorgBlockAdded() {
final NewBlockHeadersSubscription subscription = createSubscription(false);
mockSubscriptionManagerNotifyMethod(subscription);
final Block canonicalBlock = appendBlockWithParent(blockchain, genesisBlock);
final BlockOptions options = new BlockOptions().setBlockNumber(genesisBlock.getHeader().getNumber() + 1).setParentHash(genesisBlock.getHash()).setDifficulty(genesisBlock.getHeader().getDifficulty().divide(100L));
final Block forkBlock = appendBlockWithParent(blockchain, options);
options.setDifficulty(forkBlock.getHeader().getDifficulty().divide(100L));
appendBlockWithParent(blockchain, options);
options.setDifficulty(blockchain.getChainHeadBlock().getHeader().getDifficulty().multiply(2L));
final Block forkBlock2 = appendBlockWithParent(blockchain, options);
final BlockResult expectedNewBlock = blockResultFactory.transactionHash(blockchainQueriesSpy.blockByHashWithTxHashes(canonicalBlock.getHash()).orElse(null));
final BlockResult expectedNewBlock1 = blockResultFactory.transactionHash(blockchainQueriesSpy.blockByHashWithTxHashes(forkBlock2.getHash()).orElse(null));
verify(subscriptionManagerSpy, times(2)).notifySubscribersOnWorkerThread(any(), any(), any());
verify(subscriptionManagerSpy, times(2)).sendMessage(subscriptionIdCaptor.capture(), responseCaptor.capture());
assertThat(subscriptionIdCaptor.getValue()).isEqualTo(subscription.getSubscriptionId());
List<JsonRpcResult> capturedNewBlocks = responseCaptor.getAllValues();
assertThat(capturedNewBlocks.size()).isEqualTo(2);
assertThat(capturedNewBlocks.get(0)).usingRecursiveComparison().isEqualTo(expectedNewBlock);
assertThat(capturedNewBlocks.get(1)).usingRecursiveComparison().isEqualTo(expectedNewBlock1);
}
Aggregations