use of com.hedera.hashgraph.sdk.Hbar in project hedera-sdk-java by hashgraph.
the class AccountRecordsIntegrationTest method canQueryAccountRecords.
@Test
@DisplayName("Can query account records")
void canQueryAccountRecords() throws Exception {
var testEnv = new IntegrationTestEnv(1);
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 TransferTransaction().addHbarTransfer(testEnv.operatorId, new Hbar(1).negated()).addHbarTransfer(accountId, new Hbar(1)).execute(testEnv.client).getReceipt(testEnv.client);
new TransferTransaction().addHbarTransfer(testEnv.operatorId, new Hbar(1)).addHbarTransfer(accountId, new Hbar(1).negated()).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
var records = new AccountRecordsQuery().setAccountId(testEnv.operatorId).execute(testEnv.client);
assertThat(records.isEmpty()).isFalse();
testEnv.close(accountId, key);
}
use of com.hedera.hashgraph.sdk.Hbar in project hedera-sdk-java by hashgraph.
the class AccountStakersIntegrationTest method cannotQueryAccountStakersSinceItIsNotSupported.
@Test
@DisplayName("Cannot query account stakers since it is not supported")
void cannotQueryAccountStakersSinceItIsNotSupported() throws Exception {
var testEnv = new IntegrationTestEnv(1);
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
new AccountStakersQuery().setAccountId(testEnv.operatorId).setMaxQueryPayment(new Hbar(1)).execute(testEnv.client);
}).withMessageContaining(Status.NOT_SUPPORTED.toString());
testEnv.close();
}
use of com.hedera.hashgraph.sdk.Hbar in project hedera-sdk-java by hashgraph.
the class AutomaticAssociationTest method autoAssociateTest.
@Test
@DisplayName("Tokens automatically become associated")
void autoAssociateTest() throws Exception {
var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
var key = PrivateKey.generateED25519();
var accountId = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10)).setMaxAutomaticTokenAssociations(1).execute(testEnv.client).getReceipt(testEnv.client).accountId;
Objects.requireNonNull(accountId);
var accountInfo1 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
assertThat(accountInfo1.maxAutomaticTokenAssociations).isEqualTo(1);
assertThat(accountInfo1.tokenRelationships.size()).isEqualTo(0);
var tokenId1 = new TokenCreateTransaction().setTreasuryAccountId(testEnv.operatorId).setTokenName("Test Token").setTokenSymbol("T").setAdminKey(testEnv.operatorKey).setInitialSupply(1).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
var tokenId2 = new TokenCreateTransaction().setTreasuryAccountId(testEnv.operatorId).setTokenName("Test Token").setTokenSymbol("T").setAdminKey(testEnv.operatorKey).setInitialSupply(1).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
Objects.requireNonNull(tokenId1);
Objects.requireNonNull(tokenId2);
var transferResponse1 = new TransferTransaction().addTokenTransfer(tokenId1, testEnv.operatorId, -1).addTokenTransfer(tokenId1, accountId, 1).execute(testEnv.client);
transferResponse1.getReceipt(testEnv.client);
var transferRecord = transferResponse1.getRecord(testEnv.client);
assertThat(transferRecord.automaticTokenAssociations.size()).isEqualTo(1);
assertThat(transferRecord.automaticTokenAssociations.get(0).accountId).isEqualTo(accountId);
assertThat(transferRecord.automaticTokenAssociations.get(0).tokenId).isEqualTo(tokenId1);
var accountInfo2 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
assertThat(accountInfo2.tokenRelationships.size()).isEqualTo(1);
assertThat(accountInfo2.tokenRelationships.get(tokenId1).automaticAssociation).isTrue();
assertThatExceptionOfType(Exception.class).isThrownBy(() -> {
new TransferTransaction().addTokenTransfer(tokenId2, testEnv.operatorId, -1).addTokenTransfer(tokenId2, accountId, 1).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining("NO_REMAINING_AUTOMATIC_ASSOCIATIONS");
new AccountUpdateTransaction().setAccountId(accountId).setMaxAutomaticTokenAssociations(2).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
var accountInfo3 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
assertThat(accountInfo3.maxAutomaticTokenAssociations).isEqualTo(2);
new TokenDeleteTransaction().setTokenId(tokenId1).execute(testEnv.client).getReceipt(testEnv.client);
new TokenDeleteTransaction().setTokenId(tokenId2).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close(accountId, key);
}
use of com.hedera.hashgraph.sdk.Hbar in project hedera-sdk-java by hashgraph.
the class ContractBytecodeIntegrationTest method getCostInsufficientTxFeeQueryContractBytecode.
@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeQueryContractBytecode() 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 bytecodeQuery = new ContractByteCodeQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(100));
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
bytecodeQuery.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 ContractCallIntegrationTest method getCostInsufficientTxFeeContractCallFunction.
@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeContractCallFunction() 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 callQuery = new ContractCallQuery().setContractId(contractId).setGas(100000).setFunction("getMessage").setMaxQueryPayment(new Hbar(100));
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
callQuery.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();
}
Aggregations