Search in sources :

Example 76 with Hbar

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

the class AccountBalanceIntegrationTest method getCostBigMaxBalanceForClientOperator.

@Test
@DisplayName("Can fetch cost for the query, big max set")
void getCostBigMaxBalanceForClientOperator() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var balance = new AccountBalanceQuery().setAccountId(testEnv.operatorId).setMaxQueryPayment(new Hbar(1000000));
    var cost = balance.getCost(testEnv.client);
    var accBalance = balance.setQueryPayment(cost).execute(testEnv.client);
    assertThat(accBalance.hbars.toTinybars() > 0).isTrue();
    testEnv.close();
}
Also used : AccountBalanceQuery(com.hedera.hashgraph.sdk.AccountBalanceQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 77 with Hbar

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

the class AccountCreateIntegrationTest method managesExpiration.

@Test
@DisplayName("Regenerates TransactionIds in response to expiration")
void managesExpiration() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generate();
    var accountCreateTx = new AccountCreateTransaction().setKey(key).setTransactionValidDuration(Duration.ofSeconds(25)).freezeWith(testEnv.client);
    Thread.sleep(30000);
    var response = accountCreateTx.execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(info.accountId).isEqualTo(accountId);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.key.toString()).isEqualTo(key.getPublicKey().toString());
    assertThat(info.balance).isEqualTo(new Hbar(0));
    assertThat(info.autoRenewPeriod).isEqualTo(Duration.ofDays(90));
    assertThat(info.proxyAccountId).isNull();
    assertThat(info.proxyReceived).isEqualTo(Hbar.ZERO);
    testEnv.close(accountId, key);
}
Also used : AccountInfoQuery(com.hedera.hashgraph.sdk.AccountInfoQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 78 with Hbar

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

the class AccountCreateIntegrationTest method canCreateAccountWithNoInitialBalance.

@Test
@DisplayName("Can create account with no initial balance")
void canCreateAccountWithNoInitialBalance() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(info.accountId).isEqualTo(accountId);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.key.toString()).isEqualTo(key.getPublicKey().toString());
    assertThat(info.balance).isEqualTo(new Hbar(0));
    assertThat(info.autoRenewPeriod).isEqualTo(Duration.ofDays(90));
    assertThat(info.proxyAccountId).isNull();
    assertThat(info.proxyReceived).isEqualTo(Hbar.ZERO);
    testEnv.close(accountId, key);
}
Also used : AccountInfoQuery(com.hedera.hashgraph.sdk.AccountInfoQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 79 with Hbar

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

the class ContractInfoIntegrationTest method getCostInsufficientTxFeeContractInfoFunction.

@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeContractInfoFunction() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    @Var var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client);
    var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
    var infoQuery = new ContractInfoQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(100));
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        infoQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId).execute(testEnv.client).getReceipt(testEnv.client);
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) ContractDeleteTransaction(com.hedera.hashgraph.sdk.ContractDeleteTransaction) Var(com.google.errorprone.annotations.Var) ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) ContractInfoQuery(com.hedera.hashgraph.sdk.ContractInfoQuery) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 80 with Hbar

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

the class TokenDissociateIntegrationTest method cannotDissociateAccountFromTokenWhenAccountWasNotAssociatedWith.

@Test
@DisplayName("Cannot dissociate account from token when account was not associated with")
void cannotDissociateAccountFromTokenWhenAccountWasNotAssociatedWith() 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)).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 : 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)

Aggregations

Hbar (com.hedera.hashgraph.sdk.Hbar)106 Test (org.junit.jupiter.api.Test)77 DisplayName (org.junit.jupiter.api.DisplayName)75 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)62 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)34 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)31 Client (com.hedera.hashgraph.sdk.Client)22 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)22 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)19 Var (com.google.errorprone.annotations.Var)18 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)16 AccountId (com.hedera.hashgraph.sdk.AccountId)15 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)13 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)13 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)12 AccountInfoQuery (com.hedera.hashgraph.sdk.AccountInfoQuery)11 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)11 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)11 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)9 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)9