Search in sources :

Example 16 with ContractID

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

the class EntityIdServiceImplTest method cache.

@Test
void cache() {
    Contract contract = domainBuilder.contract().persist();
    ContractID contractId = getProtoContractId(contract);
    EntityId expected = contract.toEntityId();
    // db query and cache put
    assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
    // mark it as deleted
    contract.setDeleted(true);
    contractRepository.save(contract);
    // cache hit
    assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
    contractRepository.deleteById(contract.getId());
    assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
    // cache miss
    reset();
    assertThrows(AliasNotFoundException.class, () -> entityIdService.lookup(getProtoContractId(contract)));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractID(com.hederahashgraph.api.proto.java.ContractID) Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with ContractID

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

the class ContractResultMigrationTest method contractFunctionResult.

private ContractFunctionResult.Builder contractFunctionResult() {
    long contractNum = ++id;
    ContractID contractID = ContractID.newBuilder().setContractNum(contractNum).build();
    return ContractFunctionResult.newBuilder().setBloom(ByteString.copyFrom(new byte[] { 0, 1 })).setContractCallResult(ByteString.copyFrom(new byte[] { 2, 3 })).setContractID(contractID).addCreatedContractIDs(ContractID.newBuilder().setContractNum(contractNum + 1).build()).setErrorMessage("").setGasUsed(100L).addLogInfo(ContractLoginfo.newBuilder().setBloom(ByteString.copyFrom(new byte[] { 4, 5 })).setContractID(contractID).setData(ByteString.copyFrom(new byte[] { 6, 7 })).addTopic(ByteString.copyFrom(new byte[] { 0 })).addTopic(ByteString.copyFrom(new byte[] { 1 })).addTopic(ByteString.copyFrom(new byte[] { 2 })).addTopic(ByteString.copyFrom(new byte[] { 3 })).build());
}
Also used : ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 18 with ContractID

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

the class EntityIdServiceImplTest method lookupContractNum.

@Test
void lookupContractNum() {
    ContractID contractId = ContractID.newBuilder().setContractNum(100).build();
    assertThat(entityIdService.lookup(contractId)).isEqualTo(EntityId.of(100, CONTRACT));
}
Also used : ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with ContractID

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

the class EntityIdServiceImplTest method lookupContractThrows.

@Test
void lookupContractThrows() {
    ContractID contractId = ContractID.newBuilder().setRealmNum(1).build();
    assertThrows(InvalidDatasetException.class, () -> entityIdService.lookup(contractId));
}
Also used : ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 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, EntityId parentEntityContractId) {
    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(parentEntityContractId)) {
                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)

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