Search in sources :

Example 11 with TokenGrantKycTransaction

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

the class TokenGrantKycIntegrationTest method cannotGrantKycToAccountOnTokenWhenAccountWasNotAssociatedWith.

@Test
@DisplayName("Cannot grant kyc to account on token when account was not associated with")
void cannotGrantKycToAccountOnTokenWhenAccountWasNotAssociatedWith() 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 TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with TokenGrantKycTransaction

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

the class TokenWipeIntegrationTest method cannotWipeAccountsBalanceWhenAmountIsNotSet.

@Test
@DisplayName("Cannot wipe accounts balance when amount is not set")
void cannotWipeAccountsBalanceWhenAmountIsNotSet() 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).setAccountId(accountId).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_WIPING_AMOUNT.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 13 with TokenGrantKycTransaction

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

the class TokenWipeIntegrationTest method canWipeAccountsNfts.

@Test
@DisplayName("Can wipe accounts NFTs")
void canWipeAccountsNfts() 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").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).getReceipt(testEnv.client).tokenId);
    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).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = 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 : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) 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 14 with TokenGrantKycTransaction

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

the class TokenWipeIntegrationTest method cannotWipeAccountsNftsIfNotOwned.

@Test
@DisplayName("Cannot wipe accounts NFTs if the account doesn't own them")
void cannotWipeAccountsNftsIfNotOwned() 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").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).getReceipt(testEnv.client).tokenId);
    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).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = mintReceipt.serials.subList(0, 4);
    // don't transfer them
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setSerials(serialsToTransfer).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.ACCOUNT_DOES_NOT_OWN_WIPED_NFT.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) 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 15 with TokenGrantKycTransaction

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

the class TokenWipeIntegrationTest method cannotWipeAccountsBalanceWhenTokenIDIsNotSet.

@Test
@DisplayName("Cannot wipe accounts balance when token ID is not set")
void cannotWipeAccountsBalanceWhenTokenIDIsNotSet() 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().setAccountId(accountId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_TOKEN_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)

Aggregations

TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)15 Test (org.junit.jupiter.api.Test)13 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)12 Hbar (com.hedera.hashgraph.sdk.Hbar)11 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)11 DisplayName (org.junit.jupiter.api.DisplayName)11 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)10 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)8 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)8 Var (com.google.errorprone.annotations.Var)3 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)3 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)3 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)1 AccountId (com.hedera.hashgraph.sdk.AccountId)1 Client (com.hedera.hashgraph.sdk.Client)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)1 TokenId (com.hedera.hashgraph.sdk.TokenId)1 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)1