Search in sources :

Example 51 with TokenCreateTransaction

use of com.hedera.hashgraph.sdk.TokenCreateTransaction 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 52 with TokenCreateTransaction

use of com.hedera.hashgraph.sdk.TokenCreateTransaction 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 53 with TokenCreateTransaction

use of com.hedera.hashgraph.sdk.TokenCreateTransaction 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)

Example 54 with TokenCreateTransaction

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

the class TokenNftTransferIntegrationTest method cannotTransferUnownedNfts.

@Test
@DisplayName("Cannot transfer NFTs you don't own")
void cannotTransferUnownedNfts() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    @Var TransactionResponse response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = response.getReceipt(testEnv.client).accountId;
    assertThat(accountId).isNotNull();
    response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client);
    var tokenId = response.getReceipt(testEnv.client).tokenId;
    assertThat(tokenId).isNotNull();
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).setMetadata(NftMetadataGenerator.generate((byte) 10)).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).signWithOperator(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = new ArrayList<Long>(mintReceipt.serials.subList(0, 4));
    var transfer = new TransferTransaction();
    for (var serial : serialsToTransfer) {
        // Try to transfer in wrong direction
        transfer.addNftTransfer(tokenId.nft(serial), accountId, testEnv.operatorId);
    }
    transfer.freezeWith(testEnv.client).sign(key);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        transfer.execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.SENDER_DOES_NOT_OWN_NFT_SERIAL_NO.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) Var(com.google.errorprone.annotations.Var) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) ArrayList(java.util.ArrayList) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 55 with TokenCreateTransaction

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

the class TokenRevokeKycIntegrationTest method cannotRevokeKycToAccountOnTokenWhenAccountWasNotAssociatedWith.

@Test
@DisplayName("Cannot revoke kyc to account on token when account was not associated with")
void cannotRevokeKycToAccountOnTokenWhenAccountWasNotAssociatedWith() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var tokenId = Objects.requireNonNull(new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).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).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenRevokeKycTransaction().setAccountId(accountId).setTokenId(tokenId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenRevokeKycTransaction(com.hedera.hashgraph.sdk.TokenRevokeKycTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)70 Test (org.junit.jupiter.api.Test)64 DisplayName (org.junit.jupiter.api.DisplayName)61 Hbar (com.hedera.hashgraph.sdk.Hbar)34 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)29 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)21 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)15 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)14 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)11 TokenInfoQuery (com.hedera.hashgraph.sdk.TokenInfoQuery)10 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)8 CustomFixedFee (com.hedera.hashgraph.sdk.CustomFixedFee)7 ArrayList (java.util.ArrayList)7 Var (com.google.errorprone.annotations.Var)6 TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)6 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)5 PublicKey (com.hedera.hashgraph.sdk.PublicKey)5 CustomFractionalFee (com.hedera.hashgraph.sdk.CustomFractionalFee)4 TokenId (com.hedera.hashgraph.sdk.TokenId)4 TokenNftInfoQuery (com.hedera.hashgraph.sdk.TokenNftInfoQuery)4