Search in sources :

Example 61 with TokenCreateTransaction

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

the class TokenGrantKycIntegrationTest method canGrantKycAccountWithToken.

@Test
@DisplayName("Can grant kyc to account with token")
void canGrantKycAccountWithToken() 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(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    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).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 62 with TokenCreateTransaction

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

the class TokenGrantKycIntegrationTest method cannotGrantKycToAccountOnTokenWhenAccountWasNotAssociatedWith.

@Test
@DisplayName("Cannot grant kyc to account on token when account was not associated with")
void cannotGrantKycToAccountOnTokenWhenAccountWasNotAssociatedWith() 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(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 63 with TokenCreateTransaction

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

the class TokenInfoIntegrationTest method getCostBigMaxQueryTokenInfo.

@Test
@DisplayName("Get cost of token info query, with big max")
void getCostBigMaxQueryTokenInfo() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    var infoQuery = new TokenInfoQuery().setTokenId(tokenId).setMaxQueryPayment(new Hbar(1000));
    var cost = infoQuery.getCost(testEnv.client);
    infoQuery.setQueryPayment(cost).execute(testEnv.client);
    testEnv.close(tokenId);
}
Also used : TokenInfoQuery(com.hedera.hashgraph.sdk.TokenInfoQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 64 with TokenCreateTransaction

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

the class TokenInfoIntegrationTest method getCostQueryTokenInfo.

@Test
@DisplayName("Get cost of token info query")
void getCostQueryTokenInfo() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    var infoQuery = new TokenInfoQuery().setTokenId(tokenId);
    var cost = infoQuery.getCost(testEnv.client);
    infoQuery.setQueryPayment(cost).execute(testEnv.client);
    testEnv.close(tokenId);
}
Also used : 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 65 with TokenCreateTransaction

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

the class TokenInfoIntegrationTest method getCostInsufficientTxFeeQueryTokenInfo.

@Test
@DisplayName("Throws insufficient transaction fee error")
void getCostInsufficientTxFeeQueryTokenInfo() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    var infoQuery = new TokenInfoQuery().setTokenId(tokenId).setMaxQueryPayment(new Hbar(1000));
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        infoQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    testEnv.close(tokenId);
}
Also used : TokenInfoQuery(com.hedera.hashgraph.sdk.TokenInfoQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)70 Test (org.junit.jupiter.api.Test)64 DisplayName (org.junit.jupiter.api.DisplayName)61 Hbar (com.hedera.hashgraph.sdk.Hbar)34 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)29 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)21 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)15 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)14 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)11 TokenInfoQuery (com.hedera.hashgraph.sdk.TokenInfoQuery)10 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)8 CustomFixedFee (com.hedera.hashgraph.sdk.CustomFixedFee)7 ArrayList (java.util.ArrayList)7 Var (com.google.errorprone.annotations.Var)6 TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)6 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)5 PublicKey (com.hedera.hashgraph.sdk.PublicKey)5 CustomFractionalFee (com.hedera.hashgraph.sdk.CustomFractionalFee)4 TokenId (com.hedera.hashgraph.sdk.TokenId)4 TokenNftInfoQuery (com.hedera.hashgraph.sdk.TokenNftInfoQuery)4