Search in sources :

Example 21 with Hbar

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);
}
Also used : AccountRecordsQuery(com.hedera.hashgraph.sdk.AccountRecordsQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with Hbar

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();
}
Also used : AccountStakersQuery(com.hedera.hashgraph.sdk.AccountStakersQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 23 with Hbar

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);
}
Also used : AccountUpdateTransaction(com.hedera.hashgraph.sdk.AccountUpdateTransaction) AccountInfoQuery(com.hedera.hashgraph.sdk.AccountInfoQuery) TokenDeleteTransaction(com.hedera.hashgraph.sdk.TokenDeleteTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 24 with Hbar

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();
}
Also used : ContractByteCodeQuery(com.hedera.hashgraph.sdk.ContractByteCodeQuery) 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) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with Hbar

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();
}
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) ContractCallQuery(com.hedera.hashgraph.sdk.ContractCallQuery) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) 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