Search in sources :

Example 61 with EntityId

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

the class MissingAddressBooksMigrationTest method createAndStoreFileData.

private FileData createAndStoreFileData(byte[] contents, long consensusTimeStamp, boolean is102, TransactionType transactionType) {
    EntityId entityId = is102 ? AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID : AddressBookServiceImpl.ADDRESS_BOOK_101_ENTITY_ID;
    FileData fileData = new FileData(consensusTimeStamp, contents, entityId, transactionType.getProtoId());
    return fileDataRepository.save(fileData);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) FileData(com.hedera.mirror.common.domain.file.FileData)

Example 62 with EntityId

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

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

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

the class SupportDeletedTokenDissociateMigrationTest method verify.

@Test
void verify() {
    // given
    // entities
    // - 2 ft classes
    // - deleted, account1's token dissociate includes token transfer
    // - still alive
    // - 3 nft classes
    // - deleted, account1's token dissociate doesn't include token transfer, account2's includes
    // - deleted, account1's token dissociate doesn't include token transfer, account2's dissociate happened
    // before token deletion
    // - still alive
    EntityId account1 = EntityId.of("0.0.210", ACCOUNT);
    EntityId account2 = EntityId.of("0.0.211", ACCOUNT);
    EntityId ftId1 = EntityId.of("0.0.500", TOKEN);
    EntityId ftId2 = EntityId.of("0.0.501", TOKEN);
    EntityId nftId1 = EntityId.of("0.0.502", TOKEN);
    EntityId nftId2 = EntityId.of("0.0.503", TOKEN);
    EntityId nftId3 = EntityId.of("0.0.504", TOKEN);
    Token ftClass1 = token(10L, ftId1, FUNGIBLE_COMMON);
    Token ftClass2 = token(15L, ftId2, FUNGIBLE_COMMON);
    Token nftClass1 = token(20L, nftId1, NON_FUNGIBLE_UNIQUE);
    Token nftClass2 = token(25L, nftId2, NON_FUNGIBLE_UNIQUE);
    Token nftClass3 = token(30L, nftId3, NON_FUNGIBLE_UNIQUE);
    MigrationEntity ft1Entity = entity(ftClass1, true, 50L);
    MigrationEntity ft2Entity = entity(ftClass2);
    MigrationEntity nft1Entity = entity(nftClass1, true, 55L);
    MigrationEntity nft2Entity = entity(nftClass2, true, 60L);
    MigrationEntity nft3Entity = entity(nftClass3);
    persistEntities(List.of(ft1Entity, ft2Entity, nft1Entity, nft2Entity, nft3Entity));
    long account1Ft1DissociateTimestamp = 70;
    long account1Nft1DissociateTimestamp = 75;
    long account2Nft1DissociateTimestamp = 80;
    long account1Nft2DissociateTimestamp = 85;
    // happened before token deletion
    long account2Nft2DissociateTimestamp = 55;
    List<TokenAccount> tokenAccounts = List.of(tokenAccount(account1, true, 12L, 12L, ftId1), tokenAccount(account1, false, 12L, account1Ft1DissociateTimestamp, ftId1), tokenAccount(account2, true, 15L, 15L, ftId1), tokenAccount(account1, true, 20L, 20L, ftId2), tokenAccount(account1, true, 23L, 23L, nftId1), tokenAccount(account1, false, 23L, account1Nft1DissociateTimestamp, nftId1), tokenAccount(account2, true, 25L, 25L, nftId1), tokenAccount(account2, false, 25L, account2Nft1DissociateTimestamp, nftId1), tokenAccount(account1, true, 27L, 27L, nftId2), tokenAccount(account1, false, 27L, account1Nft2DissociateTimestamp, nftId2), tokenAccount(account2, true, 29L, 29L, nftId2), tokenAccount(account2, false, 29L, account2Nft2DissociateTimestamp, nftId2));
    tokenAccountRepository.saveAll(tokenAccounts);
    // token dissociate transactions
    List<Transaction> transactions = List.of(tokenDissociateTransaction(account1Ft1DissociateTimestamp, account1), tokenDissociateTransaction(account1Nft1DissociateTimestamp, account1), tokenDissociateTransaction(account2Nft1DissociateTimestamp, account2), tokenDissociateTransaction(account1Nft2DissociateTimestamp, account1), tokenDissociateTransaction(account2Nft2DissociateTimestamp, account2));
    persistTransactions(transactions);
    // transfers
    persistTokenTransfers(List.of(new TokenTransfer(account1Ft1DissociateTimestamp, -10, ftId1, account1), new TokenTransfer(account2Nft1DissociateTimestamp, -1, nftId1, account2)));
    // nfts
    // - 2 for <account1, nftId1>, 1 already deleted before dissociate, the other without dissociate transfer
    // - 2 for <account1, nftId2>, 1 already deleted before dissociate, the other without dissociate transfer
    // - 2 for <account2, nftId1>, 1 already deleted before dissociate, the other with dissociate transfer
    // - 1 for <account2, nftId2>, already deleted, account2 dissociated nftId2 before nft class deletion
    // - 1 for <account1, nftId3>
    // - 1 for <account2, nftId3>
    persistNfts(List.of(nft(account1, 25L, true, 27L, 1L, nftId1), nft(account1, 25L, false, 25L, 2L, nftId1), nft(account1, 30L, true, 35L, 1L, nftId2), nft(account1, 30L, false, 30L, 2L, nftId2), nft(account1, 40L, false, 40L, 1L, nftId3), nft(account2, 28L, true, 32L, 3L, nftId1), nft(account2, 28L, false, 28L, 4L, nftId1), nft(account2, 33L, true, 37L, 3L, nftId2), nft(account2, 45L, false, 45L, 2L, nftId3)));
    // nft transfers from nft class treasury update
    persistNftTransfers(List.of(nftTransfer(40L, NEW_TREASURY, TREASURY, NftTransferId.WILDCARD_SERIAL_NUMBER, nftId3)));
    // expected token changes
    ftClass1.setTotalSupply(ftClass1.getTotalSupply() - 10);
    ftClass1.setModifiedTimestamp(account1Ft1DissociateTimestamp);
    // 1 nft wiped from explicit token transfer of the token dissociate, 1 wiped from a previous token dissociate
    // without explicit token transfer
    nftClass1.setTotalSupply(nftClass1.getTotalSupply() - 2);
    nftClass1.setModifiedTimestamp(account2Nft1DissociateTimestamp);
    nftClass2.setTotalSupply(nftClass2.getTotalSupply() - 1);
    nftClass2.setModifiedTimestamp(account1Nft2DissociateTimestamp);
    // when
    migrate();
    // then
    assertThat(findAllNfts()).containsExactlyInAnyOrder(nft(account1, 25L, true, 27L, 1L, nftId1), nft(account1, 25L, true, account1Nft1DissociateTimestamp, 2L, nftId1), nft(account1, 30L, true, 35L, 1L, nftId2), nft(account1, 30L, true, account1Nft2DissociateTimestamp, 2L, nftId2), nft(account1, 40L, false, 40L, 1L, nftId3), nft(account2, 28L, true, 32L, 3L, nftId1), nft(account2, 28L, true, account2Nft1DissociateTimestamp, 4L, nftId1), nft(account2, 33L, true, 37L, 3L, nftId2), nft(account2, 45L, false, 45L, 2L, nftId3));
    // expect new nft transfers from token dissociate of deleted nft class
    // expect nft transfers for nft treasury update removed
    assertThat(findAllNftTransfers()).usingElementComparatorIgnoringFields("payerAccountId").containsExactlyInAnyOrder(nftTransfer(account1Nft1DissociateTimestamp, null, account1, 2L, nftId1), nftTransfer(account1Nft2DissociateTimestamp, null, account1, 2L, nftId2), nftTransfer(account2Nft1DissociateTimestamp, null, account2, 4L, nftId1));
    assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(tokenAccounts);
    assertThat(findAllTokens()).usingElementComparatorIgnoringFields("pauseKey", "pauseStatus").containsExactlyInAnyOrder(ftClass1, ftClass2, nftClass1, nftClass2, nftClass3);
    // the token transfer for nft should have been removed
    assertThat(findAllTokenTransfers()).usingElementComparatorIgnoringFields("payerAccountId").containsExactlyInAnyOrder(new TokenTransfer(account1Ft1DissociateTimestamp, -10, ftId1, account1));
    assertThat(findAllTransactions()).containsExactlyInAnyOrderElementsOf(transactions);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) Token(com.hedera.mirror.common.domain.token.Token) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 65 with EntityId

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

the class ContractResultMigrationTest method migrate.

@SuppressWarnings("deprecation")
@Test
void migrate() throws Exception {
    ContractFunctionResult.Builder functionResult = contractFunctionResult();
    MigrationContractResult contractResult = contractResult(functionResult);
    insert(contractResult);
    contractResultMigration.doMigrate();
    ContractLoginfo loginfo = functionResult.getLogInfo(0);
    assertThat(getContractLogs()).hasSize(1).first().returns(loginfo.getBloom().toByteArray(), MigrationContractLog::getBloom).returns(contractResult.getConsensusTimestamp(), MigrationContractLog::getConsensusTimestamp).returns(loginfo.getContractID().getContractNum(), MigrationContractLog::getContractId).returns(0, MigrationContractLog::getIndex).returns(Hex.encodeHexString(loginfo.getTopic(0).toByteArray()), MigrationContractLog::getTopic0).returns(Hex.encodeHexString(loginfo.getTopic(1).toByteArray()), MigrationContractLog::getTopic1).returns(Hex.encodeHexString(loginfo.getTopic(2).toByteArray()), MigrationContractLog::getTopic2).returns(Hex.encodeHexString(loginfo.getTopic(3).toByteArray()), MigrationContractLog::getTopic3);
    assertThat(getContractResults()).hasSize(1).first().returns(functionResult.getBloom().toByteArray(), MigrationContractResult::getBloom).returns(contractResult.getConsensusTimestamp(), MigrationContractResult::getConsensusTimestamp).returns(functionResult.getContractCallResult().toByteArray(), MigrationContractResult::getCallResult).returns(functionResult.getContractID().getContractNum(), MigrationContractResult::getContractId).returns(functionResult.getErrorMessage(), MigrationContractResult::getErrorMessage).returns(functionResult.getCreatedContractIDsList().stream().map(EntityId::of).map(EntityId::getId).toArray(Long[]::new), MigrationContractResult::getCreatedContractIds);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) MigrationContractResult(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult) MigrationContractLog(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractLog) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

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