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));
}
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);
}
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);
}
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;
}
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);
}
Aggregations