Search in sources :

Example 11 with NftId

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

the class EntityRecordItemListenerTokenTest method tokenWipeNft.

@Test
void tokenWipeNft() {
    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 mintTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, SERIAL_NUMBER_LIST);
    insertAndParseTransaction(mintTimestamp, mintTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(2L).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 wipeTimestamp = 15L;
    TokenTransferList wipeTransfer = nftTransfer(TOKEN_ID, DEFAULT_ACCOUNT_ID, PAYER, List.of(SERIAL_NUMBER_1));
    Transaction transaction = tokenWipeTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, 0, List.of(SERIAL_NUMBER_1));
    insertAndParseTransaction(wipeTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(1L);
        builder.addTokenTransferLists(wipeTransfer);
    });
    expectedNft1.setAccountId(null);
    expectedNft1.setDeleted(true);
    expectedNft1.setModifiedTimestamp(wipeTimestamp);
    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(wipeTimestamp, SERIAL_NUMBER_1, TOKEN_ID, null, PAYER);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, wipeTimestamp, SYMBOL, 1);
    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)

Example 12 with NftId

use of com.hedera.mirror.common.domain.token.NftId 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

NftId (com.hedera.mirror.common.domain.token.NftId)12 Test (org.junit.jupiter.api.Test)6 Nft (com.hedera.mirror.common.domain.token.Nft)4 Transaction (com.hederahashgraph.api.proto.java.Transaction)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)2 NftAllowance (com.hederahashgraph.api.proto.java.NftAllowance)2 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)2 LinkedList (java.util.LinkedList)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 BoolValue (com.google.protobuf.BoolValue)1 ByteString (com.google.protobuf.ByteString)1 Int32Value (com.google.protobuf.Int32Value)1 StringValue (com.google.protobuf.StringValue)1 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)1 ErrataType (com.hedera.mirror.common.domain.transaction.ErrataType)1 LiveHash (com.hedera.mirror.common.domain.transaction.LiveHash)1