Search in sources :

Example 1 with NftRemoveAllowance

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

the class EntityRecordItemListenerCryptoTest method cryptoDeleteAllowance.

@Test
void cryptoDeleteAllowance() {
    // given
    var delegatingSpender = EntityId.of(recordItemBuilder.accountId());
    var ownerAccountId = EntityId.of(recordItemBuilder.accountId());
    var spender1 = EntityId.of(recordItemBuilder.accountId());
    var spender2 = EntityId.of(recordItemBuilder.accountId());
    var tokenId1 = EntityId.of(recordItemBuilder.tokenId());
    var tokenId2 = EntityId.of(recordItemBuilder.tokenId());
    List<NftRemoveAllowance> nftRemoveAllowances = List.of(NftRemoveAllowance.newBuilder().setOwner(AccountID.newBuilder().setAccountNum(ownerAccountId.getEntityNum())).setTokenId(TokenID.newBuilder().setTokenNum(tokenId1.getEntityNum())).addSerialNumbers(1L).addSerialNumbers(2L).build(), NftRemoveAllowance.newBuilder().setOwner(AccountID.newBuilder().setAccountNum(ownerAccountId.getEntityNum())).setTokenId(TokenID.newBuilder().setTokenNum(tokenId2.getEntityNum())).addSerialNumbers(1L).addSerialNumbers(2L).addSerialNumbers(2L).build());
    RecordItem recordItem = recordItemBuilder.cryptoDeleteAllowance().transactionBody(b -> b.clearNftAllowances().addAllNftAllowances(nftRemoveAllowances)).build();
    var nft1 = Nft.builder().accountId(ownerAccountId).createdTimestamp(10L).deleted(false).id(new NftId(1L, tokenId1)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
    var nft2 = Nft.builder().accountId(ownerAccountId).createdTimestamp(11L).deleted(false).id(new NftId(2L, tokenId1)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
    var nft3 = Nft.builder().accountId(ownerAccountId).createdTimestamp(12L).deleted(false).id(new NftId(1L, tokenId2)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
    var nft4 = Nft.builder().accountId(ownerAccountId).createdTimestamp(13L).deleted(false).id(new NftId(2L, tokenId2)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
    List<Nft> nftsWithAllowance = Stream.of(nft1.toBuilder().delegatingSpender(delegatingSpender).modifiedTimestamp(15L).spender(spender1), nft2.toBuilder().modifiedTimestamp(16L).spender(spender2), nft3.toBuilder().modifiedTimestamp(17L).spender(spender1), nft4.toBuilder().modifiedTimestamp(18L).spender(spender2)).map(Nft.NftBuilder::build).collect(Collectors.toList());
    nftRepository.saveAll(nftsWithAllowance);
    // when
    parseRecordItemAndCommit(recordItem);
    // then
    assertAll(() -> assertEquals(0, entityRepository.count()), () -> assertTransactionAndRecord(recordItem.getTransactionBody(), recordItem.getRecord()), () -> assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2, nft3, nft4));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CryptoAllowanceRepository(com.hedera.mirror.importer.repository.CryptoAllowanceRepository) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) KeyList(com.hederahashgraph.api.proto.java.KeyList) NftAllowanceRepository(com.hedera.mirror.importer.repository.NftAllowanceRepository) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) Collection(java.util.Collection) Resource(javax.annotation.Resource) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) RealmID(com.hederahashgraph.api.proto.java.RealmID) Stream(java.util.stream.Stream) ShardID(com.hederahashgraph.api.proto.java.ShardID) NftRemoveAllowance(com.hederahashgraph.api.proto.java.NftRemoveAllowance) StakingRewardTransfer(com.hedera.mirror.common.domain.transaction.StakingRewardTransfer) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) ErrataType(com.hedera.mirror.common.domain.transaction.ErrataType) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) NftId(com.hedera.mirror.common.domain.token.NftId) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) BoolValue(com.google.protobuf.BoolValue) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) LinkedList(java.util.LinkedList) AccountID(com.hederahashgraph.api.proto.java.AccountID) LiveHash(com.hedera.mirror.common.domain.transaction.LiveHash) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TransferList(com.hederahashgraph.api.proto.java.TransferList) NftRepository(com.hedera.mirror.importer.repository.NftRepository) TokenAllowanceRepository(com.hedera.mirror.importer.repository.TokenAllowanceRepository) Int32Value(com.google.protobuf.Int32Value) IterableAssert(org.assertj.core.api.IterableAssert) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) DisplayName(org.junit.jupiter.api.DisplayName) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) Condition(org.assertj.core.api.Condition) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) NftRemoveAllowance(com.hederahashgraph.api.proto.java.NftRemoveAllowance) NftId(com.hedera.mirror.common.domain.token.NftId) Nft(com.hedera.mirror.common.domain.token.Nft) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BoolValue (com.google.protobuf.BoolValue)1 ByteString (com.google.protobuf.ByteString)1 Int32Value (com.google.protobuf.Int32Value)1 StringValue (com.google.protobuf.StringValue)1 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 Nft (com.hedera.mirror.common.domain.token.Nft)1 NftId (com.hedera.mirror.common.domain.token.NftId)1 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)1 ErrataType (com.hedera.mirror.common.domain.transaction.ErrataType)1 LiveHash (com.hedera.mirror.common.domain.transaction.LiveHash)1 NonFeeTransfer (com.hedera.mirror.common.domain.transaction.NonFeeTransfer)1 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)1 StakingRewardTransfer (com.hedera.mirror.common.domain.transaction.StakingRewardTransfer)1 DomainUtils (com.hedera.mirror.common.util.DomainUtils)1 TestUtils (com.hedera.mirror.importer.TestUtils)1 AliasNotFoundException (com.hedera.mirror.importer.exception.AliasNotFoundException)1 PartialDataAction (com.hedera.mirror.importer.parser.PartialDataAction)1