Search in sources :

Example 26 with TokenTransferList

use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTokenTest method tokenTransfer.

void tokenTransfer(List<AssessedCustomFee> assessedCustomFees, List<com.hederahashgraph.api.proto.java.AssessedCustomFee> protoAssessedCustomFees, boolean hasAutoTokenAssociations, boolean isPrecompile) {
    // given
    createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
    TokenID tokenId2 = TokenID.newBuilder().setTokenNum(7).build();
    String symbol2 = "MIRROR";
    createTokenEntity(tokenId2, FUNGIBLE_COMMON, symbol2, 10L, false, false, false);
    AccountID accountId = AccountID.newBuilder().setAccountNum(1).build();
    // token transfer
    Transaction transaction = tokenTransferTransaction();
    TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(-1000).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(1000).build()).build();
    TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(tokenId2).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(333).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(-333).build()).build();
    List<TokenTransferList> transferLists = List.of(transferList1, transferList2);
    // token treasury associations <TOKEN_ID, PAYER> and <tokenId2, PAYER> are created in the token create
    // transaction and they are not auto associations; the two token transfers' <token, recipient> pairs are
    // <TOKEN_ID, accountId> and <tokenId2, PAYER>, since <tokenId2, PAYER> already exists, only
    // <TOKEN_ID accountId> will be auto associated
    var autoTokenAssociation = TokenAssociation.newBuilder().setAccountId(accountId).setTokenId(TOKEN_ID).build();
    var autoTokenAccount = new TokenAccount(EntityId.of(TOKEN_ID), EntityId.of(accountId), TRANSFER_TIMESTAMP);
    autoTokenAccount.setAssociated(true);
    autoTokenAccount.setAutomaticAssociation(true);
    autoTokenAccount.setCreatedTimestamp(TRANSFER_TIMESTAMP);
    autoTokenAccount.setFreezeStatus(TokenFreezeStatusEnum.NOT_APPLICABLE);
    autoTokenAccount.setKycStatus(TokenKycStatusEnum.NOT_APPLICABLE);
    List<TokenAccount> expectedAutoAssociatedTokenAccounts = hasAutoTokenAssociations ? List.of(autoTokenAccount) : Collections.emptyList();
    // when
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(TRANSFER_TIMESTAMP, transaction, builder -> {
        builder.addAllTokenTransferLists(transferLists).addAllAssessedCustomFees(protoAssessedCustomFees);
        if (hasAutoTokenAssociations) {
            builder.addAutomaticTokenAssociations(autoTokenAssociation);
        }
        if (isPrecompile) {
            buildContractFunctionResult(builder.getContractCallResultBuilder());
            contractFunctionResultAtomic.set(builder.getContractCallResult());
        }
    });
    // then
    assertTokenTransferInRepository(TOKEN_ID, PAYER, TRANSFER_TIMESTAMP, -1000);
    assertTokenTransferInRepository(TOKEN_ID, accountId, TRANSFER_TIMESTAMP, 1000);
    assertTokenTransferInRepository(tokenId2, PAYER, TRANSFER_TIMESTAMP, 333);
    assertTokenTransferInRepository(tokenId2, accountId, TRANSFER_TIMESTAMP, -333);
    assertAssessedCustomFeesInDb(assessedCustomFees);
    assertThat(tokenAccountRepository.findAll()).filteredOn(TokenAccount::getAutomaticAssociation).containsExactlyInAnyOrderElementsOf(expectedAutoAssociatedTokenAccounts);
    if (isPrecompile) {
        assertContractResult(TRANSFER_TIMESTAMP, contractFunctionResultAtomic.get());
    }
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 27 with TokenTransferList

use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTokenTest method tokenBurnNftMissingNft.

@Test
void tokenBurnNftMissingNft() {
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0L);
    long mintTimestamp = 10L;
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, List.of(SERIAL_NUMBER_2));
    Transaction mintTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, List.of(SERIAL_NUMBER_2));
    insertAndParseTransaction(mintTimestamp, mintTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(SERIAL_NUMBER_LIST.size()).addSerialNumbers(SERIAL_NUMBER_2);
        builder.addTokenTransferLists(mintTransfer);
    });
    long burnTimestamp = 15L;
    TokenTransferList burnTransfer = nftTransfer(TOKEN_ID, DEFAULT_ACCOUNT_ID, PAYER, List.of(SERIAL_NUMBER_1));
    Transaction burnTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, false, 0, List.of(SERIAL_NUMBER_1));
    insertAndParseTransaction(burnTimestamp, burnTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(0);
        builder.addTokenTransferLists(burnTransfer);
    });
    // Verify
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_2, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(burnTimestamp, SERIAL_NUMBER_1, TOKEN_ID, null, PAYER);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, burnTimestamp, SYMBOL, 0);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, false, mintTimestamp, burnTimestamp, METADATA.getBytes(), EntityId.of(PAYER), true);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_2, true, mintTimestamp, mintTimestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with TokenTransferList

use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTokenTest method nftTransferMissingNft.

@Test
void nftTransferMissingNft() {
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    TokenID tokenID2 = TokenID.newBuilder().setTokenNum(7).build();
    String symbol2 = "MIRROR";
    createTokenEntity(tokenID2, FUNGIBLE_COMMON, symbol2, 15L, false, false, false);
    // token transfer
    Transaction transaction = tokenTransferTransaction();
    TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(tokenID2).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_1).build()).build();
    TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(tokenID2).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_2).build()).build();
    long transferTimestamp = 25L;
    insertAndParseTransaction(transferTimestamp, transaction, builder -> {
        builder.addAllTokenTransferLists(List.of(transferList1, transferList2));
    });
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(transferTimestamp, 1L, tokenID2, RECEIVER, PAYER);
    assertNftTransferInRepository(transferTimestamp, 2L, tokenID2, RECEIVER, PAYER);
    assertNftInRepository(tokenID2, SERIAL_NUMBER_1, false, transferTimestamp, transferTimestamp, METADATA.getBytes(), EntityId.of(RECEIVER), false);
    assertNftInRepository(tokenID2, SERIAL_NUMBER_2, false, transferTimestamp, transferTimestamp, METADATA.getBytes(), EntityId.of(RECEIVER), false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with TokenTransferList

use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTokenTest method tokenWipe.

@Test
void tokenWipe() {
    createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
    long transferAmount = -1000L;
    long wipeAmount = 100L;
    long wipeTimestamp = 10L;
    TokenTransferList tokenTransfer = tokenTransfer(TOKEN_ID, PAYER, transferAmount);
    Transaction transaction = tokenWipeTransaction(TOKEN_ID, FUNGIBLE_COMMON, wipeAmount, Collections.emptyList());
    insertAndParseTransaction(wipeTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(INITIAL_SUPPLY - wipeAmount);
        builder.addTokenTransferLists(tokenTransfer);
    });
    // Verify
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, wipeTimestamp, SYMBOL, INITIAL_SUPPLY - wipeAmount);
    assertThat(tokenTransferRepository.count()).isEqualTo(2L);
    assertTokenTransferInRepository(TOKEN_ID, PAYER, CREATE_TIMESTAMP, INITIAL_SUPPLY);
    assertTokenTransferInRepository(TOKEN_ID, PAYER, wipeTimestamp, transferAmount);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)29 Transaction (com.hederahashgraph.api.proto.java.Transaction)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Test (org.junit.jupiter.api.Test)18 ContractFunctionResult (com.hederahashgraph.api.proto.java.ContractFunctionResult)6 TokenID (com.hederahashgraph.api.proto.java.TokenID)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ByteString (com.google.protobuf.ByteString)5 NftId (com.hedera.mirror.common.domain.token.NftId)5 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)5 AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)5 AccountID (com.hederahashgraph.api.proto.java.AccountID)5 NftTransfer (com.hederahashgraph.api.proto.java.NftTransfer)5 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 ArrayList (java.util.ArrayList)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)3 StringValue (com.google.protobuf.StringValue)2 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)2 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)2