Search in sources :

Example 51 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImpl method notify.

@Override
public void notify(Aliasable aliasable) {
    if (aliasable == null || (aliasable.getDeleted() != null && aliasable.getDeleted())) {
        return;
    }
    ByteString alias = DomainUtils.fromBytes(aliasable.getAlias());
    if (alias == null) {
        return;
    }
    EntityId entityId = aliasable.toEntityId();
    EntityType type = aliasable.getType();
    GeneratedMessageV3.Builder<?> builder;
    switch(type) {
        case ACCOUNT:
            builder = AccountID.newBuilder().setShardNum(entityId.getShardNum()).setRealmNum(entityId.getRealmNum()).setAlias(alias);
            break;
        case CONTRACT:
            builder = ContractID.newBuilder().setShardNum(entityId.getShardNum()).setRealmNum(entityId.getRealmNum()).setEvmAddress(alias);
            break;
        default:
            throw new InvalidEntityException(String.format("%s entity can't have alias", type));
    }
    cache.put(builder.build().hashCode(), entityId);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ByteString(com.google.protobuf.ByteString) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException)

Example 52 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class TestRecordFiles method getV2V5Files.

public List<RecordFile> getV2V5Files() {
    EntityId nodeAccountId = EntityId.of(0, 0, 3, EntityType.ACCOUNT);
    RecordFile recordFileV2 = RecordFile.builder().consensusStart(1611188151568507001L).consensusEnd(1611188151568507001L).count(1L).digestAlgorithm(DigestAlgorithm.SHA384).fileHash("e7d9e71efd239bde3adcad8eb0571c38f91f77ae76a4af69bb44f19b2785ad3594ac1d265351a592ab14301da9bb1950").hash("e7d9e71efd239bde3adcad8eb0571c38f91f77ae76a4af69bb44f19b2785ad3594ac1d265351a592ab14301da9bb1950").name("2021-01-21T00_15_51.568507001Z.rcd").nodeAccountId(nodeAccountId).previousHash("d27ba83c736bfa2ffc9a6f062b27ea4856800bbbe820b77b32e08faf3d7475d81ef5a16f90ce065d35eefa999677edaa").version(2).build();
    RecordFile recordFileV5 = RecordFile.builder().consensusStart(1611188383558496000L).consensusEnd(1611188383558496000L).count(1L).digestAlgorithm(DigestAlgorithm.SHA384).fileHash("42717bae0e538bac34563784b08b5a5b50a9964c9435452c93134bf13355c9778a1c64cfdc30f33fe52dd7f76dbdda70").hapiVersionMajor(0).hapiVersionMinor(11).hapiVersionPatch(0).hash("e6c1d7bfe956b6b2c8061bee5c43e512111cbccb21099bb0c49e2a7c74cf617cf5b6bf65070f29eb43a80d9cef2d8242").metadataHash("1d83206a166a06c8579f9de637cf50a565341928b55bfbdc774ce85ac2169b46c23db42729723e7c39e5a042bd9e3b98").name("2021-01-21T00_19_43.558496000Z.rcd").nodeAccountId(nodeAccountId).previousHash(recordFileV2.getHash()).version(5).build();
    return List.of(recordFileV2, recordFileV5);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile)

Example 53 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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 54 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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)

Example 55 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)134 Test (org.junit.jupiter.api.Test)64 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)33 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 EntityType (com.hedera.mirror.common.domain.entity.EntityType)21 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)21 Token (com.hedera.mirror.common.domain.token.Token)20 Entity (com.hedera.mirror.common.domain.entity.Entity)17 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)17 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)16 Assertions (org.junit.jupiter.api.Assertions)16 Contract (com.hedera.mirror.common.domain.contract.Contract)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)15 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 ByteString (com.google.protobuf.ByteString)14 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)14 ContractID (com.hederahashgraph.api.proto.java.ContractID)14 Consumer (java.util.function.Consumer)13