Search in sources :

Example 16 with Nft

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

the class BatchUpserterTest method tokenDissociateTransfer.

@Test
void tokenDissociateTransfer() {
    // given
    EntityId accountId = EntityId.of("0.0.215", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.216", ACCOUNT);
    Token nftClass1 = getDeletedNftClass(10L, 25L, EntityId.of("0.0.100", TOKEN));
    Token nftClass2 = getDeletedNftClass(11L, 24L, EntityId.of("0.0.101", TOKEN));
    EntityId tokenId1 = nftClass1.getTokenId().getTokenId();
    // already deleted, result of wipe
    Nft nft1 = getNft(tokenId1, accountId, 1L, 11L, 16L, true);
    Nft nft2 = getNft(tokenId1, accountId, 2L, 11L, 11L, false);
    Nft nft3 = getNft(tokenId1, accountId, 3L, 12L, 12L, false);
    // different account
    Nft nft4 = getNft(tokenId1, accountId2, 4L, 18L, 18L, false);
    Nft nft5 = getNft(nftClass2.getTokenId().getTokenId(), accountId, 1L, 15L, 15L, false);
    nftRepository.saveAll(List.of(nft1, nft2, nft3, nft4, nft5));
    tokenRepository.saveAll(List.of(nftClass1, nftClass2));
    long consensusTimestamp = 30L;
    EntityId ftId = EntityId.of("0.0.217", TOKEN);
    EntityId payerId = EntityId.of("0.0.2002", ACCOUNT);
    TokenTransfer fungibleTokenTransfer = domainBuilder.tokenTransfer().customize(t -> t.amount(-10).id(new TokenTransfer.Id(consensusTimestamp, ftId, accountId)).isApproval(false).payerAccountId(payerId).tokenDissociate(true)).get();
    TokenTransfer nonFungibleTokenTransfer = domainBuilder.tokenTransfer().customize(t -> t.amount(-2).id(new TokenTransfer.Id(consensusTimestamp, tokenId1, accountId)).isApproval(false).payerAccountId(payerId).tokenDissociate(true)).get();
    List<TokenTransfer> tokenTransfers = List.of(fungibleTokenTransfer, nonFungibleTokenTransfer);
    // when
    persist(tokenDissociateTransferBatchUpserter, tokenTransfers);
    // then
    assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, getNft(tokenId1, accountId, 2L, 11L, 30L, true), getNft(tokenId1, accountId, 3L, 12L, 30L, true), nft4, nft5);
    NftTransfer serial2Transfer = getNftTransfer(tokenId1, accountId, 2L, consensusTimestamp);
    serial2Transfer.setPayerAccountId(payerId);
    NftTransfer serial3Transfer = getNftTransfer(tokenId1, accountId, 3L, consensusTimestamp);
    serial3Transfer.setPayerAccountId(payerId);
    assertThat(nftTransferRepository.findAll()).containsExactlyInAnyOrder(serial2Transfer, serial3Transfer);
    assertThat(tokenTransferRepository.findAll()).usingElementComparatorIgnoringFields("tokenDissociate").containsOnly(fungibleTokenTransfer);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) CryptoAllowanceRepository(com.hedera.mirror.importer.repository.CryptoAllowanceRepository) SneakyThrows(lombok.SneakyThrows) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScheduleRepository(com.hedera.mirror.importer.repository.ScheduleRepository) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) TokenSupplyTypeEnum(com.hedera.mirror.common.domain.token.TokenSupplyTypeEnum) NftAllowanceRepository(com.hedera.mirror.importer.repository.NftAllowanceRepository) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) TokenRepository(com.hedera.mirror.importer.repository.TokenRepository) TokenFreezeStatusEnum(com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum) Collection(java.util.Collection) TOKEN_DISSOCIATE_BATCH_PERSISTER(com.hedera.mirror.importer.config.MirrorImporterConfiguration.TOKEN_DISSOCIATE_BATCH_PERSISTER) Resource(javax.annotation.Resource) CryptoAllowance(com.hedera.mirror.common.domain.entity.CryptoAllowance) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) StandardCharsets(java.nio.charset.StandardCharsets) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) EntityRepository(com.hedera.mirror.importer.repository.EntityRepository) TransactionOperations(org.springframework.transaction.support.TransactionOperations) TokenAccountRepository(com.hedera.mirror.importer.repository.TokenAccountRepository) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) Schedule(com.hedera.mirror.common.domain.schedule.Schedule) TokenTypeEnum(com.hedera.mirror.common.domain.token.TokenTypeEnum) NftId(com.hedera.mirror.common.domain.token.NftId) Contract(com.hedera.mirror.common.domain.contract.Contract) Hex(org.apache.commons.codec.binary.Hex) ArrayList(java.util.ArrayList) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) NftTransferRepository(com.hedera.mirror.importer.repository.NftTransferRepository) NftRepository(com.hedera.mirror.importer.repository.NftRepository) TokenAllowanceRepository(com.hedera.mirror.importer.repository.TokenAllowanceRepository) Tuple(org.assertj.core.groups.Tuple) TokenTransferRepository(com.hedera.mirror.importer.repository.TokenTransferRepository) Entity(com.hedera.mirror.common.domain.entity.Entity) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) Key(com.hederahashgraph.api.proto.java.Key) TokenKycStatusEnum(com.hedera.mirror.common.domain.token.TokenKycStatusEnum) TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) Token(com.hedera.mirror.common.domain.token.Token) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenId(com.hedera.mirror.common.domain.token.TokenId) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) NftId(com.hedera.mirror.common.domain.token.NftId) Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 17 with Nft

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

the class SqlEntityListenerTest method onNftDomainTransfer.

@Test
void onNftDomainTransfer() {
    // create token first
    EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
    EntityId tokenId2 = EntityId.of("0.0.3", TOKEN);
    EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.4", ACCOUNT);
    EntityId treasuryId = EntityId.of("0.0.98", ACCOUNT);
    EntityId accountId3 = EntityId.of("0.0.5", ACCOUNT);
    EntityId accountId4 = EntityId.of("0.0.6", ACCOUNT);
    String metadata1 = "nft1";
    String metadata2 = "nft2";
    // save token entities first
    Token token1 = getToken(tokenId1, treasuryId, 1L, 1L);
    Token token2 = getToken(tokenId2, treasuryId, 2L, 2L);
    sqlEntityListener.onToken(token1);
    sqlEntityListener.onToken(token2);
    // create nfts
    // mint transfer combined
    Nft nft1Combined = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
    // mint transfer combined
    Nft nft2Combined = getNft(tokenId2, 1L, accountId2, 4L, false, metadata2, 4L);
    sqlEntityListener.onNft(nft1Combined);
    sqlEntityListener.onNft(nft2Combined);
    completeFileAndCommit();
    assertEquals(2, nftRepository.count());
    // nft w transfers
    // transfer
    sqlEntityListener.onNft(getNft(tokenId1, 1L, accountId3, null, null, null, 5L));
    // transfer
    sqlEntityListener.onNft(getNft(tokenId2, 1L, accountId4, null, null, null, 6L));
    completeFileAndCommit();
    // transfer
    Nft nft1 = getNft(tokenId1, 1L, accountId3, 3L, false, metadata1, 5L);
    // transfer
    Nft nft2 = getNft(tokenId2, 1L, accountId4, 4L, false, 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 18 with Nft

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

the class SqlEntityListenerTest method onNftTransferOwnershipAndDeleteOutOfOrder.

@Test
void onNftTransferOwnershipAndDeleteOutOfOrder() {
    // 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);
    completeFileAndCommit();
    // 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);
    // nft 1 burn w transfer coming first
    // 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(nft1BurnTransfer);
    sqlEntityListener.onNft(nft1Burn);
    // nft 2 burn w transfer coming first
    // 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(nft2BurnTransfer);
    sqlEntityListener.onNft(nft2Burn);
    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 19 with Nft

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

the class SqlEntityListenerTest method onNft.

@Test
void onNft() {
    // create token first
    EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
    EntityId tokenId2 = EntityId.of("0.0.3", TOKEN);
    EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.4", ACCOUNT);
    EntityId treasuryId = EntityId.of("0.0.98", ACCOUNT);
    String metadata1 = "nft1";
    String metadata2 = "nft2";
    Token token1 = getToken(tokenId1, treasuryId, 1L, 1L);
    Token token2 = getToken(tokenId2, treasuryId, 2L, 2L);
    sqlEntityListener.onToken(token1);
    sqlEntityListener.onToken(token2);
    completeFileAndCommit();
    // create nft 1
    // mint
    sqlEntityListener.onNft(getNft(tokenId1, 1L, null, 3L, false, metadata1, 3L));
    // transfer
    sqlEntityListener.onNft(getNft(tokenId1, 1L, accountId1, null, null, null, 3L));
    // create nft 2
    // mint
    sqlEntityListener.onNft(getNft(tokenId2, 1L, null, 4L, false, metadata2, 4L));
    // transfer
    sqlEntityListener.onNft(getNft(tokenId2, 1L, accountId2, null, null, null, 4L));
    completeFileAndCommit();
    // transfer
    Nft nft1 = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
    // transfer
    Nft nft2 = getNft(tokenId2, 1L, accountId2, 4L, false, metadata2, 4L);
    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 20 with Nft

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

the class SqlEntityListenerTest method onNftMintOutOfOrder.

@Test
void onNftMintOutOfOrder() {
    // create token first
    EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
    EntityId tokenId2 = EntityId.of("0.0.3", TOKEN);
    EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.4", ACCOUNT);
    EntityId treasuryId = EntityId.of("0.0.98", ACCOUNT);
    String metadata1 = "nft1";
    String metadata2 = "nft2";
    // save token entities first
    Token token1 = getToken(tokenId1, treasuryId, 1L, 1L);
    Token token2 = getToken(tokenId2, treasuryId, 2L, 2L);
    sqlEntityListener.onToken(token1);
    sqlEntityListener.onToken(token2);
    // create nft 1 w transfer coming first
    // transfer
    sqlEntityListener.onNft(getNft(tokenId1, 1L, accountId1, null, null, null, 3L));
    // mint
    sqlEntityListener.onNft(getNft(tokenId1, 1L, null, 3L, false, metadata1, 3L));
    // create nft 2 w transfer coming first
    // transfer
    sqlEntityListener.onNft(getNft(tokenId2, 1L, accountId2, null, null, null, 4L));
    // mint
    sqlEntityListener.onNft(getNft(tokenId2, 1L, null, 4L, false, metadata2, 4L));
    completeFileAndCommit();
    // transfer
    Nft nft1 = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
    // transfer
    Nft nft2 = getNft(tokenId2, 1L, accountId2, 4L, false, metadata2, 4L);
    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)

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