Search in sources :

Example 11 with TokenAssociateTransaction

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);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 12 with TokenAssociateTransaction

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);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 13 with TokenAssociateTransaction

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);
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) ScheduleSignTransaction(com.hedera.hashgraph.sdk.ScheduleSignTransaction) AccountBalanceQuery(com.hedera.hashgraph.sdk.AccountBalanceQuery) 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)

Example 14 with TokenAssociateTransaction

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);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

Example 15 with TokenAssociateTransaction

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);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) 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)

Aggregations

TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)26 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)23 Test (org.junit.jupiter.api.Test)23 Hbar (com.hedera.hashgraph.sdk.Hbar)22 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)21 DisplayName (org.junit.jupiter.api.DisplayName)21 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)13 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)10 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)8 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)5 Var (com.google.errorprone.annotations.Var)4 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)4 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)4 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)2 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)2 AccountId (com.hedera.hashgraph.sdk.AccountId)2 Client (com.hedera.hashgraph.sdk.Client)2 CustomFixedFee (com.hedera.hashgraph.sdk.CustomFixedFee)2 TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)2 TokenId (com.hedera.hashgraph.sdk.TokenId)2