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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations