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