Search in sources :

Example 1 with TokenTransfer

use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onTokenTransfer.

@Test
void onTokenTransfer() {
    TokenTransfer tokenTransfer1 = domainBuilder.tokenTransfer().get();
    TokenTransfer tokenTransfer2 = domainBuilder.tokenTransfer().get();
    TokenTransfer tokenTransfer3 = domainBuilder.tokenTransfer().get();
    // when
    sqlEntityListener.onTokenTransfer(tokenTransfer1);
    sqlEntityListener.onTokenTransfer(tokenTransfer2);
    sqlEntityListener.onTokenTransfer(tokenTransfer3);
    completeFileAndCommit();
    // then
    assertThat(tokenTransferRepository.findAll()).containsExactlyInAnyOrder(tokenTransfer1, tokenTransfer2, tokenTransfer3);
}
Also used : TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TokenTransfer

use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTokenTest method tokenDissociateDeletedFungibleToken.

@Test
void tokenDissociateDeletedFungibleToken() {
    // given
    createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
    long tokenDeleteTimestamp = 15L;
    Transaction deleteTransaction = tokenDeleteTransaction(TOKEN_ID);
    insertAndParseTransaction(tokenDeleteTimestamp, deleteTransaction);
    // when
    Transaction dissociateTransaction = tokenDissociate(List.of(TOKEN_ID), PAYER2);
    long dissociateTimeStamp = 20L;
    TokenTransferList dissociateTransfer = tokenTransfer(TOKEN_ID, PAYER2, -10);
    insertAndParseTransaction(dissociateTimeStamp, dissociateTransaction, builder -> builder.addTokenTransferLists(dissociateTransfer));
    // then
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, dissociateTimeStamp, SYMBOL, INITIAL_SUPPLY - 10);
    var expected = domainBuilder.tokenTransfer().customize(t -> t.amount(-10).id(new TokenTransfer.Id(dissociateTimeStamp, EntityId.of(TOKEN_ID), EntityId.of(PAYER2))).isApproval(false).payerAccountId(EntityId.of(PAYER)).tokenDissociate(false)).get();
    assertThat(tokenTransferRepository.findById(expected.getId())).get().isEqualTo(expected);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) EntityId(com.hedera.mirror.common.domain.entity.EntityId) FixedFee(com.hederahashgraph.api.proto.java.FixedFee) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) StringUtils(org.apache.commons.lang3.StringUtils) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) TestUtils(com.hedera.mirror.importer.TestUtils) MethodSource(org.junit.jupiter.params.provider.MethodSource) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) TokenRepository(com.hedera.mirror.importer.repository.TokenRepository) TokenFreezeStatusEnum(com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum) Assertions.from(org.assertj.core.api.Assertions.from) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Resource(javax.annotation.Resource) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) CustomFee(com.hedera.mirror.common.domain.transaction.CustomFee) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) Stream(java.util.stream.Stream) Builder(lombok.Builder) AssessedCustomFeeWrapper(com.hedera.mirror.importer.domain.AssessedCustomFeeWrapper) Lists(org.assertj.core.util.Lists) TokenAccountRepository(com.hedera.mirror.importer.repository.TokenAccountRepository) ObjectAssert(org.assertj.core.api.ObjectAssert) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) Optional(java.util.Optional) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenAssociation(com.hederahashgraph.api.proto.java.TokenAssociation) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) NftId(com.hedera.mirror.common.domain.token.NftId) RoyaltyFee(com.hederahashgraph.api.proto.java.RoyaltyFee) EnumSource(org.junit.jupiter.params.provider.EnumSource) CustomFeeWrapper(com.hedera.mirror.importer.domain.CustomFeeWrapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) FractionalFee(com.hederahashgraph.api.proto.java.FractionalFee) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) NftTransferRepository(com.hedera.mirror.importer.repository.NftTransferRepository) AccountID(com.hederahashgraph.api.proto.java.AccountID) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenAccountId(com.hedera.mirror.common.domain.token.TokenAccountId) TokenTransferRepository(com.hedera.mirror.importer.repository.TokenTransferRepository) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) TokenType(com.hederahashgraph.api.proto.java.TokenType) Fraction(com.hederahashgraph.api.proto.java.Fraction) Key(com.hederahashgraph.api.proto.java.Key) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) TokenKycStatusEnum(com.hedera.mirror.common.domain.token.TokenKycStatusEnum) Assertions(org.junit.jupiter.api.Assertions) NON_FUNGIBLE_UNIQUE(com.hederahashgraph.api.proto.java.TokenType.NON_FUNGIBLE_UNIQUE) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) Comparator(java.util.Comparator) Collections(java.util.Collections) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenId(com.hedera.mirror.common.domain.token.TokenId) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) NftId(com.hedera.mirror.common.domain.token.NftId) TokenAccountId(com.hedera.mirror.common.domain.token.TokenAccountId) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TokenTransfer

use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.

the class TokenTransferRepositoryTest method findById.

@Test
void findById() {
    EntityId tokenId = EntityId.of(0L, 1L, 20L, TOKEN);
    EntityId accountId = EntityId.of(0L, 1L, 7L, ACCOUNT);
    EntityId payerAccountId = EntityId.of(0L, 1L, 500L, ACCOUNT);
    long amount = 40L;
    TokenTransfer tokenTransfer = domainBuilder.tokenTransfer().customize(t -> t.amount(amount).id(new TokenTransfer.Id(1L, tokenId, accountId)).payerAccountId(payerAccountId).tokenDissociate(false)).get();
    tokenTransferRepository.save(tokenTransfer);
    assertThat(tokenTransferRepository.findById(tokenTransfer.getId())).get().isEqualTo(tokenTransfer);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Test(org.junit.jupiter.api.Test) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) Test(org.junit.jupiter.api.Test)

Example 4 with TokenTransfer

use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method insertFungibleTokenTransfers.

private void insertFungibleTokenTransfers(long consensusTimestamp, TransactionBody body, boolean isTokenDissociate, TokenID tokenId, EntityId entityTokenId, EntityId payerAccountId, List<AccountAmount> tokenTransfers) {
    for (AccountAmount accountAmount : tokenTransfers) {
        EntityId accountId = EntityId.of(accountAmount.getAccountID());
        long amount = accountAmount.getAmount();
        TokenTransfer tokenTransfer = new TokenTransfer();
        tokenTransfer.setAmount(amount);
        tokenTransfer.setId(new TokenTransfer.Id(consensusTimestamp, entityTokenId, accountId));
        tokenTransfer.setIsApproval(false);
        tokenTransfer.setPayerAccountId(payerAccountId);
        tokenTransfer.setTokenDissociate(isTokenDissociate);
        // then again set is_approval=true
        if (amount < 0) {
            // Is the accountAmount from the record also inside a body's transfer list for the given tokenId?
            AccountAmount accountAmountInsideTransferList = findAccountAmount(accountAmount::equals, tokenId, body);
            if (accountAmountInsideTransferList == null) {
                // Is there any account amount inside the body's transfer list for the given tokenId
                // with the same accountId as the accountAmount from the record?
                AccountAmount accountAmountWithSameIdInsideBody = findAccountAmount(aa -> aa.getAccountID().equals(accountAmount.getAccountID()) && aa.getIsApproval(), tokenId, body);
                if (accountAmountWithSameIdInsideBody != null) {
                    tokenTransfer.setIsApproval(true);
                }
            } else {
                tokenTransfer.setIsApproval(accountAmountInsideTransferList.getIsApproval());
            }
        }
        entityListener.onTokenTransfer(tokenTransfer);
        if (isTokenDissociate) {
            // token transfers in token dissociate are for deleted tokens and the amount is negative to
            // bring the account's balance of the token to 0. Set the totalSupply of the token object to the
            // negative amount, later in the pipeline the token total supply will be reduced accordingly
            Token token = Token.of(entityTokenId);
            token.setModifiedTimestamp(consensusTimestamp);
            token.setTotalSupply(accountAmount.getAmount());
            entityListener.onToken(token);
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Token(com.hedera.mirror.common.domain.token.Token) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 5 with TokenTransfer

use of com.hedera.mirror.common.domain.token.TokenTransfer in project hedera-mirror-node by hashgraph.

the class TransferTransactionPayerMigrationTest method verifyEntityTimestampMigration.

@Test
void verifyEntityTimestampMigration() throws Exception {
    Entity node = domainBuilder.entity().customize(e -> e.createdTimestamp(10L).timestampRange(Range.atLeast(10L))).get();
    Entity treasury = domainBuilder.entity().customize(e -> e.createdTimestamp(20L).timestampRange(Range.atLeast(20L))).get();
    Entity sender = domainBuilder.entity().customize(e -> e.createdTimestamp(30L).timestampRange(Range.atLeast(30L))).get();
    Entity receiver = domainBuilder.entity().customize(e -> e.createdTimestamp(40L).timestampRange(Range.atLeast(40L))).get();
    Entity contract = domainBuilder.entity().customize(e -> e.createdTimestamp(50L).timestampRange(Range.atLeast(50L)).type(EntityType.CONTRACT)).get();
    Entity file = domainBuilder.entity().customize(e -> e.createdTimestamp(60L).timestampRange(Range.atLeast(60L)).type(EntityType.FILE)).get();
    Entity topic = domainBuilder.entity().customize(e -> e.createdTimestamp(70L).timestampRange(Range.atLeast(70L)).type(EntityType.TOPIC)).get();
    Entity token = domainBuilder.entity().customize(e -> e.createdTimestamp(80L).timestampRange(Range.atLeast(80L)).type(TOKEN)).get();
    Entity schedule = domainBuilder.entity().customize(e -> e.createdTimestamp(90L).timestampRange(Range.atLeast(90L)).type(EntityType.SCHEDULE)).get();
    // given
    persistEntities(List.of(node, treasury, sender, receiver, contract, file, topic, token, schedule));
    MigrationTransaction transfer1 = transaction(schedule.getCreatedTimestamp() + 200L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer2 = transaction(schedule.getCreatedTimestamp() + 300L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer3 = transaction(schedule.getCreatedTimestamp() + 400L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer4 = transaction(schedule.getCreatedTimestamp() + 500L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer5 = transaction(schedule.getCreatedTimestamp() + 600L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    persistTransactions(List.of(transaction(contract.getCreatedTimestamp(), contract.getId(), SUCCESS, TransactionType.CONTRACTCREATEINSTANCE), transaction(contract.getCreatedTimestamp() + 1, contract.getId(), INSUFFICIENT_TX_FEE, TransactionType.CONTRACTUPDATEINSTANCE), transaction(file.getCreatedTimestamp(), file.getId(), SUCCESS, TransactionType.FILECREATE), transaction(file.getCreatedTimestamp() + 1, file.getId(), SUCCESS, TransactionType.FILEDELETE), transaction(topic.getCreatedTimestamp(), topic.getId(), SUCCESS, TransactionType.CONSENSUSCREATETOPIC), transaction(topic.getCreatedTimestamp() + 1, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(topic.getCreatedTimestamp() + 2, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(topic.getCreatedTimestamp() + 3, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(token.getCreatedTimestamp(), token.getId(), SUCCESS, TransactionType.TOKENCREATION), transaction(schedule.getCreatedTimestamp(), schedule.getId(), SUCCESS, TransactionType.SCHEDULECREATE), transfer1, transfer2, transfer3, transfer4, transfer5));
    EntityId nodeId = node.toEntityId();
    EntityId treasuryId = treasury.toEntityId();
    EntityId senderId = sender.toEntityId();
    EntityId receiverId = receiver.toEntityId();
    EntityId tokenId = token.toEntityId();
    long senderPaymentAmount = -45L;
    long receivedAmount = 30L;
    long nodePaymentAmount = 10L;
    long treasuryPaymentAmount = 5L;
    AssessedCustomFee assessedCustomFee1 = new AssessedCustomFee();
    assessedCustomFee1.setAmount(receivedAmount);
    assessedCustomFee1.setEffectivePayerAccountIds(List.of(senderId.getId()));
    assessedCustomFee1.setId(new AssessedCustomFee.Id(receiverId, transfer1.getConsensusTimestamp()));
    assessedCustomFee1.setPayerAccountId(tokenId);
    assessedCustomFee1.setTokenId(tokenId);
    AssessedCustomFee assessedCustomFee2 = new AssessedCustomFee();
    assessedCustomFee2.setAmount(receivedAmount);
    assessedCustomFee2.setEffectivePayerAccountIds(List.of(senderId.getId()));
    assessedCustomFee2.setId(new AssessedCustomFee.Id(receiverId, transfer5.getConsensusTimestamp()));
    assessedCustomFee2.setPayerAccountId(tokenId);
    assessedCustomFee2.setTokenId(tokenId);
    persistAssessedCustomFees(List.of(// assessed custom fee transfer
    assessedCustomFee1, // all transfers
    assessedCustomFee2));
    persistCryptoTransfers(List.of(// assessed custom fee transfer
    new CryptoTransfer(transfer1.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer1.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer1.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer1.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // crypto only transfer
    new CryptoTransfer(transfer2.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer2.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer2.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer2.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // nft transfer
    new CryptoTransfer(transfer3.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer3.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer3.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer3.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // token transfer
    new CryptoTransfer(transfer4.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer4.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer4.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer4.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // all transfers
    new CryptoTransfer(transfer5.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer5.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer5.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer5.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId)));
    persistNonFeeTransfers(List.of(// assessed custom fee only transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.consensusTimestamp(transfer1.getConsensusTimestamp()).amount(senderPaymentAmount).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer1.getConsensusTimestamp()).entityId(receiverId)).get(), // crypto only transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer2.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer2.getConsensusTimestamp()).entityId(receiverId)).get(), // nft transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer3.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer3.getConsensusTimestamp()).entityId(receiverId)).get(), // token transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer4.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer4.getConsensusTimestamp()).entityId(receiverId)).get(), // all transfers
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer5.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer5.getConsensusTimestamp()).entityId(receiverId)).get()));
    persistNftTransfers(List.of(// nft transfer
    domainBuilder.nftTransfer().customize(n -> n.id(new NftTransferId(transfer3.getConsensusTimestamp(), 1L, tokenId)).payerAccountId(null).receiverAccountId(receiverId).senderAccountId(senderId)).get(), // all transfers
    domainBuilder.nftTransfer().customize(n -> n.id(new NftTransferId(transfer5.getConsensusTimestamp(), 2L, tokenId)).payerAccountId(null).receiverAccountId(receiverId).senderAccountId(senderId)).get()));
    persistTokenTransfers(List.of(// token transfer
    new TokenTransfer(transfer4.getConsensusTimestamp(), -receivedAmount, tokenId, senderId), new TokenTransfer(transfer4.getConsensusTimestamp(), receivedAmount, tokenId, receiverId), // all transfers
    new TokenTransfer(transfer5.getConsensusTimestamp(), -receivedAmount, tokenId, senderId), new TokenTransfer(transfer5.getConsensusTimestamp(), receivedAmount, tokenId, receiverId)));
    // when
    migrate();
    List<SharedTransfer> expectedAssessedCustomFeeTransfers = List.of(// assessed custom fee transfer
    new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, senderId));
    List<SharedTransfer> expectedCryptoTransfers = List.of(// assessed custom fee transfer
    new SharedTransfer(senderPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // crypto only transfer
    new SharedTransfer(senderPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer2.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // nft transfer
    new SharedTransfer(senderPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // token transfer
    new SharedTransfer(senderPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // all transfers
    new SharedTransfer(senderPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, treasuryId, null));
    List<SharedTransfer> expectedNftTransfers = List.of(// nft transfer
    new SharedTransfer(1L, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, senderId), new SharedTransfer(2L, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, senderId));
    List<SharedTransfer> expectedNonFeeTransfers = List.of(// assessed custom fee only transfer
    new SharedTransfer(senderPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, null), // crypto only transfer
    new SharedTransfer(senderPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer2.getConsensusTimestamp(), PAYER_ID, receiverId, null), // nft transfer
    new SharedTransfer(senderPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, null), // token transfer
    new SharedTransfer(senderPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), // token transfer
    new SharedTransfer(senderPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null));
    List<SharedTransfer> expectedTokenTransfers = List.of(// token transfer
    new SharedTransfer(-receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), // all transfer
    new SharedTransfer(-receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null));
    // then
    assertThat(findAssessedCustomFees()).containsExactlyInAnyOrderElementsOf(expectedAssessedCustomFeeTransfers);
    assertThat(findCryptoTransfers()).containsExactlyInAnyOrderElementsOf(expectedCryptoTransfers);
    assertThat(findNftTransfers()).containsExactlyInAnyOrderElementsOf(expectedNftTransfers);
    assertThat(findNonFeeTransfersAsSharedTransfers()).containsExactlyInAnyOrderElementsOf(expectedNonFeeTransfers);
    assertThat(findTokenTransfers()).containsExactlyInAnyOrderElementsOf(expectedTokenTransfers);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TransactionRepository(com.hedera.mirror.importer.repository.TransactionRepository) StringUtils(org.apache.commons.lang3.StringUtils) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) Value(org.springframework.beans.factory.annotation.Value) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) ObjectUtils(org.apache.commons.lang3.ObjectUtils) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) NftTransferRepository(com.hedera.mirror.importer.repository.NftTransferRepository) Tag(org.junit.jupiter.api.Tag) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) EnabledIfV1(com.hedera.mirror.importer.EnabledIfV1) NonFeeTransferRepository(com.hedera.mirror.importer.repository.NonFeeTransferRepository) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) TestPropertySource(org.springframework.test.context.TestPropertySource) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) PostgreSQLGuavaRangeType(com.vladmihalcea.hibernate.type.range.guava.PostgreSQLGuavaRangeType) PreparedStatement(java.sql.PreparedStatement) File(java.io.File) TokenTransferRepository(com.hedera.mirror.importer.repository.TokenTransferRepository) Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) List(java.util.List) EntityRepository(com.hedera.mirror.importer.repository.EntityRepository) CryptoTransferRepository(com.hedera.mirror.importer.repository.CryptoTransferRepository) Data(lombok.Data) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) AllArgsConstructor(lombok.AllArgsConstructor) NoArgsConstructor(lombok.NoArgsConstructor) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

TokenTransfer (com.hedera.mirror.common.domain.token.TokenTransfer)12 EntityId (com.hedera.mirror.common.domain.entity.EntityId)7 Test (org.junit.jupiter.api.Test)7 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 Token (com.hedera.mirror.common.domain.token.Token)4 Entity (com.hedera.mirror.common.domain.entity.Entity)3 TOKEN (com.hedera.mirror.common.domain.entity.EntityType.TOKEN)3 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)3 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)3 Resource (javax.annotation.Resource)3 ByteString (com.google.protobuf.ByteString)2 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)2 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)2 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)2 Nft (com.hedera.mirror.common.domain.token.Nft)2 NftId (com.hedera.mirror.common.domain.token.NftId)2 NftTransfer (com.hedera.mirror.common.domain.token.NftTransfer)2 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)2