Search in sources :

Example 6 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.

the class HapiCryptoTransfer method fullyAggregateTokenTransfersList.

private Map<TokenID, Pair<Integer, List<AccountAmount>>> fullyAggregateTokenTransfersList(final HapiApiSpec spec) {
    Map<TokenID, Pair<Integer, List<AccountAmount>>> map = new HashMap<>();
    for (TokenMovement xfer : tokenAwareProviders) {
        if (xfer.isFungibleToken()) {
            var list = xfer.specializedFor(spec);
            if (map.containsKey(list.getToken())) {
                var existingVal = map.get(list.getToken());
                List<AccountAmount> newList = Stream.of(existingVal.getRight(), list.getTransfersList()).flatMap(Collection::stream).collect(Collectors.toList());
                map.put(list.getToken(), Pair.of(existingVal.getLeft(), aggregateTransfers(newList)));
            } else {
                map.put(list.getToken(), Pair.of(list.getExpectedDecimals().getValue(), aggregateTransfers(list.getTransfersList())));
            }
        }
    }
    return map;
}
Also used : TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TokenID(com.hederahashgraph.api.proto.java.TokenID) Pair(org.apache.commons.lang3.tuple.Pair) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 7 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID 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 8 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionHandlerTest method updateTransactionWithAliasNotFoundAndPartialDataActionSkip.

@Test
void updateTransactionWithAliasNotFoundAndPartialDataActionSkip() {
    recordParserProperties.setPartialDataAction(PartialDataAction.SKIP);
    var alias = DomainUtils.fromBytes(domainBuilder.key());
    var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
    var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
    when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
    transactionHandler.updateTransaction(transaction, recordItem);
    assertTokenUpdate(timestamp, tokenId, Assertions::assertNull);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) DomainUtils(com.hedera.mirror.common.util.DomainUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.when(org.mockito.Mockito.when) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) Assertions(org.junit.jupiter.api.Assertions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionHandlerTest method updateTransactionThrowsWithAliasNotFound.

@ParameterizedTest(name = "{0}")
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "ERROR" })
void updateTransactionThrowsWithAliasNotFound(PartialDataAction partialDataAction) {
    // given
    recordParserProperties.setPartialDataAction(partialDataAction);
    var alias = DomainUtils.fromBytes(domainBuilder.key());
    var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
    var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
    when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
    // when, then
    assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) DomainUtils(com.hedera.mirror.common.util.DomainUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.when(org.mockito.Mockito.when) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionHandlerTest method updateTreasury.

@Test
void updateTreasury() {
    AbstractEntity entity = getExpectedUpdatedEntity();
    AccountID previousAccountId = AccountID.newBuilder().setAccountNum(1L).build();
    AccountID newAccountId = AccountID.newBuilder().setAccountNum(2L).build();
    TokenID tokenID = TokenID.newBuilder().setTokenNum(3L).build();
    long consensusTimestamp = DomainUtils.timestampInNanosMax(MODIFIED_TIMESTAMP);
    TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(tokenID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(newAccountId).setSenderAccountID(previousAccountId).setSerialNumber(NftTransferId.WILDCARD_SERIAL_NUMBER).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);
    TransactionBody body = recordItem.getTransactionBody();
    var payerAccount = EntityId.of(body.getTransactionID().getAccountID()).toEntity().getId();
    verify(nftRepository).updateTreasury(tokenID.getTokenNum(), previousAccountId.getAccountNum(), newAccountId.getAccountNum(), consensusTimestamp, payerAccount, false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) TokenID(com.hederahashgraph.api.proto.java.TokenID) 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

TokenID (com.hederahashgraph.api.proto.java.TokenID)24 AccountID (com.hederahashgraph.api.proto.java.AccountID)11 Test (org.junit.jupiter.api.Test)9 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)5 TokenUpdateTransactionBody (com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)5 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)5 ByteString (com.google.protobuf.ByteString)4 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 Range (com.google.common.collect.Range)3 Entity (com.hedera.mirror.common.domain.entity.Entity)3 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)3 EntityType (com.hedera.mirror.common.domain.entity.EntityType)3 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)3 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)3