Search in sources :

Example 1 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class EthNewFilterTest method newFilterWithAddressOnlyParamInstallsExpectedLogFilter.

@Test
public void newFilterWithAddressOnlyParamInstallsExpectedLogFilter() {
    final Address address = Address.fromHexString("0x0");
    final FilterParameter filterParameter = filterParamWithAddressAndTopics(address, null);
    final JsonRpcRequestContext request = ethNewFilter(filterParameter);
    final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), "0x1");
    final LogsQuery expectedLogsQuery = new LogsQuery.Builder().address(address).build();
    when(filterManager.installLogFilter(any(), any(), eq(expectedLogsQuery))).thenReturn("0x1");
    final JsonRpcResponse actualResponse = method.response(request);
    assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);
    verify(filterManager).installLogFilter(refEq(BlockParameter.LATEST), refEq(BlockParameter.LATEST), eq(expectedLogsQuery));
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) Address(org.hyperledger.besu.datatypes.Address) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) FilterParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter) Test(org.junit.Test)

Example 2 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class FilterManagerLogFilterTest method privateLogFilterShouldQueryPrivacyQueriesObject.

@Test
public void privateLogFilterShouldQueryPrivacyQueriesObject() {
    final LogWithMetadata logWithMetadata = logWithMetadata();
    final LogsQuery logsQuery = logsQuery();
    when(privacyQueries.matchingLogs(eq(PRIVACY_GROUP_ID), any(), eq(logsQuery))).thenReturn(singletonList(logWithMetadata));
    final String filterId = filterManager.installPrivateLogFilter(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY, latest(), latest(), logsQuery);
    final Hash blockAddedHash = recordBlockEvents(1).get(0).getBlock().getHash();
    verify(privacyQueries).matchingLogs(eq(PRIVACY_GROUP_ID), eq(blockAddedHash), eq(logsQuery));
    assertThat(filterManager.logsChanges(filterId).get(0)).isEqualTo(logWithMetadata);
}
Also used : LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) Hash(org.hyperledger.besu.datatypes.Hash) Test(org.junit.Test)

Example 3 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class LogsQueryTest method univariateTopicQueryLogWithoutTopicReturnFalse.

@Test
public void univariateTopicQueryLogWithoutTopicReturnFalse() {
    final Address address = Address.fromHexString("0x1111111111111111111111111111111111111111");
    final LogTopic topic = LogTopic.fromHexString("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    final List<LogTopic> topics = new ArrayList<>();
    topics.add(topic);
    final List<List<LogTopic>> topicsQuery = new ArrayList<>();
    topicsQuery.add(topics);
    final LogsQuery query = new LogsQuery.Builder().address(address).topics(topicsQuery).build();
    final Log log = new Log(address, data, Lists.newArrayList());
    assertThat(query.matches(log)).isFalse();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) Log(org.hyperledger.besu.evm.log.Log) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.Test)

Example 4 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class LogsQueryTest method multivariateTopicQueryMismatchReturnFalse.

@Test
public void multivariateTopicQueryMismatchReturnFalse() {
    final Address address = Address.fromHexString("0x1111111111111111111111111111111111111111");
    final LogTopic topic1 = LogTopic.fromHexString("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    final LogTopic topic2 = LogTopic.fromHexString("0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
    final LogTopic topic3 = LogTopic.fromHexString("0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc");
    final List<LogTopic> logTopics = new ArrayList<>();
    logTopics.add(topic1);
    logTopics.add(topic2);
    final List<LogTopic> queryTopics = new ArrayList<>();
    queryTopics.add(topic3);
    final List<List<LogTopic>> queryParameter = new ArrayList<>();
    queryParameter.add(queryTopics);
    final LogsQuery query = new LogsQuery.Builder().address(address).topics(queryParameter).build();
    final Log log = new Log(address, data, logTopics);
    assertThat(query.matches(log)).isFalse();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) Log(org.hyperledger.besu.evm.log.Log) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.Test)

Example 5 with LogsQuery

use of org.hyperledger.besu.ethereum.api.query.LogsQuery in project besu by hyperledger.

the class LogsQueryTest method univariateTopicQueryMatchReturnTrue.

@Test
public void univariateTopicQueryMatchReturnTrue() {
    final Address address = Address.fromHexString("0x1111111111111111111111111111111111111111");
    final LogTopic topic = LogTopic.fromHexString("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    final List<LogTopic> topics = new ArrayList<>();
    topics.add(topic);
    final List<List<LogTopic>> topicsQuery = new ArrayList<>();
    topicsQuery.add(topics);
    final LogsQuery query = new LogsQuery.Builder().address(address).topics(topicsQuery).build();
    final Log log = new Log(address, data, Lists.newArrayList(topic));
    assertThat(query.couldMatch(LogsBloomFilter.builder().insertLog(log).build())).isTrue();
    assertThat(query.matches(log)).isTrue();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) Log(org.hyperledger.besu.evm.log.Log) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.Test)

Aggregations

LogsQuery (org.hyperledger.besu.ethereum.api.query.LogsQuery)28 Test (org.junit.Test)24 Address (org.hyperledger.besu.datatypes.Address)22 ArrayList (java.util.ArrayList)19 LogTopic (org.hyperledger.besu.evm.log.LogTopic)19 List (java.util.List)18 Log (org.hyperledger.besu.evm.log.Log)18 Collections.emptyList (java.util.Collections.emptyList)14 Collections.singletonList (java.util.Collections.singletonList)13 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)6 FilterParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter)6 Hash (org.hyperledger.besu.datatypes.Hash)4 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)4 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)4 LogWithMetadata (org.hyperledger.besu.ethereum.core.LogWithMetadata)4 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 TransactionPool (org.hyperledger.besu.ethereum.eth.transactions.TransactionPool)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1