Search in sources :

Example 6 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenSupplyFtsPrecompile.

private void tokenSupplyFtsPrecompile(boolean isMint) {
    createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
    long amount = 1000;
    long mintTimestamp = 10L;
    TokenTransferList tokenTransfer = tokenTransfer(TOKEN_ID, PAYER, amount);
    Transaction transaction = tokenSupplyTransaction(TOKEN_ID, FUNGIBLE_COMMON, isMint, amount, null);
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(mintTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(INITIAL_SUPPLY + amount);
        builder.addTokenTransferLists(tokenTransfer);
        buildContractFunctionResult(builder.getContractCallResultBuilder());
        contractFunctionResultAtomic.set(builder.getContractCallResult());
    });
    // Verify
    assertThat(tokenTransferRepository.count()).isEqualTo(2L);
    assertTokenTransferInRepository(TOKEN_ID, PAYER, CREATE_TIMESTAMP, INITIAL_SUPPLY);
    assertTokenTransferInRepository(TOKEN_ID, PAYER, mintTimestamp, amount);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, mintTimestamp, SYMBOL, INITIAL_SUPPLY + amount);
    assertContractResult(mintTimestamp, contractFunctionResultAtomic.get());
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 7 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenWipeNftMissingNft.

@Test
void tokenWipeNftMissingNft() {
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    long wipeTimestamp = 15L;
    TokenTransferList wipeTransfer = nftTransfer(TOKEN_ID, DEFAULT_ACCOUNT_ID, RECEIVER, List.of(SERIAL_NUMBER_1));
    Transaction transaction = tokenWipeTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, 0, List.of(SERIAL_NUMBER_1));
    insertAndParseTransaction(wipeTimestamp, transaction, builder -> {
        builder.addTokenTransferLists(wipeTransfer);
    });
    // Verify
    assertThat(nftTransferRepository.count()).isEqualTo(1L);
    assertNftTransferInRepository(wipeTimestamp, SERIAL_NUMBER_1, TOKEN_ID, null, RECEIVER);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, wipeTimestamp, SYMBOL, 0);
    assertNftInRepository(TOKEN_ID, 1L, false, wipeTimestamp, wipeTimestamp, METADATA.getBytes(), EntityId.of(PAYER), true);
}
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 8 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenSupplyMintNftsPrecompile.

private void tokenSupplyMintNftsPrecompile(long timestamp) {
    // given
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, SERIAL_NUMBER_LIST);
    Transaction transaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, SERIAL_NUMBER_LIST);
    // when
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(timestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(SERIAL_NUMBER_LIST.size()).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        builder.addTokenTransferLists(mintTransfer);
        buildContractFunctionResult(builder.getContractCallResultBuilder());
        contractFunctionResultAtomic.set(builder.getContractCallResult());
    });
    // then
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(timestamp, SERIAL_NUMBER_2, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(timestamp, SERIAL_NUMBER_1, TOKEN_ID, PAYER, null);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, timestamp, SYMBOL, 2);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, true, timestamp, timestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_2, true, timestamp, timestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    assertContractResult(timestamp, contractFunctionResultAtomic.get());
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 9 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method nftTransfersHaveCorrectIsApprovalValue.

@ParameterizedTest
@MethodSource("nftTransfersHaveCorrectIsApprovalValueArgumentProvider")
void nftTransfersHaveCorrectIsApprovalValue(boolean isApproval1, boolean isApproval2) {
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    // mint transfer / transaction 1
    long mintTimestamp1 = 20L;
    TokenTransferList mintTransfer1 = nftTransfer(TOKEN_ID, RECEIVER, DEFAULT_ACCOUNT_ID, List.of(SERIAL_NUMBER_1));
    Transaction mintTransaction1 = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, List.of(SERIAL_NUMBER_1));
    insertAndParseTransaction(mintTimestamp1, mintTransaction1, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(1L).addSerialNumbers(SERIAL_NUMBER_1);
        builder.addTokenTransferLists(mintTransfer1);
    });
    // mint transfer / transaction 2
    long mintTimestamp2 = 30L;
    TokenTransferList mintTransfer2 = nftTransfer(TOKEN_ID, RECEIVER, DEFAULT_ACCOUNT_ID, List.of(SERIAL_NUMBER_2));
    Transaction mintTransaction2 = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, List.of(SERIAL_NUMBER_2));
    insertAndParseTransaction(mintTimestamp2, mintTransaction2, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(2L).addSerialNumbers(SERIAL_NUMBER_2);
        builder.addTokenTransferLists(mintTransfer2);
    });
    // token transfer
    Transaction transaction = buildTransaction(builder -> {
        // NFT transfer list 1
        TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_1).setIsApproval(isApproval1).build()).build();
        // NFT transfer list 2
        TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_2).setIsApproval(isApproval2).build()).build();
        builder.getCryptoTransferBuilder().addTokenTransfers(transferList1).addTokenTransfers(transferList2);
    });
    long transferTimestamp = 40L;
    insertAndParseTransaction(transferTimestamp, transaction, builder -> {
        // NFT transfer list 1
        TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_1).build()).build();
        // NFT transfer list 2
        TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_2).build()).build();
        builder.addAllTokenTransferLists(List.of(transferList1, transferList2));
    });
    assertThat(nftTransferRepository.count()).isEqualTo(4L);
    assertNftTransferInRepository(mintTimestamp1, SERIAL_NUMBER_1, TOKEN_ID, RECEIVER, null);
    assertNftTransferInRepository(mintTimestamp2, SERIAL_NUMBER_2, TOKEN_ID, RECEIVER, null);
    assertNftTransferInRepository(transferTimestamp, 1L, TOKEN_ID, RECEIVER, PAYER, isApproval1);
    assertNftTransferInRepository(transferTimestamp, 2L, TOKEN_ID, RECEIVER, PAYER, isApproval2);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, true, mintTimestamp1, transferTimestamp, METADATA.getBytes(), EntityId.of(RECEIVER), false);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_2, true, mintTimestamp2, transferTimestamp, METADATA.getBytes(), EntityId.of(RECEIVER), false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with TokenTransferList

use of com.hederahashgraph.api.proto.java.TokenTransferList 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)

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