use of com.hedera.hashgraph.sdk.TokenAssociateTransaction in project hedera-mirror-node by hashgraph.
the class TokenAssociateTransactionSupplierTest method createWithMinimumData.
@Test
void createWithMinimumData() {
TokenAssociateTransactionSupplier tokenAssociateTransactionSupplier = new TokenAssociateTransactionSupplier();
tokenAssociateTransactionSupplier.setAccountId(ACCOUNT_ID.toString());
tokenAssociateTransactionSupplier.setTokenId(TOKEN_ID.toString());
TokenAssociateTransaction actual = tokenAssociateTransactionSupplier.get();
assertThat(actual).returns(ACCOUNT_ID, TokenAssociateTransaction::getAccountId).returns(MAX_TRANSACTION_FEE_HBAR, TokenAssociateTransaction::getMaxTransactionFee).returns(List.of(TOKEN_ID), TokenAssociateTransaction::getTokenIds);
}
use of com.hedera.hashgraph.sdk.TokenAssociateTransaction in project hedera-mirror-node by hashgraph.
the class TokenAssociateTransactionSupplierTest method createWithCustomData.
@Test
void createWithCustomData() {
TokenAssociateTransactionSupplier tokenAssociateTransactionSupplier = new TokenAssociateTransactionSupplier();
tokenAssociateTransactionSupplier.setAccountId(ACCOUNT_ID.toString());
tokenAssociateTransactionSupplier.setMaxTransactionFee(1);
tokenAssociateTransactionSupplier.setTokenId(TOKEN_ID.toString());
TokenAssociateTransaction actual = tokenAssociateTransactionSupplier.get();
assertThat(actual).returns(ACCOUNT_ID, TokenAssociateTransaction::getAccountId).returns(ONE_TINYBAR, TokenAssociateTransaction::getMaxTransactionFee).returns(List.of(TOKEN_ID), TokenAssociateTransaction::getTokenIds);
}
use of com.hedera.hashgraph.sdk.TokenAssociateTransaction in project hedera-sdk-java by hashgraph.
the class ScheduleCreateIntegrationTest method canScheduleTokenTransfer.
@Test
@DisplayName("Can schedule token transfer")
void canScheduleTokenTransfer() throws Exception {
var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
PrivateKey key = PrivateKey.generateED25519();
var accountId = new AccountCreateTransaction().setReceiverSignatureRequired(true).setKey(key).setInitialBalance(new Hbar(10)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client).accountId;
Objects.requireNonNull(accountId);
var tokenId = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setInitialSupply(100).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
Objects.requireNonNull(tokenId);
new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
var scheduleId = new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).schedule().execute(testEnv.client).getReceipt(testEnv.client).scheduleId;
Objects.requireNonNull(scheduleId);
var balanceQuery1 = new AccountBalanceQuery().setAccountId(accountId).execute(testEnv.client);
assertThat(balanceQuery1.tokens.get(tokenId)).isEqualTo(0);
new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
var balanceQuery2 = new AccountBalanceQuery().setAccountId(accountId).execute(testEnv.client);
assertThat(balanceQuery2.tokens.get(tokenId)).isEqualTo(10);
testEnv.close(tokenId, accountId, key);
}
use of com.hedera.hashgraph.sdk.TokenAssociateTransaction in project hedera-sdk-java by hashgraph.
the class TokenAssociateIntegrationTest method canExecuteTokenAssociateTransactionEvenWhenTokenIDsAreNotSet.
@Test
@Disabled
@DisplayName("Can execute token associate transaction even when token IDs are not set")
void canExecuteTokenAssociateTransactionEvenWhenTokenIDsAreNotSet() 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 TokenAssociateTransaction().setAccountId(accountId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close(accountId, key);
}
use of com.hedera.hashgraph.sdk.TokenAssociateTransaction in project hedera-sdk-java by hashgraph.
the class TokenAssociateIntegrationTest method cannotAssociateAccountWhenAccountDoesNotSignTransaction.
@Test
@DisplayName("Cannot associate account with tokens when account does not sign transaction")
void cannotAssociateAccountWhenAccountDoesNotSignTransaction() 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 TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INVALID_SIGNATURE.toString());
testEnv.close(tokenId, accountId, key);
}
Aggregations