Search in sources :

Example 11 with Nft

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

the class BatchUpserterTest method getNft.

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

Example 12 with Nft

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

the class NftRepositoryTest method updateAccountId.

@Test
void updateAccountId() {
    Nft savedNft = nftRepository.save(nft("0.0.3", 2, 2));
    EntityId accountId = EntityId.of("0.0.10", EntityType.ACCOUNT);
    nftRepository.transferNftOwnership(savedNft.getId(), accountId, 3L);
    savedNft.setAccountId(accountId);
    savedNft.setModifiedTimestamp(3L);
    assertThat(nftRepository.findById(savedNft.getId())).contains(savedNft);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test)

Example 13 with Nft

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

the class NftRepositoryTest method updateTreasury.

@Test
void updateTreasury() {
    long consensusTimestamp = 6L;
    EntityId newAccountId = EntityId.of("0.0.2", EntityType.ACCOUNT);
    Nft nft1 = nft("0.0.100", 1, 1);
    Nft nft2 = nft("0.0.100", 2, 2);
    Nft nft3 = nft("0.0.100", 3, 3);
    // Not updated since wrong token
    Nft nft4 = nft("0.0.101", 1, 4);
    // Not updated since wrong account
    Nft nft5 = nft("0.0.100", 4, 5);
    nft5.setAccountId(newAccountId);
    nftRepository.saveAll(List.of(nft1, nft2, nft3, nft4, nft5));
    EntityId tokenId = nft1.getId().getTokenId();
    EntityId previousAccountId = nft1.getAccountId();
    nftRepository.updateTreasury(tokenId.getId(), previousAccountId.getId(), newAccountId.getId(), consensusTimestamp, EntityId.of("0.0.200", EntityType.ACCOUNT).getId(), false);
    assertAccountUpdated(nft1, newAccountId);
    assertAccountUpdated(nft2, newAccountId);
    assertAccountUpdated(nft3, newAccountId);
    assertThat(nftRepository.findById(nft4.getId())).get().isEqualTo(nft4);
    assertThat(nftRepository.findById(nft5.getId())).get().isEqualTo(nft5);
    IterableAssert<NftTransfer> nftTransfers = assertThat(nftTransferRepository.findAll()).hasSize(3);
    nftTransfers.extracting(NftTransfer::getReceiverAccountId).containsOnly(newAccountId);
    nftTransfers.extracting(NftTransfer::getSenderAccountId).containsOnly(previousAccountId);
    nftTransfers.extracting(n -> n.getId().getTokenId()).containsOnly(tokenId);
    nftTransfers.extracting(n -> n.getId().getConsensusTimestamp()).containsOnly(consensusTimestamp);
    nftTransfers.extracting(n -> n.getId().getSerialNumber()).containsExactlyInAnyOrder(1L, 2L, 3L);
    nftTransfers.extracting(NftTransfer::getIsApproval).containsExactlyInAnyOrder(false, false, false);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Test(org.junit.jupiter.api.Test) NftId(com.hedera.mirror.common.domain.token.NftId) IterableAssert(org.assertj.core.api.IterableAssert) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) Resource(javax.annotation.Resource) AbstractObjectAssert(org.assertj.core.api.AbstractObjectAssert) EntityType(com.hedera.mirror.common.domain.entity.EntityType) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test)

Example 14 with Nft

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

the class EntityRecordItemListener method transferNftOwnership.

private void transferNftOwnership(long modifiedTimeStamp, long serialNumber, EntityId tokenId, EntityId receiverId) {
    Nft nft = new Nft(serialNumber, tokenId);
    nft.setAccountId(receiverId);
    nft.setModifiedTimestamp(modifiedTimeStamp);
    entityListener.onNft(nft);
}
Also used : Nft(com.hedera.mirror.common.domain.token.Nft)

Example 15 with Nft

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

the class SupportDeletedTokenDissociateMigrationTest method nft.

private Nft nft(EntityId accountId, long createdTimestamp, boolean deleted, long modifiedTimestamp, long serialNumber, EntityId tokenId) {
    Nft nft = new Nft(serialNumber, tokenId);
    nft.setAccountId(accountId);
    nft.setCreatedTimestamp(createdTimestamp);
    nft.setDeleted(deleted);
    nft.setMetadata(new byte[] { 1 });
    nft.setModifiedTimestamp(modifiedTimestamp);
    return nft;
}
Also used : Nft(com.hedera.mirror.common.domain.token.Nft)

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