Search in sources :

Example 21 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenMintNftsMissingToken.

@Test
void tokenMintNftsMissingToken() {
    // given
    long mintTimestamp = 10L;
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, SERIAL_NUMBER_LIST);
    Transaction transaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 2, SERIAL_NUMBER_LIST);
    // when
    insertAndParseTransaction(mintTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(1L).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        builder.addTokenTransferLists(mintTransfer);
    });
    // then
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_2, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_1, TOKEN_ID, PAYER, null);
    assertTokenInRepository(TOKEN_ID, false, CREATE_TIMESTAMP, mintTimestamp, SYMBOL, 1);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, false, mintTimestamp, mintTimestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_2, false, 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 22 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenCreateAndAssociateAndWipeInSameRecordFile.

@Test
void tokenCreateAndAssociateAndWipeInSameRecordFile() {
    long transferAmount = -1000L;
    long wipeAmount = 100L;
    long wipeTimestamp = 10L;
    long newTotalSupply = INITIAL_SUPPLY - wipeAmount;
    // create token with a transfer
    Transaction createTransaction = tokenCreateTransaction(FUNGIBLE_COMMON, false, false, false, SYMBOL);
    TokenTransferList createTokenTransfer = tokenTransfer(TOKEN_ID, PAYER2, INITIAL_SUPPLY);
    RecordItem createTokenRecordItem = getRecordItem(CREATE_TIMESTAMP, createTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(INITIAL_SUPPLY).setTokenID(TOKEN_ID);
        builder.addTokenTransferLists(createTokenTransfer);
    });
    // associate with token
    Transaction associateTransaction = tokenAssociate(List.of(TOKEN_ID), PAYER2);
    RecordItem associateRecordItem = getRecordItem(ASSOCIATE_TIMESTAMP, associateTransaction);
    // wipe amount from token with a transfer
    TokenTransferList wipeTokenTransfer = tokenTransfer(TOKEN_ID, PAYER2, transferAmount);
    Transaction wipeTransaction = tokenWipeTransaction(TOKEN_ID, FUNGIBLE_COMMON, wipeAmount, null);
    RecordItem wipeRecordItem = getRecordItem(wipeTimestamp, wipeTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(newTotalSupply);
        builder.addTokenTransferLists(wipeTokenTransfer);
    });
    // process all record items in a single file
    parseRecordItemsAndCommit(List.of(createTokenRecordItem, associateRecordItem, wipeRecordItem));
    // Verify token, tokenAccount and tokenTransfer
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, wipeTimestamp, SYMBOL, newTotalSupply);
    assertTokenAccountInRepository(TOKEN_ID, PAYER2, ASSOCIATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, true, TokenFreezeStatusEnum.NOT_APPLICABLE, TokenKycStatusEnum.NOT_APPLICABLE);
    assertThat(tokenTransferRepository.count()).isEqualTo(2L);
    assertTokenTransferInRepository(TOKEN_ID, PAYER2, CREATE_TIMESTAMP, INITIAL_SUPPLY);
    assertTokenTransferInRepository(TOKEN_ID, PAYER2, wipeTimestamp, transferAmount);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method nftUpdateTreasury.

@Test
void nftUpdateTreasury() {
    // given
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    long mintTimestamp = 10L;
    List<Long> serialNumbers = List.of(1L);
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, serialNumbers);
    Transaction mintTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, serialNumbers);
    insertAndParseTransaction(mintTimestamp, mintTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(serialNumbers.size()).addAllSerialNumbers(serialNumbers);
        builder.addTokenTransferLists(mintTransfer);
    });
    // when
    long updateTimestamp = 15L;
    TokenTransferList treasuryUpdateTransfer = nftTransfer(TOKEN_ID, PAYER2, PAYER, List.of(NftTransferId.WILDCARD_SERIAL_NUMBER));
    insertAndParseTransaction(updateTimestamp, buildTransaction(builder -> builder.getTokenUpdateBuilder().setToken(TOKEN_ID).setTreasury(PAYER2)), builder -> builder.addTokenTransferLists(treasuryUpdateTransfer));
    // then
    assertThat(nftTransferRepository.findAll()).containsExactlyInAnyOrder(domainNftTransfer(mintTimestamp, PAYER, DEFAULT_ACCOUNT_ID, 1L, TOKEN_ID, PAYER), domainNftTransfer(updateTimestamp, PAYER2, PAYER, 1L, TOKEN_ID, PAYER));
}
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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenMintNfts.

@Test
void tokenMintNfts() {
    // given
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    long mintTimestamp = 10L;
    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
    insertAndParseTransaction(mintTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(SERIAL_NUMBER_LIST.size()).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        builder.addTokenTransferLists(mintTransfer);
    });
    // then
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_2, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_1, TOKEN_ID, PAYER, null);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, mintTimestamp, SYMBOL, 2);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, true, mintTimestamp, mintTimestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    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 25 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenBurnNft.

@Test
void tokenBurnNft() {
    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, SERIAL_NUMBER_LIST);
    Transaction mintTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, SERIAL_NUMBER_LIST);
    insertAndParseTransaction(mintTimestamp, mintTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(SERIAL_NUMBER_LIST.size()).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        builder.addTokenTransferLists(mintTransfer);
    });
    // approve allowance for nft 1
    long approveAllowanceTimestamp = 12L;
    var cryptoApproveAllowanceTransaction = buildTransaction(b -> b.getCryptoApproveAllowanceBuilder().addNftAllowances(NftAllowance.newBuilder().setOwner(PAYER).setTokenId(TOKEN_ID).addSerialNumbers(SERIAL_NUMBER_1).setSpender(SPENDER)));
    insertAndParseTransaction(approveAllowanceTimestamp, cryptoApproveAllowanceTransaction);
    var expectedNft1 = Nft.builder().id(new NftId(SERIAL_NUMBER_1, EntityId.of(TOKEN_ID))).accountId(EntityId.of(PAYER)).createdTimestamp(mintTimestamp).deleted(false).metadata(METADATA.getBytes()).modifiedTimestamp(approveAllowanceTimestamp).spender(EntityId.of(SPENDER)).build();
    assertThat(nftRepository.findById(expectedNft1.getId())).get().isEqualTo(expectedNft1);
    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(0L);
        builder.addTokenTransferLists(burnTransfer);
    });
    expectedNft1.setAccountId(null);
    expectedNft1.setDeleted(true);
    expectedNft1.setModifiedTimestamp(burnTimestamp);
    expectedNft1.setSpender(null);
    var expectedNft2 = Nft.builder().id(new NftId(SERIAL_NUMBER_2, EntityId.of(TOKEN_ID))).accountId(EntityId.of(PAYER)).createdTimestamp(mintTimestamp).deleted(false).metadata(METADATA.getBytes()).modifiedTimestamp(mintTimestamp).build();
    // Verify
    assertThat(nftTransferRepository.count()).isEqualTo(3L);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_1, TOKEN_ID, PAYER, null);
    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);
    assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(expectedNft1, expectedNft2);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) NftId(com.hedera.mirror.common.domain.token.NftId) 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