Search in sources :

Example 71 with Hbar

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

the class AccountUpdateIntegrationTest method canUpdateAccountWithNewKey.

@Test
@DisplayName("Can update account with a new key")
void canUpdateAccountWithNewKey() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key1 = PrivateKey.generateED25519();
    var key2 = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key1).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    @Var var info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(info.accountId).isEqualTo(accountId);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.key.toString()).isEqualTo(key1.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);
    new AccountUpdateTransaction().setAccountId(accountId).setKey(key2.getPublicKey()).freezeWith(testEnv.client).sign(key1).sign(key2).execute(testEnv.client).getReceipt(testEnv.client);
    info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(info.accountId).isEqualTo(accountId);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.key.toString()).isEqualTo(key2.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, key2);
}
Also used : AccountUpdateTransaction(com.hedera.hashgraph.sdk.AccountUpdateTransaction) Var(com.google.errorprone.annotations.Var) 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 72 with Hbar

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

the class ClientIntegrationTest method testReplaceNodes.

@Test
@DisplayName("setNetwork() functions correctly")
void testReplaceNodes() throws Exception {
    @Var Map<String, AccountId> network = new HashMap<>();
    network.put("0.testnet.hedera.com:50211", new AccountId(3));
    network.put("1.testnet.hedera.com:50211", new AccountId(4));
    var testEnv = new IntegrationTestEnv(1);
    testEnv.client.setMaxQueryPayment(new Hbar(2)).setRequestTimeout(Duration.ofMinutes(2)).setNetwork(network);
    assertThat(testEnv.operatorId).isNotNull();
    // Execute two simple queries so we create a channel for each network node.
    new AccountBalanceQuery().setAccountId(testEnv.operatorId).execute(testEnv.client);
    new AccountBalanceQuery().setAccountId(testEnv.operatorId).execute(testEnv.client);
    network = new HashMap<>();
    network.put("1.testnet.hedera.com:50211", new AccountId(4));
    network.put("2.testnet.hedera.com:50211", new AccountId(5));
    testEnv.client.setNetwork(network);
    network = new HashMap<>();
    network.put("35.186.191.247:50211", new AccountId(4));
    network.put("35.192.2.25:50211", new AccountId(5));
    testEnv.client.setNetwork(network);
    testEnv.close();
}
Also used : AccountId(com.hedera.hashgraph.sdk.AccountId) HashMap(java.util.HashMap) Var(com.google.errorprone.annotations.Var) 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 73 with Hbar

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

the class ContractBytecodeIntegrationTest method getCostBigMaxQueryContractBytecode.

@Test
@DisplayName("Can get cost, even with a big max")
void getCostBigMaxQueryContractBytecode() 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(1000));
    var cost = bytecodeQuery.getCost(testEnv.client);
    var bytecode = bytecodeQuery.setQueryPayment(cost).execute(testEnv.client);
    assertThat(bytecode.size()).isEqualTo(798);
    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 74 with Hbar

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

the class ContractCallIntegrationTest method getCostBigMaxContractCallFunction.

@Test
@DisplayName("Can get cost, even with a big max")
void getCostBigMaxContractCallFunction() 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").setQueryPayment(new Hbar(1));
    var result = callQuery.execute(testEnv.client);
    assertThat(result.getString(0)).isEqualTo("Hello from Hedera.");
    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)

Example 75 with Hbar

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

the class AccountBalanceIntegrationTest method getCostBalanceForClientOperator.

@Test
@DisplayName("Can fetch cost for the query")
void getCostBalanceForClientOperator() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var balance = new AccountBalanceQuery().setAccountId(testEnv.operatorId).setMaxQueryPayment(new Hbar(1));
    var cost = balance.getCost(testEnv.client);
    var accBalance = balance.setQueryPayment(cost).execute(testEnv.client);
    assertThat(accBalance.hbars.toTinybars() > 0).isTrue();
    assertThat(cost.toTinybars()).isEqualTo(0);
    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)

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