Search in sources :

Example 1 with TokenAssociateTransaction

use of com.hedera.hashgraph.sdk.TokenAssociateTransaction 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 2 with TokenAssociateTransaction

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

the class TokenFreezeIntegrationTest method canFreezeAccountWithToken.

@Test
@DisplayName("Can freeze account with token")
void canFreezeAccountWithToken() 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 TokenFreezeTransaction().setAccountId(accountId).setTokenId(tokenId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenFreezeTransaction(com.hedera.hashgraph.sdk.TokenFreezeTransaction) 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)

Example 3 with TokenAssociateTransaction

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

the class TokenWipeIntegrationTest method canWipeAccountsBalance.

@Test
@DisplayName("Can wipe accounts balance")
void canWipeAccountsBalance() 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 TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    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) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TokenAssociateTransaction

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

the class TokenWipeIntegrationTest method cannotWipeAccountsBalanceWhenAccountIDIsNotSet.

@Test
@DisplayName("Cannot wipe accounts balance when account ID is not set")
void cannotWipeAccountsBalanceWhenAccountIDIsNotSet() 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 TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).execute(testEnv.client).getReceipt(testEnv.client);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenWipeTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_ACCOUNT_ID.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) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with TokenAssociateTransaction

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

the class TokenNftTransferIntegrationTest method canTransferNfts.

@Test
@DisplayName("Can transfer NFTs")
void canTransferNfts() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    @Var TransactionResponse response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = response.getReceipt(testEnv.client).accountId;
    assertThat(accountId).isNotNull();
    response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).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 = response.getReceipt(testEnv.client).tokenId;
    assertThat(tokenId).isNotNull();
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).setMetadata(NftMetadataGenerator.generate((byte) 10)).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).signWithOperator(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = new ArrayList<Long>(mintReceipt.serials.subList(0, 4));
    var transfer = new TransferTransaction();
    for (var serial : serialsToTransfer) {
        transfer.addNftTransfer(tokenId.nft(serial), testEnv.operatorId, accountId);
    }
    transfer.execute(testEnv.client).getReceipt(testEnv.client);
    new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setSerials(serialsToTransfer).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : Var(com.google.errorprone.annotations.Var) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) ArrayList(java.util.ArrayList) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) 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