use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.
the class SupportDeletedTokenDissociateMigrationTest method persistTokenTransfers.
private void persistTokenTransfers(List<TokenTransfer> tokenTransfers) {
for (TokenTransfer tokenTransfer : tokenTransfers) {
var id = tokenTransfer.getId();
jdbcOperations.update("insert into token_transfer (amount, account_id, consensus_timestamp, token_id)" + " values (?,?,?,?)", tokenTransfer.getAmount(), id.getAccountId().getId(), id.getConsensusTimestamp(), id.getTokenId().getId());
}
}
use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.
the class SupportDeletedTokenDissociateMigrationTest method findAllTokenTransfers.
private List<TokenTransfer> findAllTokenTransfers() {
return jdbcOperations.query("select * from token_transfer", (rs, rowNum) -> {
TokenTransfer tokenTransfer = new TokenTransfer();
tokenTransfer.setId(new TokenTransfer.Id(rs.getLong("consensus_timestamp"), EntityIdEndec.decode(rs.getLong("token_id"), TOKEN), EntityIdEndec.decode(rs.getLong("account_id"), ACCOUNT)));
tokenTransfer.setAmount(rs.getLong("amount"));
return tokenTransfer;
});
}
use of com.hedera.mirror.common.domain.token.TokenTransfer 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.token.TokenTransfer in project hedera-mirror-node by hashgraph.
the class BalanceReconciliationServiceTest method tokenTransfer.
private void tokenTransfer(long accountNum, long tokenNum, long amount) {
long timestamp = domainBuilder.timestamp();
EntityId accountId = EntityId.of(accountNum, EntityType.ACCOUNT);
EntityId tokenId = EntityId.of(tokenNum, EntityType.TOKEN);
domainBuilder.tokenTransfer().customize(c -> c.amount(amount).id(new TokenTransfer.Id(timestamp, tokenId, accountId))).persist();
}
use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method getTokenTransfer.
private TokenTransfer getTokenTransfer(long amount, long consensusTimestamp, EntityId tokenId, EntityId accountId) {
TokenTransfer tokenTransfer = new TokenTransfer();
tokenTransfer.setAmount(amount);
tokenTransfer.setId(new TokenTransfer.Id(consensusTimestamp, tokenId, accountId));
tokenTransfer.setPayerAccountId(TRANSACTION_PAYER);
return tokenTransfer;
}
Aggregations