Search in sources :

Example 6 with Log

use of org.hyperledger.besu.evm.log.Log in project besu by hyperledger.

the class FlexiblePrivacyPrecompiledContractTest method testPayloadFoundInEnclaveWith32ByteResult.

@Test
public void testPayloadFoundInEnclaveWith32ByteResult() {
    final Enclave enclave = mock(Enclave.class);
    final FlexiblePrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final List<Log> logs = new ArrayList<>();
    contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.successful(logs, 0, 0, Bytes.fromHexString(DEFAULT_OUTPUT), null)));
    final VersionedPrivateTransaction versionedPrivateTransaction = versionedPrivateTransactionBesu();
    final byte[] payload = convertVersionedPrivateTransactionToBytes(versionedPrivateTransaction);
    final String privateFrom = versionedPrivateTransaction.getPrivateTransaction().getPrivateFrom().toBase64String();
    final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
    when(enclave.receive(any())).thenReturn(response);
    final FlexiblePrivacyPrecompiledContract contractSpy = spy(contract);
    Mockito.doReturn(true).when(contractSpy).canExecute(any(), any(), any(), any(), any(), any(), any(), any());
    final PrecompiledContract.PrecompileContractResult result = contractSpy.computePrecompile(privateTransactionLookupId, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Log(org.hyperledger.besu.evm.log.Log) Enclave(org.hyperledger.besu.enclave.Enclave) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) ArrayList(java.util.ArrayList) VersionedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction) Test(org.junit.Test)

Example 7 with Log

use of org.hyperledger.besu.evm.log.Log 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 8 with Log

use of org.hyperledger.besu.evm.log.Log 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 9 with Log

use of org.hyperledger.besu.evm.log.Log 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)

Example 10 with Log

use of org.hyperledger.besu.evm.log.Log in project besu by hyperledger.

the class LogsQueryTest method wildcardQueryAddressTopicReturnTrue.

@Test
public void wildcardQueryAddressTopicReturnTrue() {
    final LogsQuery query = new LogsQuery.Builder().build();
    final Address address = Address.fromHexString("0x1111111111111111111111111111111111111111");
    final List<LogTopic> topics = new ArrayList<>();
    final Log log = new Log(address, data, topics);
    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) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.Test)

Aggregations

Log (org.hyperledger.besu.evm.log.Log)53 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)30 Address (org.hyperledger.besu.datatypes.Address)24 LogTopic (org.hyperledger.besu.evm.log.LogTopic)22 LogsQuery (org.hyperledger.besu.ethereum.api.query.LogsQuery)18 Bytes (org.apache.tuweni.bytes.Bytes)17 List (java.util.List)13 Collections.emptyList (java.util.Collections.emptyList)12 Collections.singletonList (java.util.Collections.singletonList)12 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)7 BlockWithReceipts (org.hyperledger.besu.ethereum.core.BlockWithReceipts)6 PrecompiledContract (org.hyperledger.besu.evm.precompile.PrecompiledContract)6 Enclave (org.hyperledger.besu.enclave.Enclave)5 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)5 LogResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.LogResult)5 Block (org.hyperledger.besu.ethereum.core.Block)5 Transaction (org.hyperledger.besu.ethereum.core.Transaction)5 TransactionReceipt (org.hyperledger.besu.ethereum.core.TransactionReceipt)5 VersionedPrivateTransaction (org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction)4