Search in sources :

Example 26 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-services by hashgraph.

the class GetAccountBalanceAnswerTest method syntaxCheckValidatesCidIfPresent.

@Test
void syntaxCheckValidatesCidIfPresent() {
    // setup:
    ContractID cid = asContract(contractIdLit);
    // given:
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setContractID(cid).build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    // and:
    given(optionValidator.queryableContractStatus(cid, accounts)).willReturn(CONTRACT_DELETED);
    // when:
    ResponseCodeEnum status = subject.checkValidity(query, view);
    // expect:
    assertEquals(CONTRACT_DELETED, status);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test)

Example 27 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-mirror-node by hashgraph.

the class ContractResultServiceImpl method getCreatedContractIds.

@SuppressWarnings("deprecation")
private List<Long> getCreatedContractIds(ContractFunctionResult functionResult, RecordItem recordItem, ContractResult contractResult) {
    List<Long> createdContractIds = new ArrayList<>();
    boolean persist = shouldPersistCreatedContractIDs(recordItem);
    for (ContractID createdContractId : functionResult.getCreatedContractIDsList()) {
        EntityId contractId = entityIdService.lookup(createdContractId);
        if (!EntityId.isEmpty(contractId)) {
            createdContractIds.add(contractId.getId());
            // The parent contract ID can also sometimes appear in the created contract IDs list, so exclude it
            if (persist && !contractId.equals(contractResult.getContractId())) {
                processCreatedContractEntity(recordItem, contractId);
            }
        }
    }
    return createdContractIds;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 28 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method assertContractCallResult.

private void assertContractCallResult(ContractCallTransactionBody transactionBody, TransactionRecord record) {
    long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
    ContractFunctionResult result = record.getContractCallResult();
    // get the corresponding entity id from the local cache, fall back to parseContractId if not found.
    ContractID protoContractId = record.getContractCallResult().getContractID();
    EntityId contractId = contractIds.getOrDefault(protoContractId, parseContractId(protoContractId));
    ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getAmount(), ContractResult::getAmount).returns(contractId, ContractResult::getContractId).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(toBytes(transactionBody.getFunctionParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
    assertContractResult(consensusTimestamp, result, result.getLogInfoList(), contractResult, result.getStateChangesList());
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) DomainUtils.toBytes(com.hedera.mirror.common.util.DomainUtils.toBytes) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ByteBuffer(java.nio.ByteBuffer) ContractID(com.hederahashgraph.api.proto.java.ContractID) Map(java.util.Map) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Version(org.springframework.data.util.Version) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) Collectors(java.util.stream.Collectors) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) BytesValue(com.google.protobuf.BytesValue) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) STAKEDID_NOT_SET(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody.StakedIdCase.STAKEDID_NOT_SET) ObjectAssert(org.assertj.core.api.ObjectAssert) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) Value(lombok.Value) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Int32Value(com.google.protobuf.Int32Value) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Consumer(java.util.function.Consumer) TokenType(com.hederahashgraph.api.proto.java.TokenType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Assertions(org.junit.jupiter.api.Assertions) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) Collections(java.util.Collections) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 29 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractUpdateAllWithMemoToExisting.

@Test
void contractUpdateAllWithMemoToExisting() {
    // first create the contract
    EntityId contractId = EntityId.of(CONTRACT_ID);
    Contract contract = domainBuilder.contract().customize(c -> c.obtainerId(null).id(contractId.getId()).num(contractId.getEntityNum()).stakedNodeId(1L)).persist();
    // now update
    Transaction transaction = contractUpdateAllTransaction(false);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.UPDATE);
    ContractUpdateTransactionBody contractUpdateTransactionBody = transactionBody.getContractUpdateInstance();
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID)), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractEntity(contractUpdateTransactionBody, record.getConsensusTimestamp()).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
    Contract::getFileId));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) DomainUtils.toBytes(com.hedera.mirror.common.util.DomainUtils.toBytes) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ByteBuffer(java.nio.ByteBuffer) ContractID(com.hederahashgraph.api.proto.java.ContractID) Map(java.util.Map) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Version(org.springframework.data.util.Version) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) Collectors(java.util.stream.Collectors) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) BytesValue(com.google.protobuf.BytesValue) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) STAKEDID_NOT_SET(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody.StakedIdCase.STAKEDID_NOT_SET) ObjectAssert(org.assertj.core.api.ObjectAssert) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) Value(lombok.Value) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Int32Value(com.google.protobuf.Int32Value) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Consumer(java.util.function.Consumer) TokenType(com.hederahashgraph.api.proto.java.TokenType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Assertions(org.junit.jupiter.api.Assertions) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) Collections(java.util.Collections) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Contract(com.hedera.mirror.common.domain.contract.Contract) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-mirror-node by hashgraph.

the class ContractCallTransactionHandlerTest method testGetEntityIdReceipt.

@Test
void testGetEntityIdReceipt() {
    var recordItem = recordItemBuilder.contractCall().build();
    ContractID contractIdBody = recordItem.getTransactionBody().getContractCall().getContractID();
    ContractID contractIdReceipt = recordItem.getRecord().getReceipt().getContractID();
    EntityId expectedEntityId = EntityId.of(contractIdReceipt);
    when(entityIdService.lookup(contractIdReceipt, contractIdBody)).thenReturn(expectedEntityId);
    EntityId entityId = transactionHandler.getEntity(recordItem);
    assertThat(entityId).isEqualTo(expectedEntityId);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test)

Aggregations

ContractID (com.hederahashgraph.api.proto.java.ContractID)33 Test (org.junit.jupiter.api.Test)18 EntityId (com.hedera.mirror.common.domain.entity.EntityId)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 AccountID (com.hederahashgraph.api.proto.java.AccountID)9 Contract (com.hedera.mirror.common.domain.contract.Contract)7 Assertions (org.junit.jupiter.api.Assertions)7 ByteString (com.google.protobuf.ByteString)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)6 DomainUtils (com.hedera.mirror.common.util.DomainUtils)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Range (com.google.common.collect.Range)4 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 RecordItemBuilder (com.hedera.mirror.importer.parser.domain.RecordItemBuilder)4 Utility (com.hedera.mirror.importer.util.Utility)4 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 List (java.util.List)4