Search in sources :

Example 1 with TokenNftInfoQuery

use of com.hedera.hashgraph.sdk.TokenNftInfoQuery in project hedera-sdk-java by hashgraph.

the class TokenNftInfoIntegrationTest method cannotQueryNftInfoByInvalidNftId.

@Test
@DisplayName("Cannot query NFT info by invalid NftId")
void cannotQueryNftInfoByInvalidNftId() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var createReceipt = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client);
    var tokenId = Objects.requireNonNull(createReceipt.tokenId);
    byte[] metadata = { 50 };
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).addMetadata(metadata).execute(testEnv.client).getReceipt(testEnv.client);
    var nftId = tokenId.nft(mintReceipt.serials.get(0));
    var invalidNftId = new NftId(nftId.tokenId, nftId.serial + 1);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenNftInfoQuery().setNftId(invalidNftId).execute(testEnv.client);
    }).withMessageContaining(Status.INVALID_NFT_ID.toString());
    testEnv.close(tokenId);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenNftInfoQuery(com.hedera.hashgraph.sdk.TokenNftInfoQuery) NftId(com.hedera.hashgraph.sdk.NftId) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with TokenNftInfoQuery

use of com.hedera.hashgraph.sdk.TokenNftInfoQuery in project hedera-sdk-java by hashgraph.

the class TokenNftInfoIntegrationTest method cannotQueryNftInfoByInvalidSerialNumber.

@Test
@DisplayName("Cannot query NFT info by invalid NftId Serial Number")
void cannotQueryNftInfoByInvalidSerialNumber() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var createReceipt = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client);
    var tokenId = Objects.requireNonNull(createReceipt.tokenId);
    byte[] metadata = { 50 };
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).addMetadata(metadata).execute(testEnv.client).getReceipt(testEnv.client);
    var nftId = tokenId.nft(mintReceipt.serials.get(0));
    var invalidNftId = new NftId(nftId.tokenId, -1L);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenNftInfoQuery().byNftId(invalidNftId).execute(testEnv.client);
    }).withMessageContaining(Status.INVALID_TOKEN_NFT_SERIAL_NUMBER.toString());
    testEnv.close(tokenId);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenNftInfoQuery(com.hedera.hashgraph.sdk.TokenNftInfoQuery) NftId(com.hedera.hashgraph.sdk.NftId) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TokenNftInfoQuery

use of com.hedera.hashgraph.sdk.TokenNftInfoQuery in project hedera-sdk-java by hashgraph.

the class TokenNftInfoIntegrationTest method canQueryNftInfoByAccountId.

@Disabled
@Test
@DisplayName("Can query NFT info by AccountId")
void canQueryNftInfoByAccountId() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var createReceipt = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client);
    var tokenId = Objects.requireNonNull(createReceipt.tokenId);
    List<byte[]> metadatas = NftMetadataGenerator.generate((byte) 10);
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).setMetadata(metadatas).execute(testEnv.client).getReceipt(testEnv.client);
    var nftInfos = new TokenNftInfoQuery().byAccountId(testEnv.operatorId).setEnd(10).execute(testEnv.client);
    assertThat(nftInfos.size()).isEqualTo(10);
    var serials = new ArrayList<Long>(mintReceipt.serials);
    for (var info : nftInfos) {
        assertThat(info.nftId.tokenId).isEqualTo(tokenId);
        assertThat(serials.remove(info.nftId.serial)).isTrue();
        assertThat(info.accountId).isEqualTo(testEnv.operatorId);
    }
    testEnv.close(tokenId);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) ArrayList(java.util.ArrayList) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenNftInfoQuery(com.hedera.hashgraph.sdk.TokenNftInfoQuery) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with TokenNftInfoQuery

use of com.hedera.hashgraph.sdk.TokenNftInfoQuery in project hedera-sdk-java by hashgraph.

the class TokenNftInfoIntegrationTest method canQueryNftInfoByTokenId.

@Disabled
@Test
@DisplayName("Can query NFT info by TokenId")
void canQueryNftInfoByTokenId() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var createReceipt = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client);
    var tokenId = Objects.requireNonNull(createReceipt.tokenId);
    List<byte[]> metadatas = NftMetadataGenerator.generate((byte) 10);
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).setMetadata(metadatas).execute(testEnv.client).getReceipt(testEnv.client);
    var nftInfos = new TokenNftInfoQuery().byTokenId(tokenId).setEnd(10).execute(testEnv.client);
    assertThat(nftInfos.size()).isEqualTo(10);
    var serials = new ArrayList<Long>(mintReceipt.serials);
    for (var info : nftInfos) {
        assertThat(info.nftId.tokenId).isEqualTo(tokenId);
        assertThat(serials.remove(info.nftId.serial)).isTrue();
        assertThat(info.accountId).isEqualTo(testEnv.operatorId);
    }
    testEnv.close(tokenId);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) ArrayList(java.util.ArrayList) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenNftInfoQuery(com.hedera.hashgraph.sdk.TokenNftInfoQuery) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)4 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)4 TokenNftInfoQuery (com.hedera.hashgraph.sdk.TokenNftInfoQuery)4 DisplayName (org.junit.jupiter.api.DisplayName)4 Test (org.junit.jupiter.api.Test)4 NftId (com.hedera.hashgraph.sdk.NftId)2 ArrayList (java.util.ArrayList)2 Disabled (org.junit.jupiter.api.Disabled)2