Search in sources :

Example 11 with TokenMintTransaction

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

the class TokenBurnIntegrationTest method cannotBurnNftsWhenNftIsNotOwned.

@Test
@DisplayName("Cannot burn NFTs when NFT is not owned by treasury")
void cannotBurnNftsWhenNftIsNotOwned() 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).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client);
    var tokenId = Objects.requireNonNull(createReceipt.tokenId);
    var serials = new TokenMintTransaction().setTokenId(tokenId).setMetadata(NftMetadataGenerator.generate((byte) 1)).execute(testEnv.client).getReceipt(testEnv.client).serials;
    var key = PrivateKey.generateED25519();
    var accountId = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).signWithOperator(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addNftTransfer(tokenId.nft(serials.get(0)), testEnv.operatorId, accountId).execute(testEnv.client).getReceipt(testEnv.client);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenBurnTransaction().setSerials(serials).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TREASURY_MUST_OWN_BURNED_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) TokenBurnTransaction(com.hedera.hashgraph.sdk.TokenBurnTransaction) 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 12 with TokenMintTransaction

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

the class TokenMintIntegrationTest method cannotMintTokensWhenAmountIsNotSet.

@Test
@DisplayName("Cannot mint tokens when amount is not set")
void cannotMintTokensWhenAmountIsNotSet() 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);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenMintTransaction().setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_TOKEN_MINT_AMOUNT.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 13 with TokenMintTransaction

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

the class TokenMintIntegrationTest method cannotMintMoreThanMaxSupply.

@Test
@DisplayName("Cannot mint more tokens than max supply")
void cannotMintMoreThanMaxSupply() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var tokenId = Objects.requireNonNull(new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setSupplyType(TokenSupplyType.FINITE).setMaxSupply(5).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenMintTransaction().setTokenId(tokenId).setAmount(6).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TOKEN_MAX_SUPPLY_REACHED.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 14 with TokenMintTransaction

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

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

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