Search in sources :

Example 16 with TokenMintTransaction

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

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

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

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

the class TokenWipeIntegrationTest method canWipeAccountsNfts.

@Test
@DisplayName("Can wipe accounts NFTs")
void canWipeAccountsNfts() 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").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).tokenId);
    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).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = mintReceipt.serials.subList(0, 4);
    var transfer = new TransferTransaction();
    for (var serial : serialsToTransfer) {
        transfer.addNftTransfer(tokenId.nft(serial), testEnv.operatorId, accountId);
    }
    transfer.execute(testEnv.client).getReceipt(testEnv.client);
    new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setSerials(serialsToTransfer).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 20 with TokenMintTransaction

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

the class TokenWipeIntegrationTest method cannotWipeAccountsNftsIfNotOwned.

@Test
@DisplayName("Cannot wipe accounts NFTs if the account doesn't own them")
void cannotWipeAccountsNftsIfNotOwned() 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").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).tokenId);
    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).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = mintReceipt.serials.subList(0, 4);
    // don't transfer them
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setSerials(serialsToTransfer).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.ACCOUNT_DOES_NOT_OWN_WIPED_NFT.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)20 Test (org.junit.jupiter.api.Test)19 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)15 DisplayName (org.junit.jupiter.api.DisplayName)15 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)6 Hbar (com.hedera.hashgraph.sdk.Hbar)6 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)5 TokenNftInfoQuery (com.hedera.hashgraph.sdk.TokenNftInfoQuery)4 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)4 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)4 ArrayList (java.util.ArrayList)4 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)3 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)3 Var (com.google.errorprone.annotations.Var)2 NftId (com.hedera.hashgraph.sdk.NftId)2 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)2 Disabled (org.junit.jupiter.api.Disabled)2 TokenBurnTransaction (com.hedera.hashgraph.sdk.TokenBurnTransaction)1 TokenInfoQuery (com.hedera.hashgraph.sdk.TokenInfoQuery)1 TokenType (com.hedera.hashgraph.sdk.TokenType)1