Search in sources :

Example 46 with Entity

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

the class HistoricalAccountInfoMigrationTest method create.

@Test
void create() {
    AccountInfo.Builder accountInfo = accountInfo();
    String publicKey = DomainUtils.getPublicKey(accountInfo.getKey().toByteArray());
    assertThat(historicalAccountInfoMigration.process(accountInfo.build())).isTrue();
    assertThat(entityRepository.findById(ACCOUNT_ID1)).get().returns(accountInfo.getAutoRenewPeriod().getSeconds(), from(Entity::getAutoRenewPeriod)).returns(accountInfo.getDeleted(), from(Entity::getDeleted)).returns(publicKey, from(Entity::getPublicKey)).returns(DomainUtils.timeStampInNanos(accountInfo.getExpirationTime()), from(Entity::getExpirationTimestamp)).returns(accountInfo.getKey().toByteArray(), from(Entity::getKey)).returns(accountInfo.getMemo(), from(Entity::getMemo)).returns(EntityId.of(accountInfo.getProxyAccountID()), from(Entity::getProxyAccountId));
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) ByteString(com.google.protobuf.ByteString) AccountInfo(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse.AccountInfo) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 47 with Entity

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

the class HistoricalAccountInfoMigrationTest method existingEntitiesWrongType.

@Test
void existingEntitiesWrongType() throws Exception {
    Entity entity1 = createEntity(ACCOUNT_ID1, EntityType.ACCOUNT, true);
    Entity entity2 = createEntity(ACCOUNT_ID2, EntityType.ACCOUNT, true);
    Entity entity3 = createEntity(ACCOUNT_ID3, EntityType.ACCOUNT, true);
    Entity entity4 = createEntity(CONTRACT_ID1, EntityType.ACCOUNT, true);
    historicalAccountInfoMigration.doMigrate();
    assertThat(contractRepository.findAll()).hasSize(CONTRACT_COUNT).first().returns(EntityType.CONTRACT, Contract::getType).returns(entity4.getNum(), Contract::getNum);
    assertThat(entityRepository.findAll()).containsExactlyInAnyOrder(entity1, entity2, entity3);
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 48 with Entity

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

the class HistoricalAccountInfoMigrationTest method emptyValues.

@Test
void emptyValues() {
    AccountID accountId = AccountID.newBuilder().setAccountNum(ACCOUNT_ID1).build();
    AccountInfo.Builder accountInfo = accountInfo().clear().setAccountID(accountId);
    assertThat(historicalAccountInfoMigration.process(accountInfo.build())).isTrue();
    assertThat(entityRepository.findById(ACCOUNT_ID1)).get().returns(null, from(Entity::getAutoRenewPeriod)).returns(false, from(Entity::getDeleted)).returns(null, from(Entity::getPublicKey)).returns(null, from(Entity::getExpirationTimestamp)).returns(null, from(Entity::getKey)).returns("", from(Entity::getMemo)).returns(null, from(Entity::getProxyAccountId));
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) AccountID(com.hederahashgraph.api.proto.java.AccountID) AccountInfo(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse.AccountInfo) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 49 with Entity

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

the class RemoveInvalidEntityMigrationTest method verifyEntityTypeMigrationInvalidEntities.

@Test
void verifyEntityTypeMigrationInvalidEntities() throws Exception {
    EntityId typeMismatchedAccountEntityId = entityId(1, EntityType.TOPIC);
    EntityId typeMismatchedContractEntityId = entityId(2, EntityType.TOKEN);
    EntityId typeMismatchedFileEntityId = entityId(3, EntityType.CONTRACT);
    EntityId typeMismatchedTopicEntityId = entityId(4, EntityType.ACCOUNT);
    EntityId typeMismatchedTokenEntityId = entityId(5, EntityType.FILE);
    insertEntity(typeMismatchedAccountEntityId);
    insertEntity(typeMismatchedContractEntityId);
    insertEntity(typeMismatchedFileEntityId);
    insertEntity(typeMismatchedTopicEntityId);
    insertEntity(typeMismatchedTokenEntityId);
    List<Transaction> transactionList = new ArrayList<>();
    transactionList.add(transaction(1, 1, EntityType.ACCOUNT, ResponseCodeEnum.SUCCESS, TransactionType.CRYPTOCREATEACCOUNT));
    transactionList.add(transaction(20, 2, EntityType.CONTRACT, ResponseCodeEnum.SUCCESS, TransactionType.CONTRACTCREATEINSTANCE));
    transactionList.add(transaction(30, 3, EntityType.FILE, ResponseCodeEnum.SUCCESS, TransactionType.FILECREATE));
    transactionList.add(transaction(40, 4, EntityType.TOPIC, ResponseCodeEnum.SUCCESS, TransactionType.CONSENSUSCREATETOPIC));
    transactionList.add(transaction(50, 5, EntityType.TOKEN, ResponseCodeEnum.SUCCESS, TransactionType.TOKENCREATION));
    transactionList.add(transaction(70, 50, EntityType.TOPIC, ResponseCodeEnum.INVALID_TOPIC_ID, TransactionType.CONSENSUSSUBMITMESSAGE));
    transactionList.add(transaction(80, 100, EntityType.TOPIC, ResponseCodeEnum.TOPIC_EXPIRED, TransactionType.CONSENSUSSUBMITMESSAGE));
    transactionList.forEach(this::insertTransaction);
    // migration
    migrate();
    assertEquals(5, getEntityCount());
    assertEquals(7, transactionRepository.count());
    assertAll(() -> assertThat(findEntityById(typeMismatchedAccountEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.ACCOUNT), () -> assertThat(findEntityById(typeMismatchedContractEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.CONTRACT), () -> assertThat(findEntityById(typeMismatchedFileEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.FILE), () -> assertThat(findEntityById(typeMismatchedTopicEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.TOPIC), () -> assertThat(findEntityById(typeMismatchedTokenEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.TOKEN));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 50 with Entity

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

the class CleanupEntityMigrationTest method entity.

private Entity entity(long id, EntityType entityType) {
    Entity entity = new Entity();
    entity.setId(id);
    entity.setNum(id);
    entity.setRealm(0L);
    entity.setShard(0L);
    entity.setType(entityType);
    entity.setAutoRenewAccountId(EntityIdEndec.encode(1, 2, 3));
    entity.setProxyAccountId(EntityId.of("4.5.6", EntityType.ACCOUNT));
    return entity;
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity)

Aggregations

Entity (com.hedera.mirror.common.domain.entity.Entity)78 Test (org.junit.jupiter.api.Test)52 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)40 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)23 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)22 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)21 Transaction (com.hederahashgraph.api.proto.java.Transaction)19 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)16 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)15 EntityId (com.hedera.mirror.common.domain.entity.EntityId)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)11 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)10 ByteString (com.google.protobuf.ByteString)9 Contract (com.hedera.mirror.common.domain.contract.Contract)9 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)9 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)9 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)9 Resource (javax.annotation.Resource)9 Assertions (org.junit.jupiter.api.Assertions)9