Search in sources :

Example 1 with Nft

use of com.hedera.mirror.common.domain.token.Nft 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)

Example 2 with Nft

use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerCryptoTest method cryptoApproveAllowance.

@Test
void cryptoApproveAllowance() {
    // given
    var consensusTimestamp = recordItemBuilder.timestamp();
    List<Nft> expectedNfts = new LinkedList<>();
    var nftAllowances = customizeNftAllowances(consensusTimestamp, expectedNfts);
    RecordItem recordItem = recordItemBuilder.cryptoApproveAllowance().transactionBody(b -> b.clearNftAllowances().addAllNftAllowances(nftAllowances)).record(r -> r.setConsensusTimestamp(consensusTimestamp)).build();
    // when
    parseRecordItemAndCommit(recordItem);
    // then
    assertAllowances(recordItem, expectedNfts);
}
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) Nft(com.hedera.mirror.common.domain.token.Nft) LinkedList(java.util.LinkedList) 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)

Example 3 with Nft

use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onNftTransferOwnershipAndDelete.

@Test
void onNftTransferOwnershipAndDelete() {
    // create token first
    EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
    EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.3", ACCOUNT);
    EntityId treasury = EntityId.of("0.0.98", ACCOUNT);
    String metadata1 = "nft1";
    String metadata2 = "nft2";
    // save token entities first
    Token token1 = getToken(tokenId1, treasury, 1L, 1L);
    sqlEntityListener.onToken(token1);
    // create nfts
    // mint transfer combined
    Nft nft1Combined = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
    // mint transfer combined
    Nft nft2Combined = getNft(tokenId1, 2L, accountId2, 4L, false, metadata2, 4L);
    sqlEntityListener.onNft(nft1Combined);
    sqlEntityListener.onNft(nft2Combined);
    completeFileAndCommit();
    assertEquals(2, nftRepository.count());
    // mint/burn
    Nft nft1Burn = getNft(tokenId1, 1L, EntityId.EMPTY, null, true, null, 5L);
    // mint/burn transfer
    Nft nft1BurnTransfer = getNft(tokenId1, 1L, null, null, null, null, 5L);
    sqlEntityListener.onNft(nft1Burn);
    sqlEntityListener.onNft(nft1BurnTransfer);
    // mint/burn
    Nft nft2Burn = getNft(tokenId1, 2L, EntityId.EMPTY, null, true, null, 6L);
    // mint/burn transfer
    Nft nft2BurnTransfer = getNft(tokenId1, 2L, null, null, null, null, 6L);
    sqlEntityListener.onNft(nft2Burn);
    sqlEntityListener.onNft(nft2BurnTransfer);
    completeFileAndCommit();
    // expected nfts
    // transfer
    Nft nft1 = getNft(tokenId1, 1L, null, 3L, true, metadata1, 5L);
    // transfer
    Nft nft2 = getNft(tokenId1, 2L, null, 4L, true, metadata2, 6L);
    assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Token(com.hedera.mirror.common.domain.token.Token) ByteString(com.google.protobuf.ByteString) Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Nft

use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method getNft.

private Nft getNft(EntityId tokenId, long serialNumber, EntityId accountId, Long createdTimestamp, Boolean deleted, String metadata, long modifiedTimestamp) {
    Nft nft = new Nft();
    nft.setAccountId(accountId);
    nft.setCreatedTimestamp(createdTimestamp);
    nft.setDeleted(deleted);
    nft.setMetadata(metadata == null ? null : metadata.getBytes(StandardCharsets.UTF_8));
    nft.setId(new NftId(serialNumber, tokenId));
    nft.setModifiedTimestamp(modifiedTimestamp);
    return nft;
}
Also used : NftId(com.hedera.mirror.common.domain.token.NftId) Nft(com.hedera.mirror.common.domain.token.Nft)

Example 5 with Nft

use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.

the class NftRepositoryTest method save.

@Test
void save() {
    Nft savedNft = nftRepository.save(nft("0.0.2", 1, 1));
    assertThat(nftRepository.findById(savedNft.getId())).contains(savedNft);
}
Also used : Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test)

Aggregations

Nft (com.hedera.mirror.common.domain.token.Nft)20 EntityId (com.hedera.mirror.common.domain.entity.EntityId)12 Test (org.junit.jupiter.api.Test)12 ByteString (com.google.protobuf.ByteString)8 NftId (com.hedera.mirror.common.domain.token.NftId)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Token (com.hedera.mirror.common.domain.token.Token)5 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)5 Contract (com.hedera.mirror.common.domain.contract.Contract)3 Entity (com.hedera.mirror.common.domain.entity.Entity)3 ContractRepository (com.hedera.mirror.importer.repository.ContractRepository)3 CryptoAllowanceRepository (com.hedera.mirror.importer.repository.CryptoAllowanceRepository)3 NftAllowanceRepository (com.hedera.mirror.importer.repository.NftAllowanceRepository)3 NftRepository (com.hedera.mirror.importer.repository.NftRepository)3 HashMap (java.util.HashMap)3 BoolValue (com.google.protobuf.BoolValue)2 Int32Value (com.google.protobuf.Int32Value)2 StringValue (com.google.protobuf.StringValue)2 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)2 EntityType (com.hedera.mirror.common.domain.entity.EntityType)2