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);
}
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);
}
Aggregations