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);
}
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);
}
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());
}
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));
}
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));
}
Aggregations