Search in sources :

Example 1 with TokenDissociateTransaction

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

the class TokenDissociateIntegrationTest method cannotDissociateAccountWithTokensWhenAccountIDIsNotSet.

@Test
@DisplayName("Cannot dissociate account with tokens when account ID is not set")
void cannotDissociateAccountWithTokensWhenAccountIDIsNotSet() 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);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenDissociateTransaction().freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_ACCOUNT_ID.toString());
    testEnv.close(accountId, key);
}
Also used : TokenDissociateTransaction(com.hedera.hashgraph.sdk.TokenDissociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with TokenDissociateTransaction

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

the class TokenDissociateIntegrationTest method cannotDissociateAccountWhenAccountDoesNotSignTransaction.

@Test
@DisplayName("Cannot dissociate account with tokens when account does not sign transaction")
void cannotDissociateAccountWhenAccountDoesNotSignTransaction() 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 TokenDissociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_SIGNATURE.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenDissociateTransaction(com.hedera.hashgraph.sdk.TokenDissociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TokenDissociateTransaction

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

the class TokenDissociateIntegrationTest method canExecuteTokenDissociateTransactionEvenWhenTokenIDsAreNotSet.

@Test
@DisplayName("Can execute token dissociate transaction even when token IDs are not set")
void canExecuteTokenDissociateTransactionEvenWhenTokenIDsAreNotSet() 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);
    new TokenDissociateTransaction().setAccountId(accountId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(accountId, key);
}
Also used : TokenDissociateTransaction(com.hedera.hashgraph.sdk.TokenDissociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TokenDissociateTransaction

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

the class TokenDissociateIntegrationTest method canAssociateAccountWithToken.

@Test
@DisplayName("Can dissociate account with token")
void canAssociateAccountWithToken() 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 TokenDissociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(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) TokenDissociateTransaction(com.hedera.hashgraph.sdk.TokenDissociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with TokenDissociateTransaction

use of com.hedera.hashgraph.sdk.TokenDissociateTransaction in project hedera-mirror-node by hashgraph.

the class TokenClient method dissociate.

public NetworkTransactionResponse dissociate(ExpandedAccountId accountId, TokenId token) {
    log.debug("Dissociate account {} with token {}", accountId.getAccountId(), token);
    TokenDissociateTransaction tokenDissociateTransaction = new TokenDissociateTransaction().setAccountId(accountId.getAccountId()).setTokenIds(List.of(token)).setTransactionMemo(getMemo("Dissociate token"));
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(tokenDissociateTransaction, KeyList.of(accountId.getPrivateKey()));
    log.debug("Dissociated {} with token {}", accountId, token);
    return networkTransactionResponse;
}
Also used : NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) TokenDissociateTransaction(com.hedera.hashgraph.sdk.TokenDissociateTransaction)

Aggregations

TokenDissociateTransaction (com.hedera.hashgraph.sdk.TokenDissociateTransaction)8 Test (org.junit.jupiter.api.Test)7 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)5 Hbar (com.hedera.hashgraph.sdk.Hbar)5 DisplayName (org.junit.jupiter.api.DisplayName)5 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)3 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)1 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)1