use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method tokenTransfersMustHaveCorrectIsApprovalValue.
@Test
void tokenTransfersMustHaveCorrectIsApprovalValue() {
// given
createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
TokenID tokenId2 = TokenID.newBuilder().setTokenNum(7).build();
createTokenEntity(tokenId2, FUNGIBLE_COMMON, "MIRROR", 10L, false, false, false);
AccountID accountId = AccountID.newBuilder().setAccountNum(1).build();
TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(-1000).build()).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER2).setAmount(-100).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(1000).build()).build();
TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(tokenId2).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(333).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(-333).build()).build();
List<TokenTransferList> transferLists = List.of(transferList1, transferList2);
// when
Transaction transaction = buildTransaction(builder -> {
TokenTransferList bodyTransferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(-600).setIsApproval(true).build()).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER2).setAmount(-100).setIsApproval(true).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(-333).build()).build();
builder.getCryptoTransferBuilder().addTokenTransfers(bodyTransferList1);
});
insertAndParseTransaction(TRANSFER_TIMESTAMP, transaction, builder -> {
builder.addAllTokenTransferLists(transferLists);
});
// then
assertTokenTransferInRepository(TOKEN_ID, PAYER, TRANSFER_TIMESTAMP, -1000, true);
assertTokenTransferInRepository(TOKEN_ID, PAYER2, TRANSFER_TIMESTAMP, -100, true);
assertTokenTransferInRepository(TOKEN_ID, accountId, TRANSFER_TIMESTAMP, 1000);
assertTokenTransferInRepository(tokenId2, PAYER, TRANSFER_TIMESTAMP, 333);
assertTokenTransferInRepository(tokenId2, accountId, TRANSFER_TIMESTAMP, -333);
}
use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method tokenDissociateDeletedNonFungibleToken.
@Test
void tokenDissociateDeletedNonFungibleToken() {
// given
createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
// mint
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);
});
// transfer
long transferTimestamp = 15L;
TokenTransferList nftTransfer = nftTransfer(TOKEN_ID, PAYER2, PAYER, List.of(1L));
insertAndParseTransaction(transferTimestamp, tokenTransferTransaction(), builder -> builder.addTokenTransferLists(nftTransfer));
// delete
long tokenDeleteTimestamp = 20L;
Transaction deleteTransaction = tokenDeleteTransaction(TOKEN_ID);
insertAndParseTransaction(tokenDeleteTimestamp, deleteTransaction);
// when
// dissociate
Transaction dissociateTransaction = tokenDissociate(List.of(TOKEN_ID), PAYER2);
long dissociateTimeStamp = 25L;
TokenTransferList dissociateTransfer = tokenTransfer(TOKEN_ID, PAYER2, -1);
insertAndParseTransaction(dissociateTimeStamp, dissociateTransaction, builder -> builder.addTokenTransferLists(dissociateTransfer));
// then
assertNftInRepository(TOKEN_ID, 1L, true, mintTimestamp, dissociateTimeStamp, PAYER2, true);
assertNftInRepository(TOKEN_ID, 2L, true, mintTimestamp, mintTimestamp, PAYER, false);
assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, dissociateTimeStamp, SYMBOL, 1);
assertThat(nftTransferRepository.findAll()).containsExactlyInAnyOrder(domainNftTransfer(mintTimestamp, PAYER, DEFAULT_ACCOUNT_ID, 1L, TOKEN_ID, PAYER), domainNftTransfer(mintTimestamp, PAYER, DEFAULT_ACCOUNT_ID, 2L, TOKEN_ID, PAYER), domainNftTransfer(transferTimestamp, PAYER2, PAYER, 1L, TOKEN_ID, PAYER), domainNftTransfer(dissociateTimeStamp, DEFAULT_ACCOUNT_ID, PAYER2, 1L, TOKEN_ID, PAYER));
assertThat(tokenTransferRepository.findAll()).isEmpty();
}
use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method tokenMint.
@Test
void tokenMint() {
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, true, amount, null);
insertAndParseTransaction(mintTimestamp, transaction, builder -> {
builder.getReceiptBuilder().setNewTotalSupply(INITIAL_SUPPLY + amount);
builder.addTokenTransferLists(tokenTransfer);
});
// 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);
}
use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method tokenBurn.
@Test
void tokenBurn() {
// given
createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
long amount = -1000;
long burnTimestamp = 10L;
TokenTransferList tokenTransfer = tokenTransfer(TOKEN_ID, PAYER, amount);
Transaction transaction = tokenSupplyTransaction(TOKEN_ID, FUNGIBLE_COMMON, false, amount, null);
// when
insertAndParseTransaction(burnTimestamp, transaction, builder -> {
builder.getReceiptBuilder().setNewTotalSupply(INITIAL_SUPPLY - amount);
builder.addTokenTransferLists(tokenTransfer);
});
// then
assertThat(tokenTransferRepository.count()).isEqualTo(2L);
assertTokenTransferInRepository(TOKEN_ID, PAYER, CREATE_TIMESTAMP, INITIAL_SUPPLY);
assertTokenTransferInRepository(TOKEN_ID, PAYER, burnTimestamp, amount);
assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, burnTimestamp, SYMBOL, INITIAL_SUPPLY - amount);
}
use of com.hederahashgraph.api.proto.java.TokenTransferList in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method noTreasuryUpdate.
@Test
void noTreasuryUpdate() {
AbstractEntity entity = getExpectedUpdatedEntity();
TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(TokenID.newBuilder().setTokenNum(3L).build()).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(AccountID.newBuilder().setAccountNum(2L).build()).setSenderAccountID(AccountID.newBuilder().setAccountNum(1L).build()).setSerialNumber(// Not wildcard
1L).build()).build();
TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
Transaction transaction = new Transaction();
transaction.setEntityId(entity.toEntityId());
transactionHandler.updateTransaction(transaction, recordItem);
Mockito.verifyNoInteractions(nftRepository);
}
Aggregations