Search in sources :

Example 1 with TokenDeleteTransaction

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

the class TokenDeleteIntegrationTest method cannotDeleteTokenWhenTokenIDIsNotSet.

@Test
@DisplayName("Cannot delete token when token ID is not set")
void cannotDeleteTokenWhenTokenIDIsNotSet() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenDeleteTransaction().execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_TOKEN_ID.toString());
    testEnv.close();
}
Also used : TokenDeleteTransaction(com.hedera.hashgraph.sdk.TokenDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with TokenDeleteTransaction

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

the class TokenInfoIntegrationTest method canQueryTokenInfoWhenAllKeysAreDifferent.

@Test
@DisplayName("Can query token info when all keys are different")
void canQueryTokenInfoWhenAllKeysAreDifferent() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key1 = PrivateKey.generateED25519();
    var key2 = PrivateKey.generateED25519();
    var key3 = PrivateKey.generateED25519();
    var key4 = PrivateKey.generateED25519();
    var key5 = PrivateKey.generateED25519();
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).setTreasuryAccountId(testEnv.operatorId).setAdminKey(key1).setFreezeKey(key2).setWipeKey(key3).setKycKey(key4).setSupplyKey(key5).setFreezeDefault(false).freezeWith(testEnv.client).sign(key1).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    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(3);
    assertThat(info.treasuryAccountId).isEqualTo(testEnv.operatorId);
    assertThat(info.adminKey).isNotNull();
    assertThat(info.freezeKey).isNotNull();
    assertThat(info.wipeKey).isNotNull();
    assertThat(info.kycKey).isNotNull();
    assertThat(info.supplyKey).isNotNull();
    assertThat(info.adminKey.toString()).isEqualTo(key1.getPublicKey().toString());
    assertThat(info.freezeKey.toString()).isEqualTo(key2.getPublicKey().toString());
    assertThat(info.wipeKey.toString()).isEqualTo(key3.getPublicKey().toString());
    assertThat(info.kycKey.toString()).isEqualTo(key4.getPublicKey().toString());
    assertThat(info.supplyKey.toString()).isEqualTo(key5.getPublicKey().toString());
    assertThat(info.defaultFreezeStatus).isNotNull();
    assertThat(info.defaultFreezeStatus).isFalse();
    assertThat(info.defaultKycStatus).isNotNull();
    assertThat(info.defaultKycStatus).isFalse();
    assertThat(info.tokenType).isEqualTo(TokenType.FUNGIBLE_COMMON);
    assertThat(info.supplyType).isEqualTo(TokenSupplyType.INFINITE);
    new TokenDeleteTransaction().setTokenId(tokenId).freezeWith(testEnv.client).sign(key1).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : TokenInfoQuery(com.hedera.hashgraph.sdk.TokenInfoQuery) TokenDeleteTransaction(com.hedera.hashgraph.sdk.TokenDeleteTransaction) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TokenDeleteTransaction

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

the class TokenDeleteIntegrationTest method canDeleteToken.

@Test
@DisplayName("Can delete token")
void canDeleteToken() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var response = 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);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    new TokenDeleteTransaction().setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : TokenDeleteTransaction(com.hedera.hashgraph.sdk.TokenDeleteTransaction) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TokenDeleteTransaction

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

the class TransferTokensExample method main.

public static void main(String[] args) throws Exception {
    Client client = Client.forName(HEDERA_NETWORK);
    // Defaults the operator account ID and key such that all generated transactions will be paid for
    // by this account and be signed by this key
    client.setOperator(OPERATOR_ID, OPERATOR_KEY);
    // Generate a Ed25519 private, public key pair
    PrivateKey key1 = PrivateKey.generateED25519();
    PrivateKey key2 = PrivateKey.generateED25519();
    System.out.println("private key = " + key1);
    System.out.println("public key = " + key1.getPublicKey());
    System.out.println("private key = " + key2);
    System.out.println("public key = " + key2.getPublicKey());
    @Var TransactionResponse response = new AccountCreateTransaction().setKey(key1.getPublicKey()).setInitialBalance(Hbar.fromTinybars(1000)).execute(client);
    // This will wait for the receipt to become available
    @Var TransactionReceipt receipt = response.getReceipt(client);
    AccountId accountId1 = Objects.requireNonNull(receipt.accountId);
    System.out.println("accountId1 = " + accountId1);
    response = new AccountCreateTransaction().setKey(key2.getPublicKey()).setInitialBalance(Hbar.fromTinybars(1000)).execute(client);
    // This will wait for the receipt to become available
    receipt = response.getReceipt(client);
    AccountId accountId2 = Objects.requireNonNull(receipt.accountId);
    System.out.println("accountId2 = " + accountId1);
    response = new TokenCreateTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).setTreasuryAccountId(OPERATOR_ID).setAdminKey(OPERATOR_KEY.getPublicKey()).setFreezeKey(OPERATOR_KEY.getPublicKey()).setWipeKey(OPERATOR_KEY.getPublicKey()).setKycKey(OPERATOR_KEY.getPublicKey()).setSupplyKey(OPERATOR_KEY.getPublicKey()).setFreezeDefault(false).execute(client);
    TokenId tokenId = Objects.requireNonNull(response.getReceipt(client).tokenId);
    System.out.println("token = " + tokenId);
    new TokenAssociateTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId1).setTokenIds(Collections.singletonList(tokenId)).freezeWith(client).sign(OPERATOR_KEY).sign(key1).execute(client).getReceipt(client);
    System.out.println("Associated account " + accountId1 + " with token " + tokenId);
    new TokenAssociateTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId2).setTokenIds(Collections.singletonList(tokenId)).freezeWith(client).sign(OPERATOR_KEY).sign(key2).execute(client).getReceipt(client);
    System.out.println("Associated account " + accountId2 + " with token " + tokenId);
    new TokenGrantKycTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId1).setTokenId(tokenId).execute(client).getReceipt(client);
    System.out.println("Granted KYC for account " + accountId1 + " on token " + tokenId);
    new TokenGrantKycTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId2).setTokenId(tokenId).execute(client).getReceipt(client);
    System.out.println("Granted KYC for account " + accountId2 + " on token " + tokenId);
    new TransferTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).addTokenTransfer(tokenId, OPERATOR_ID, -10).addTokenTransfer(tokenId, accountId1, 10).execute(client).getReceipt(client);
    System.out.println("Sent 10 tokens from account " + OPERATOR_ID + " to account " + accountId1 + " on token " + tokenId);
    new TransferTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).addTokenTransfer(tokenId, accountId1, -10).addTokenTransfer(tokenId, accountId2, 10).freezeWith(client).sign(key1).execute(client).getReceipt(client);
    System.out.println("Sent 10 tokens from account " + accountId1 + " to account " + accountId2 + " on token " + tokenId);
    new TransferTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).addTokenTransfer(tokenId, accountId2, -10).addTokenTransfer(tokenId, accountId1, 10).freezeWith(client).sign(key2).execute(client).getReceipt(client);
    System.out.println("Sent 10 tokens from account " + accountId2 + " to account " + accountId1 + " on token " + tokenId);
    new TokenWipeTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setTokenId(tokenId).setAccountId(accountId1).setAmount(10).execute(client).getReceipt(client);
    System.out.println("Wiped balance of account " + accountId1);
    new TokenDeleteTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setTokenId(tokenId).execute(client).getReceipt(client);
    System.out.println("Deleted token " + tokenId);
    new AccountDeleteTransaction().setAccountId(accountId1).setTransferAccountId(OPERATOR_ID).freezeWith(client).sign(OPERATOR_KEY).sign(key1).execute(client).getReceipt(client);
    System.out.println("Deleted accountId1 " + accountId1);
    new AccountDeleteTransaction().setAccountId(accountId2).setTransferAccountId(OPERATOR_ID).freezeWith(client).sign(OPERATOR_KEY).sign(key2).execute(client).getReceipt(client);
    System.out.println("Deleted accountId2" + accountId2);
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) AccountId(com.hedera.hashgraph.sdk.AccountId) Var(com.google.errorprone.annotations.Var) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) TokenDeleteTransaction(com.hedera.hashgraph.sdk.TokenDeleteTransaction) AccountDeleteTransaction(com.hedera.hashgraph.sdk.AccountDeleteTransaction) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) Client(com.hedera.hashgraph.sdk.Client) TokenId(com.hedera.hashgraph.sdk.TokenId) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction)

Example 5 with TokenDeleteTransaction

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

the class AutomaticAssociationTest method autoAssociateTest.

@Test
@DisplayName("Tokens automatically become associated")
void autoAssociateTest() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    var accountId = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10)).setMaxAutomaticTokenAssociations(1).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    Objects.requireNonNull(accountId);
    var accountInfo1 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(accountInfo1.maxAutomaticTokenAssociations).isEqualTo(1);
    assertThat(accountInfo1.tokenRelationships.size()).isEqualTo(0);
    var tokenId1 = new TokenCreateTransaction().setTreasuryAccountId(testEnv.operatorId).setTokenName("Test Token").setTokenSymbol("T").setAdminKey(testEnv.operatorKey).setInitialSupply(1).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
    var tokenId2 = new TokenCreateTransaction().setTreasuryAccountId(testEnv.operatorId).setTokenName("Test Token").setTokenSymbol("T").setAdminKey(testEnv.operatorKey).setInitialSupply(1).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
    Objects.requireNonNull(tokenId1);
    Objects.requireNonNull(tokenId2);
    var transferResponse1 = new TransferTransaction().addTokenTransfer(tokenId1, testEnv.operatorId, -1).addTokenTransfer(tokenId1, accountId, 1).execute(testEnv.client);
    transferResponse1.getReceipt(testEnv.client);
    var transferRecord = transferResponse1.getRecord(testEnv.client);
    assertThat(transferRecord.automaticTokenAssociations.size()).isEqualTo(1);
    assertThat(transferRecord.automaticTokenAssociations.get(0).accountId).isEqualTo(accountId);
    assertThat(transferRecord.automaticTokenAssociations.get(0).tokenId).isEqualTo(tokenId1);
    var accountInfo2 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(accountInfo2.tokenRelationships.size()).isEqualTo(1);
    assertThat(accountInfo2.tokenRelationships.get(tokenId1).automaticAssociation).isTrue();
    assertThatExceptionOfType(Exception.class).isThrownBy(() -> {
        new TransferTransaction().addTokenTransfer(tokenId2, testEnv.operatorId, -1).addTokenTransfer(tokenId2, accountId, 1).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining("NO_REMAINING_AUTOMATIC_ASSOCIATIONS");
    new AccountUpdateTransaction().setAccountId(accountId).setMaxAutomaticTokenAssociations(2).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    var accountInfo3 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(accountInfo3.maxAutomaticTokenAssociations).isEqualTo(2);
    new TokenDeleteTransaction().setTokenId(tokenId1).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenDeleteTransaction().setTokenId(tokenId2).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(accountId, key);
}
Also used : AccountUpdateTransaction(com.hedera.hashgraph.sdk.AccountUpdateTransaction) AccountInfoQuery(com.hedera.hashgraph.sdk.AccountInfoQuery) TokenDeleteTransaction(com.hedera.hashgraph.sdk.TokenDeleteTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)10 Test (org.junit.jupiter.api.Test)7 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)6 DisplayName (org.junit.jupiter.api.DisplayName)5 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)3 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)3 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)2 AccountId (com.hedera.hashgraph.sdk.AccountId)2 Client (com.hedera.hashgraph.sdk.Client)2 Hbar (com.hedera.hashgraph.sdk.Hbar)2 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)2 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)2 TokenId (com.hedera.hashgraph.sdk.TokenId)2 TokenInfoQuery (com.hedera.hashgraph.sdk.TokenInfoQuery)2 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 Var (com.google.errorprone.annotations.Var)1 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)1 AccountInfoQuery (com.hedera.hashgraph.sdk.AccountInfoQuery)1 AccountUpdateTransaction (com.hedera.hashgraph.sdk.AccountUpdateTransaction)1 CustomFee (com.hedera.hashgraph.sdk.CustomFee)1