Search in sources :

Example 1 with Log

use of org.hyperledger.besu.evm.log.Log in project hedera-services by hashgraph.

the class EncodingFacadeTest method logBuilderWithTopicsWithDifferentTypes.

@Test
void logBuilderWithTopicsWithDifferentTypes() {
    final var log = EncodingFacade.LogBuilder.logBuilder().forLogger(logger).forEventSignature(TRANSFER_EVENT).forIndexedArgument(senderAddress).forIndexedArgument(20L).forIndexedArgument(BigInteger.valueOf(20)).forIndexedArgument(Boolean.TRUE).forIndexedArgument(false).build();
    final List<LogTopic> topics = new ArrayList<>();
    topics.add(LogTopic.wrap(Bytes.fromHexString("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")));
    topics.add(LogTopic.wrap(Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000008")));
    topics.add(LogTopic.wrap(Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000014")));
    topics.add(LogTopic.wrap(Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000014")));
    topics.add(LogTopic.wrap(Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")));
    topics.add(LogTopic.wrap(Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")));
    assertEquals(new Log(logger, Bytes.EMPTY, topics), log);
}
Also used : Log(org.hyperledger.besu.evm.log.Log) ArrayList(java.util.ArrayList) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.jupiter.api.Test)

Example 2 with Log

use of org.hyperledger.besu.evm.log.Log in project hedera-services by hashgraph.

the class EncodingFacadeTest method logBuilderWithTopics.

@Test
void logBuilderWithTopics() {
    final var log = EncodingFacade.LogBuilder.logBuilder().forLogger(logger).forEventSignature(TRANSFER_EVENT).forIndexedArgument(senderAddress).forIndexedArgument(recipientAddress).build();
    final List<LogTopic> topics = new ArrayList<>();
    topics.add(LogTopic.wrap(Bytes.fromHexString("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")));
    topics.add(LogTopic.wrap(Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000008")));
    topics.add(LogTopic.wrap(Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000006")));
    assertEquals(new Log(logger, Bytes.EMPTY, topics), log);
}
Also used : Log(org.hyperledger.besu.evm.log.Log) ArrayList(java.util.ArrayList) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.jupiter.api.Test)

Example 3 with Log

use of org.hyperledger.besu.evm.log.Log in project hedera-services by hashgraph.

the class TransactionProcessingResultTest method assertCorrectDataOnSuccessfulTransaction.

@Test
void assertCorrectDataOnSuccessfulTransaction() {
    var firstContract = new Account(new Id(0, 0, 1003));
    var secondContract = new Account(new Id(0, 0, 1004));
    var listOfCreatedContracts = List.of(firstContract.getId().asGrpcContract(), secondContract.getId().asGrpcContract());
    var log = new Log(logger.getId().asEvmAddress(), Bytes.fromHexString("0x0102"), List.of(logTopic, logTopic, logTopic, logTopic));
    final var logList = List.of(log);
    final var firstContractChanges = new TreeMap<Bytes, Pair<Bytes, Bytes>>(BytesComparator.INSTANCE);
    firstContractChanges.put(UInt256.valueOf(1L), new ImmutablePair<>(UInt256.valueOf(1L), null));
    final var secondContractChanges = new TreeMap<Bytes, Pair<Bytes, Bytes>>(BytesComparator.INSTANCE);
    secondContractChanges.put(UInt256.valueOf(1L), new ImmutablePair<>(UInt256.valueOf(1L), UInt256.valueOf(2L)));
    secondContractChanges.put(UInt256.valueOf(2L), new ImmutablePair<>(UInt256.valueOf(55L), UInt256.valueOf(255L)));
    final Map<Address, Map<Bytes, Pair<Bytes, Bytes>>> contractStateChanges = new TreeMap<>(BytesComparator.INSTANCE);
    contractStateChanges.put(firstContract.getId().asEvmAddress(), firstContractChanges);
    contractStateChanges.put(secondContract.getId().asEvmAddress(), secondContractChanges);
    final var expect = ContractFunctionResult.newBuilder().setGasUsed(GAS_USAGE).setBloom(ByteString.copyFrom(LogsBloomFilter.builder().insertLogs(logList).build().toArray()));
    expect.setContractCallResult(ByteString.copyFrom(Bytes.EMPTY.toArray()));
    expect.setContractID(EntityIdUtils.contractIdFromEvmAddress(recipient.getId().asEvmAddress().toArray()));
    expect.addAllCreatedContractIDs(listOfCreatedContracts);
    final var firstContractChangesRpc = ContractStateChange.newBuilder().setContractID(firstContract.getId().asGrpcContract()).addStorageChanges(StorageChange.newBuilder().setSlot(ByteString.copyFrom(UInt256.valueOf(1L).trimLeadingZeros().toArrayUnsafe())).setValueRead(ByteString.copyFrom(UInt256.valueOf(1L).trimLeadingZeros().toArrayUnsafe())).build()).build();
    final var secondContractChangesRpc = ContractStateChange.newBuilder().setContractID(secondContract.getId().asGrpcContract()).addStorageChanges(StorageChange.newBuilder().setSlot(ByteString.copyFrom(UInt256.valueOf(1L).trimLeadingZeros().toArrayUnsafe())).setValueRead(ByteString.copyFrom(UInt256.valueOf(1L).trimLeadingZeros().toArrayUnsafe())).setValueWritten(BytesValue.newBuilder().setValue(ByteString.copyFrom(UInt256.valueOf(2L).trimLeadingZeros().toArrayUnsafe()))).build()).addStorageChanges(StorageChange.newBuilder().setSlot(ByteString.copyFrom(UInt256.valueOf(2L).trimLeadingZeros().toArrayUnsafe())).setValueRead(ByteString.copyFrom(UInt256.valueOf(55L).trimLeadingZeros().toArrayUnsafe())).setValueWritten(BytesValue.newBuilder().setValue(ByteString.copyFrom(UInt256.valueOf(255L).trimLeadingZeros().toArrayUnsafe()))).build()).build();
    expect.addAllStateChanges(List.of(firstContractChangesRpc, secondContractChangesRpc));
    var result = TransactionProcessingResult.successful(logList, GAS_USAGE, GAS_REFUND, 1234L, Bytes.EMPTY, recipient.getId().asEvmAddress(), contractStateChanges);
    result.setCreatedContracts(listOfCreatedContracts);
    assertEquals(expect.getGasUsed(), result.getGasUsed());
    final var resultAsGrpc = result.toGrpc();
    assertEquals(GAS_REFUND, result.getSbhRefund());
    assertEquals(Optional.empty(), result.getHaltReason());
    assertEquals(expect.getBloom(), resultAsGrpc.getBloom());
    assertEquals(expect.getContractID(), resultAsGrpc.getContractID());
    assertEquals(ByteString.EMPTY, resultAsGrpc.getContractCallResult());
    assertEquals(listOfCreatedContracts, resultAsGrpc.getCreatedContractIDsList());
}
Also used : Account(com.hedera.services.store.models.Account) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Log(org.hyperledger.besu.evm.log.Log) Id(com.hedera.services.store.models.Id) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.jupiter.api.Test)

Example 4 with Log

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

the class FlexiblePrivacyPrecompiledContractTest method testPayloadFoundInEnclave.

@Test
public void testPayloadFoundInEnclave() {
    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 5 with Log

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

the class PrivacyPrecompiledContractTest method testPayloadFoundInEnclave.

@Test
public void testPayloadFoundInEnclave() {
    final Enclave enclave = mock(Enclave.class);
    when(enclave.retrievePrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID)).thenReturn(new PrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", Arrays.asList(VALID_BASE64_ENCLAVE_KEY.toBase64String())));
    final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final List<Log> logs = new ArrayList<>();
    contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.successful(logs, 0, 0, Bytes.fromHexString(DEFAULT_OUTPUT), null)));
    final PrivateTransaction privateTransaction = privateTransactionBesu();
    final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
    final String privateFrom = privateTransaction.getPrivateFrom().toBase64String();
    final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
    when(enclave.receive(any(String.class))).thenReturn(response);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Log(org.hyperledger.besu.evm.log.Log) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) ArrayList(java.util.ArrayList) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Bytes(org.apache.tuweni.bytes.Bytes) Enclave(org.hyperledger.besu.enclave.Enclave) 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