use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult in project besu by hyperledger.
the class LogsSubscriptionServiceTest method multipleSubscriptionsForSingleMatchingLog.
@Test
public void multipleSubscriptionsForSingleMatchingLog() {
final BlockWithReceipts blockWithReceipts = generateBlock(2, 2, 2);
final Block block = blockWithReceipts.getBlock();
final List<TransactionReceipt> receipts = blockWithReceipts.getReceipts();
final int txIndex = 1;
final int logIndex = 1;
final Log targetLog = receipts.get(txIndex).getLogsList().get(logIndex);
final List<LogsSubscription> subscriptions = Stream.generate(() -> createSubscription(targetLog.getLogger())).limit(3).collect(Collectors.toList());
registerSubscriptions(subscriptions);
blockchain.appendBlock(blockWithReceipts.getBlock(), blockWithReceipts.getReceipts());
for (LogsSubscription subscription : subscriptions) {
final ArgumentCaptor<LogResult> captor = ArgumentCaptor.forClass(LogResult.class);
verify(subscriptionManager).sendMessage(eq(subscription.getSubscriptionId()), captor.capture());
final List<LogResult> logResults = captor.getAllValues();
assertThat(logResults).hasSize(1);
final LogResult result = logResults.get(0);
assertLogResultMatches(result, block, receipts, txIndex, logIndex, false);
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult in project besu by hyperledger.
the class LogsSubscriptionServiceTest method noMatchingLogsEmitted.
@Test
public void noMatchingLogsEmitted() {
final Address address = Address.fromHexString("0x0");
final LogsSubscription subscription = createSubscription(address);
registerSubscriptions(subscription);
final BlockWithReceipts blockWithReceipts = generateBlock(2, 2, 2);
blockchain.appendBlock(blockWithReceipts.getBlock(), blockWithReceipts.getReceipts());
final ArgumentCaptor<LogResult> captor = ArgumentCaptor.forClass(LogResult.class);
verify(subscriptionManager, times(0)).sendMessage(eq(subscription.getSubscriptionId()), captor.capture());
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult in project besu by hyperledger.
the class LogsSubscriptionServiceTest method singleMatchingLogEvent.
@Test
public void singleMatchingLogEvent() {
final BlockWithReceipts blockWithReceipts = generateBlock(2, 2, 2);
final Block block = blockWithReceipts.getBlock();
final List<TransactionReceipt> receipts = blockWithReceipts.getReceipts();
final int txIndex = 1;
final int logIndex = 1;
final Log targetLog = receipts.get(txIndex).getLogsList().get(logIndex);
final LogsSubscription subscription = createSubscription(targetLog.getLogger());
registerSubscriptions(subscription);
blockchain.appendBlock(blockWithReceipts.getBlock(), blockWithReceipts.getReceipts());
final ArgumentCaptor<LogResult> captor = ArgumentCaptor.forClass(LogResult.class);
verify(subscriptionManager).sendMessage(eq(subscription.getSubscriptionId()), captor.capture());
final List<LogResult> logResults = captor.getAllValues();
assertThat(logResults).hasSize(1);
final LogResult result = logResults.get(0);
assertLogResultMatches(result, block, receipts, txIndex, logIndex, false);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult in project besu by hyperledger.
the class LogsSubscriptionServiceTest method singleMatchingLogEmittedThenRemovedInReorg.
@Test
public void singleMatchingLogEmittedThenRemovedInReorg() {
// Create block that emits an event
final BlockWithReceipts blockWithReceipts = generateBlock(2, 2, 2);
final Block block = blockWithReceipts.getBlock();
final List<TransactionReceipt> receipts = blockWithReceipts.getReceipts();
final int txIndex = 1;
final int logIndex = 1;
final Log targetLog = receipts.get(txIndex).getLogsList().get(logIndex);
final LogsSubscription subscription = createSubscription(targetLog.getLogger());
registerSubscriptions(subscription);
blockchain.appendBlock(blockWithReceipts.getBlock(), blockWithReceipts.getReceipts());
// Cause a reorg that removes the block which emitted an event
BlockHeader parentHeader = blockchain.getGenesisBlock().getHeader();
while (!blockchain.getChainHeadHash().equals(parentHeader.getHash())) {
final BlockWithReceipts newBlock = generateBlock(parentHeader, 2, 0, 0);
parentHeader = newBlock.getBlock().getHeader();
blockchain.appendBlock(newBlock.getBlock(), newBlock.getReceipts());
}
final ArgumentCaptor<LogResult> captor = ArgumentCaptor.forClass(LogResult.class);
verify(subscriptionManager, times(2)).sendMessage(eq(subscription.getSubscriptionId()), captor.capture());
final List<LogResult> logResults = captor.getAllValues();
assertThat(logResults).hasSize(2);
final LogResult firstLog = logResults.get(0);
assertLogResultMatches(firstLog, block, receipts, txIndex, logIndex, false);
final LogResult secondLog = logResults.get(1);
assertLogResultMatches(secondLog, block, receipts, txIndex, logIndex, true);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult in project besu by hyperledger.
the class LogsSubscriptionServiceTest method noLogsEmitted.
@Test
public void noLogsEmitted() {
final Address address = Address.fromHexString("0x0");
final LogsSubscription subscription = createSubscription(address);
registerSubscriptions(subscription);
final BlockWithReceipts blockWithReceipts = generateBlock(2, 0, 0);
blockchain.appendBlock(blockWithReceipts.getBlock(), blockWithReceipts.getReceipts());
final ArgumentCaptor<LogResult> captor = ArgumentCaptor.forClass(LogResult.class);
verify(subscriptionManager, times(0)).sendMessage(eq(subscription.getSubscriptionId()), captor.capture());
}
Aggregations