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