use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class ContractCallLocalAnswerTest method getsCallResponseWhenNoCtx.
@Test
void getsCallResponseWhenNoCtx() throws Throwable {
// setup:
Query sensibleQuery = validQuery(ANSWER_ONLY, 5L);
final var transactionProcessingResult = TransactionProcessingResult.failed(0, 0, 1, Optional.empty(), Optional.empty(), new TreeMap<>());
given(accountStore.loadAccount(any())).willReturn(new Account(Id.fromGrpcContract(target)));
given(accountStore.loadContract(any())).willReturn(new Account(Id.fromGrpcContract(target)));
given(evmTxProcessor.execute(any(), any(), anyLong(), anyLong(), any(), any())).willReturn(transactionProcessingResult);
Response response = subject.responseGiven(sensibleQuery, view, OK, 0L);
// then:
var opResponse = response.getContractCallLocal();
assertTrue(opResponse.hasHeader(), "Missing response header!");
assertEquals(CONTRACT_EXECUTION_EXCEPTION, opResponse.getHeader().getNodeTransactionPrecheckCode());
assertEquals(target, opResponse.getFunctionResult().getContractID());
}
use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class CallLocalExecutorTest method processingReturnsModificationHaltReason.
@Test
void processingReturnsModificationHaltReason() {
// setup:
final var transactionProcessingResult = TransactionProcessingResult.failed(0, 0, 1, Optional.empty(), Optional.of(ExceptionalHaltReason.ILLEGAL_STATE_CHANGE), Collections.emptyMap());
final var expected = response(LOCAL_CALL_MODIFICATION_EXCEPTION, transactionProcessingResult);
given(accountStore.loadAccount(any())).willReturn(new Account(callerID));
given(accountStore.loadContract(any())).willReturn(new Account(contractID));
given(evmTxProcessor.execute(any(), any(), anyLong(), anyLong(), any(), any())).willReturn(transactionProcessingResult);
// when:
final var result = CallLocalExecutor.execute(accountStore, evmTxProcessor, query, aliasManager);
// then:
assertEquals(expected, result);
}
use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class CallLocalExecutorTest method processingReturnsInvalidSolidityAddressHaltReason.
@Test
void processingReturnsInvalidSolidityAddressHaltReason() {
// setup:
final var transactionProcessingResult = TransactionProcessingResult.failed(0, 0, 1, Optional.empty(), Optional.of(HederaExceptionalHaltReason.INVALID_SOLIDITY_ADDRESS), Collections.emptyMap());
final var expected = response(INVALID_SOLIDITY_ADDRESS, transactionProcessingResult);
given(accountStore.loadAccount(any())).willReturn(new Account(callerID));
given(accountStore.loadContract(any())).willReturn(new Account(contractID));
given(evmTxProcessor.execute(any(), any(), anyLong(), anyLong(), any(), any())).willReturn(transactionProcessingResult);
// when:
final var result = CallLocalExecutor.execute(accountStore, evmTxProcessor, query, aliasManager);
// then:
assertEquals(expected, result);
}
use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class CallLocalExecutorTest method processingSuccessful.
@Test
void processingSuccessful() {
// setup:
final var transactionProcessingResult = TransactionProcessingResult.successful(new ArrayList<>(), 0, 0, 1, Bytes.EMPTY, callerID.asEvmAddress(), Collections.emptyMap());
final var expected = response(OK, transactionProcessingResult);
given(accountStore.loadAccount(any())).willReturn(new Account(callerID));
given(accountStore.loadContract(any())).willReturn(new Account(contractID));
given(evmTxProcessor.execute(any(), any(), anyLong(), anyLong(), any(), any())).willReturn(transactionProcessingResult);
// when:
final var result = CallLocalExecutor.execute(accountStore, evmTxProcessor, query, aliasManager);
// then:
assertEquals(expected, result);
}
use of com.hedera.services.store.models.Account 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());
}
Aggregations