Search in sources :

Example 1 with Account

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());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) ContractCallLocalResponse(com.hederahashgraph.api.proto.java.ContractCallLocalResponse) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) Account(com.hedera.services.store.models.Account) Query(com.hederahashgraph.api.proto.java.Query) ContractCallLocalQuery(com.hederahashgraph.api.proto.java.ContractCallLocalQuery) Test(org.junit.jupiter.api.Test)

Example 2 with Account

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);
}
Also used : Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Example 3 with Account

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);
}
Also used : Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Example 4 with Account

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);
}
Also used : Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Example 5 with Account

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

Aggregations

Account (com.hedera.services.store.models.Account)15 Test (org.junit.jupiter.api.Test)14 TokenRelationship (com.hedera.services.store.models.TokenRelationship)3 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)2 Id (com.hedera.services.store.models.Id)2 Token (com.hedera.services.store.models.Token)2 IdUtils.asAccount (com.hedera.test.utils.IdUtils.asAccount)2 NftId (com.hedera.services.store.models.NftId)1 OwnershipTracker (com.hedera.services.store.models.OwnershipTracker)1 UniqueToken (com.hedera.services.store.models.UniqueToken)1 EntityNumPair.fromNftId (com.hedera.services.utils.EntityNumPair.fromNftId)1 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)1 ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)1 Query (com.hederahashgraph.api.proto.java.Query)1 Response (com.hederahashgraph.api.proto.java.Response)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Address (org.hyperledger.besu.datatypes.Address)1