use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.
the class EntityTimestampMigrationTest method transaction.
private Transaction transaction(long consensusNs, long entityNum, ResponseCodeEnum result, TransactionType type) {
Transaction transaction = new Transaction();
transaction.setConsensusTimestamp(consensusNs);
transaction.setEntityId(EntityId.of(0, 0, entityNum, EntityType.UNKNOWN));
transaction.setNodeAccountId(NODE_ACCOUNT_ID);
transaction.setPayerAccountId(PAYER_ID);
transaction.setResult(result.getNumber());
transaction.setType(type.getProtoId());
transaction.setValidStartNs(consensusNs - 10);
return transaction;
}
use of com.hedera.mirror.common.domain.transaction.Transaction 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));
}
use of com.hedera.mirror.common.domain.transaction.Transaction 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);
}
use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.
the class EntityTimestampMigrationV1_46_0Test method transaction.
private Transaction transaction(long consensusNs, long entityNum, ResponseCodeEnum result, TransactionType type) {
Transaction transaction = new Transaction();
transaction.setConsensusTimestamp(consensusNs);
transaction.setEntityId(EntityId.of(0, 0, entityNum, EntityType.UNKNOWN));
transaction.setNodeAccountId(NODE_ACCOUNT_ID);
transaction.setPayerAccountId(PAYER_ID);
transaction.setResult(result.getNumber());
transaction.setType(type.getProtoId());
transaction.setValidStartNs(consensusNs - 10);
return transaction;
}
use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTreasury.
@Test
void updateTreasury() {
AbstractEntity entity = getExpectedUpdatedEntity();
AccountID previousAccountId = AccountID.newBuilder().setAccountNum(1L).build();
AccountID newAccountId = AccountID.newBuilder().setAccountNum(2L).build();
TokenID tokenID = TokenID.newBuilder().setTokenNum(3L).build();
long consensusTimestamp = DomainUtils.timestampInNanosMax(MODIFIED_TIMESTAMP);
TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(tokenID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(newAccountId).setSenderAccountID(previousAccountId).setSerialNumber(NftTransferId.WILDCARD_SERIAL_NUMBER).build()).build();
TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
Transaction transaction = new Transaction();
transaction.setEntityId(entity.toEntityId());
transactionHandler.updateTransaction(transaction, recordItem);
TransactionBody body = recordItem.getTransactionBody();
var payerAccount = EntityId.of(body.getTransactionID().getAccountID()).toEntity().getId();
verify(nftRepository).updateTreasury(tokenID.getTokenNum(), previousAccountId.getAccountNum(), newAccountId.getAccountNum(), consensusTimestamp, payerAccount, false);
}
Aggregations