Search in sources :

Example 11 with ContractID

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

the class ContractDeleteTransactionHandler method getEntity.

/**
 * First attempts to extract the contract ID from the receipt, which was populated in HAPI 0.23 for contract
 * deletes. Otherwise, falls back to checking the transaction body which may contain an EVM address. In case of
 * partial mirror nodes, it's possible the database does not have the mapping for that EVM address in the body,
 * hence the need for prioritizing the receipt.
 *
 * @param recordItem to check
 * @return The contract ID associated with this contract delete
 */
@Override
public EntityId getEntity(RecordItem recordItem) {
    ContractID contractIdBody = recordItem.getTransactionBody().getContractDeleteInstance().getContractID();
    ContractID contractIdReceipt = recordItem.getRecord().getReceipt().getContractID();
    return entityIdService.lookup(contractIdReceipt, contractIdBody);
}
Also used : ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 12 with ContractID

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

the class ContractUpdateTransactionHandler method getEntity.

/**
 * First attempts to extract the contract ID from the receipt, which was populated in HAPI 0.23 for contract update.
 * Otherwise, falls back to checking the transaction body which may contain an EVM address. In case of partial
 * mirror nodes, it's possible the database does not have the mapping for that EVM address in the body, hence the
 * need for prioritizing the receipt.
 *
 * @param recordItem to check
 * @return The contract ID associated with this contract transaction
 */
@Override
public EntityId getEntity(RecordItem recordItem) {
    ContractID contractIdBody = recordItem.getTransactionBody().getContractUpdateInstance().getContractID();
    ContractID contractIdReceipt = recordItem.getRecord().getReceipt().getContractID();
    return entityIdService.lookup(contractIdReceipt, contractIdBody);
}
Also used : ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 13 with ContractID

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

the class EntityIdServiceImplTest method lookupContractsReturnsFirst.

@Test
void lookupContractsReturnsFirst() {
    ContractID contractId1 = ContractID.newBuilder().setContractNum(100).build();
    ContractID contractId2 = ContractID.newBuilder().setContractNum(101).build();
    EntityId entityId = entityIdService.lookup(contractId1, contractId2);
    assertThat(entityId).isEqualTo(EntityId.of(contractId1));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) 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 14 with ContractID

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

the class EntityIdServiceImplTest method lookupParsableEvmAddressShardRealmMismatch.

@Test
void lookupParsableEvmAddressShardRealmMismatch() {
    ContractID contractId = ContractID.newBuilder().setShardNum(1).setRealmNum(2).setEvmAddress(DomainUtils.fromBytes(PARSABLE_EVM_ADDRESS)).build();
    assertThrows(AliasNotFoundException.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 15 with ContractID

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

the class EntityIdServiceImplTest method lookupContracts.

@Test
void lookupContracts() {
    ContractID nullContractId = null;
    ContractID contractId = ContractID.newBuilder().setContractNum(100).build();
    ContractID contractIdInvalid = ContractID.newBuilder().setRealmNum(1).build();
    Contract contractDeleted = domainBuilder.contract().customize(e -> e.deleted(true)).persist();
    EntityId entityId = entityIdService.lookup(nullContractId, ContractID.getDefaultInstance(), getProtoContractId(contractDeleted), contractIdInvalid, contractId);
    assertThat(entityId).isEqualTo(EntityId.of(contractId));
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Contract(com.hedera.mirror.common.domain.contract.Contract) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Entity(com.hedera.mirror.common.domain.entity.Entity) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ContractID(com.hederahashgraph.api.proto.java.ContractID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Assertions(org.junit.jupiter.api.Assertions) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) AccountID(com.hederahashgraph.api.proto.java.AccountID) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) 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)

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