Search in sources :

Example 1 with TokenMintTransaction

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

the class TokenInfoIntegrationTest method canQueryNfts.

@Test
@DisplayName("Can query NFT")
void canQueryNfts() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setSupplyType(TokenSupplyType.FINITE).setMaxSupply(5000).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).setMetadata(NftMetadataGenerator.generate((byte) 10)).execute(testEnv.client).getReceipt(testEnv.client);
    assertThat(mintReceipt.serials.size()).isEqualTo(10);
    var info = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client);
    assertThat(info.tokenId).isEqualTo(tokenId);
    assertThat(info.name).isEqualTo("ffff");
    assertThat(info.symbol).isEqualTo("F");
    assertThat(info.decimals).isEqualTo(0);
    assertThat(info.totalSupply).isEqualTo(10);
    assertThat(testEnv.operatorId).isEqualTo(info.treasuryAccountId);
    assertThat(info.adminKey).isNotNull();
    assertThat(info.freezeKey).isNull();
    assertThat(info.wipeKey).isNull();
    assertThat(info.kycKey).isNull();
    assertThat(info.supplyKey).isNotNull();
    assertThat(info.defaultFreezeStatus).isNull();
    assertThat(info.defaultKycStatus).isNull();
    assertThat(info.tokenType).isEqualTo(TokenType.NON_FUNGIBLE_UNIQUE);
    assertThat(info.supplyType).isEqualTo(TokenSupplyType.FINITE);
    assertThat(info.maxSupply).isEqualTo(5000);
    testEnv.close(tokenId);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenInfoQuery(com.hedera.hashgraph.sdk.TokenInfoQuery) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with TokenMintTransaction

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

the class TokenMintIntegrationTest method canMintTokens.

@Test
@DisplayName("Can mint tokens")
void canMintTokens() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    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);
    var receipt = new TokenMintTransaction().setAmount(10).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    assertThat(receipt.totalSupply).isEqualTo(1000000 + 10);
    testEnv.close(tokenId);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TokenMintTransaction

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

the class TokenMintIntegrationTest method cannotMintNftsIfMetadataTooBig.

@Test
@DisplayName("Cannot mint NFTs if metadata too big")
void cannotMintNftsIfMetadataTooBig() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    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);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenMintTransaction().setMetadata(NftMetadataGenerator.generateOneLarge()).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.METADATA_TOO_LONG.toString());
    testEnv.close(tokenId);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TokenMintTransaction

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

the class TokenMintIntegrationTest method cannotMintTokensWhenSupplyKeyDoesNotSignTransaction.

@Test
@DisplayName("Cannot mint tokens when supply key does not sign transaction")
void cannotMintTokensWhenSupplyKeyDoesNotSignTransaction() 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(key).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenMintTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_SIGNATURE.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) 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)

Example 5 with TokenMintTransaction

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

the class TokenNftTransferIntegrationTest method canTransferNfts.

@Test
@DisplayName("Can transfer NFTs")
void canTransferNfts() 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).setKycKey(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);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = new ArrayList<Long>(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 : 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) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) 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)

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