Search in sources :

Example 41 with Entity

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

the class RemoveInvalidEntityMigrationTest method insertEntity.

/**
 * Insert entity object using only columns supported before V_1_36.2
 *
 * @param entityId entityId domain
 */
private void insertEntity(EntityId entityId) {
    Entity entity = new Entity();
    entity.setId(entityId.getId());
    entity.setNum(entityId.getEntityNum());
    entity.setRealm(entityId.getRealmNum());
    entity.setShard(entityId.getShardNum());
    entity.setType(entityId.getType());
    entity.setMemo("abc" + (char) 0);
    entity.setAutoRenewAccountId(EntityId.of("1.2.3", EntityType.ACCOUNT).getId());
    entity.setProxyAccountId(EntityId.of("4.5.6", EntityType.ACCOUNT));
    jdbcOperations.update("insert into t_entities (auto_renew_account_id, auto_renew_period, deleted, entity_num, " + "entity_realm, entity_shard, ed25519_public_key_hex, exp_time_ns, fk_entity_type_id, " + "id, key, memo, proxy_account_id, submit_key) values" + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", entity.getAutoRenewAccountId(), entity.getAutoRenewPeriod(), entity.getDeleted(), entity.getNum(), entity.getRealm(), entity.getShard(), entity.getPublicKey(), entity.getExpirationTimestamp(), entity.getType().getId(), entity.getId(), entity.getKey(), entity.getMemo(), entity.getProxyAccountId().getId(), entity.getSubmitKey());
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity)

Example 42 with Entity

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

the class RemoveInvalidEntityMigrationTest method verifyEntityTypeMigrationInvalidEntitiesMultiBatch.

@Test
void verifyEntityTypeMigrationInvalidEntitiesMultiBatch() throws Exception {
    insertEntity(entityId(1, EntityType.ACCOUNT));
    insertEntity(entityId(2, EntityType.CONTRACT));
    insertEntity(entityId(3, EntityType.FILE));
    insertEntity(entityId(4, EntityType.TOPIC));
    insertEntity(entityId(5, EntityType.TOKEN));
    EntityId typeMismatchedAccountEntityId = entityId(6, EntityType.TOPIC);
    EntityId typeMismatchedContractEntityId = entityId(7, EntityType.TOKEN);
    EntityId typeMismatchedFileEntityId = entityId(8, EntityType.CONTRACT);
    EntityId typeMismatchedTopicEntityId = entityId(9, EntityType.ACCOUNT);
    EntityId typeMismatchedTokenEntityId = entityId(10, 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(60, 6, EntityType.ACCOUNT, ResponseCodeEnum.SUCCESS, TransactionType.CRYPTOCREATEACCOUNT));
    transactionList.add(transaction(70, 7, EntityType.CONTRACT, ResponseCodeEnum.SUCCESS, TransactionType.CONTRACTCREATEINSTANCE));
    transactionList.add(transaction(80, 8, EntityType.FILE, ResponseCodeEnum.SUCCESS, TransactionType.FILECREATE));
    transactionList.add(transaction(90, 9, EntityType.TOPIC, ResponseCodeEnum.SUCCESS, TransactionType.CONSENSUSCREATETOPIC));
    transactionList.add(transaction(100, 10, EntityType.TOKEN, ResponseCodeEnum.SUCCESS, TransactionType.TOKENCREATION));
    transactionList.add(transaction(500, 50, EntityType.TOPIC, ResponseCodeEnum.INVALID_TOPIC_ID, TransactionType.CONSENSUSSUBMITMESSAGE));
    transactionList.add(transaction(1000, 100, EntityType.TOPIC, ResponseCodeEnum.TOPIC_EXPIRED, TransactionType.CONSENSUSSUBMITMESSAGE));
    transactionList.forEach(this::insertTransaction);
    // migration
    migrate();
    assertEquals(10, getEntityCount());
    assertEquals(12, 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 43 with Entity

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

the class RemoveInvalidEntityMigrationTest method findEntityById.

private Entity findEntityById(long id) {
    return jdbcOperations.queryForObject("select * from t_entities where id = ?", new Object[] { id }, (rs, rowNum) -> {
        Entity entity = new Entity();
        entity.setAutoRenewAccountId(rs.getLong("auto_renew_account_id"));
        entity.setAutoRenewPeriod(rs.getLong("auto_renew_period"));
        entity.setDeleted(rs.getBoolean("deleted"));
        entity.setExpirationTimestamp(rs.getLong("exp_time_ns"));
        entity.setId(rs.getLong("id"));
        entity.setKey(rs.getBytes("key"));
        entity.setMemo(rs.getString("memo"));
        entity.setNum(rs.getLong("entity_num"));
        entity.setRealm(rs.getLong("entity_realm"));
        entity.setShard(rs.getLong("entity_shard"));
        entity.setProxyAccountId(EntityIdEndec.decode(rs.getLong("proxy_account_id"), EntityType.ACCOUNT));
        entity.setSubmitKey(rs.getBytes("submit_key"));
        entity.setType(EntityType.fromId(rs.getInt("fk_entity_type_id")));
        return entity;
    });
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity)

Example 44 with Entity

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

the class HistoricalAccountInfoMigrationTest method update.

@Test
void update() {
    createEntity(ACCOUNT_ID1, EntityType.ACCOUNT, false);
    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 45 with Entity

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

the class HistoricalAccountInfoMigrationTest method skipExisting.

@Test
void skipExisting() {
    AccountInfo.Builder accountInfo = accountInfo();
    Entity entity = createEntity(ACCOUNT_ID1, EntityType.ACCOUNT, true);
    assertThat(historicalAccountInfoMigration.process(accountInfo.build())).isFalse();
    assertThat(entityRepository.findAll()).hasSize(1).containsExactly(entity);
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) AccountInfo(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse.AccountInfo) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

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