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