Search in sources :

Example 11 with TokenTransferList

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);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hederahashgraph.api.proto.java.Transaction) TokenID(com.hederahashgraph.api.proto.java.TokenID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with TokenTransferList

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();
}
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 13 with TokenTransferList

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);
}
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 14 with TokenTransferList

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);
}
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 15 with TokenTransferList

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);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) 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