Search in sources :

Example 1 with LogResult

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);
    }
}
Also used : Log(org.hyperledger.besu.evm.log.Log) LogResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) BlockWithReceipts(org.hyperledger.besu.ethereum.core.BlockWithReceipts) Block(org.hyperledger.besu.ethereum.core.Block) Test(org.junit.Test)

Example 2 with LogResult

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());
}
Also used : Address(org.hyperledger.besu.datatypes.Address) LogResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult) BlockWithReceipts(org.hyperledger.besu.ethereum.core.BlockWithReceipts) Test(org.junit.Test)

Example 3 with LogResult

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);
}
Also used : Log(org.hyperledger.besu.evm.log.Log) LogResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) BlockWithReceipts(org.hyperledger.besu.ethereum.core.BlockWithReceipts) Block(org.hyperledger.besu.ethereum.core.Block) Test(org.junit.Test)

Example 4 with LogResult

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);
}
Also used : Log(org.hyperledger.besu.evm.log.Log) LogResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) BlockWithReceipts(org.hyperledger.besu.ethereum.core.BlockWithReceipts) Block(org.hyperledger.besu.ethereum.core.Block) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 5 with LogResult

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());
}
Also used : Address(org.hyperledger.besu.datatypes.Address) LogResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult) BlockWithReceipts(org.hyperledger.besu.ethereum.core.BlockWithReceipts) Test(org.junit.Test)

Aggregations

LogResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult)7 BlockWithReceipts (org.hyperledger.besu.ethereum.core.BlockWithReceipts)7 Test (org.junit.Test)7 Log (org.hyperledger.besu.evm.log.Log)5 Block (org.hyperledger.besu.ethereum.core.Block)4 TransactionReceipt (org.hyperledger.besu.ethereum.core.TransactionReceipt)4 Address (org.hyperledger.besu.datatypes.Address)2 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)2 ArrayList (java.util.ArrayList)1