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();
}
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);
}
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);
}
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();
}
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);
}
Aggregations