use of com.hedera.hashgraph.sdk.TokenCreateTransaction in project hedera-sdk-java by hashgraph.
the class TokenCreateIntegrationTest method canCreateTokenWithCustomFees.
@Test
@DisplayName("Can create token with custom fees")
void canCreateTokenWithCustomFees() throws Exception {
var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
var customFees = new ArrayList<CustomFee>();
customFees.add(new CustomFixedFee().setAmount(10).setFeeCollectorAccountId(testEnv.operatorId));
customFees.add(new CustomFractionalFee().setNumerator(1).setDenominator(20).setMin(1).setMax(10).setFeeCollectorAccountId(testEnv.operatorId));
var tokenId = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setCustomFees(customFees).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
testEnv.close(tokenId);
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction in project hedera-sdk-java by hashgraph.
the class TokenDeleteIntegrationTest method cannotDeleteTokenWhenAdminKeyDoesNotSignTransaction.
@Test
@DisplayName("Cannot delete token when admin key does not sign transaction")
void cannotDeleteTokenWhenAdminKeyDoesNotSignTransaction() throws Exception {
var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
var key = PrivateKey.generateED25519();
var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setAdminKey(key).freezeWith(testEnv.client).sign(key).execute(testEnv.client);
var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new TokenDeleteTransaction().setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INVALID_SIGNATURE.toString());
new TokenDeleteTransaction().setTokenId(tokenId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction 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);
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction 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);
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction 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);
}
Aggregations