Search in sources :

Example 6 with AccountUpdateTransaction

use of com.hedera.hashgraph.sdk.AccountUpdateTransaction 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)

Aggregations

AccountUpdateTransaction (com.hedera.hashgraph.sdk.AccountUpdateTransaction)6 Test (org.junit.jupiter.api.Test)5 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)3 AccountInfoQuery (com.hedera.hashgraph.sdk.AccountInfoQuery)3 Hbar (com.hedera.hashgraph.sdk.Hbar)3 DisplayName (org.junit.jupiter.api.DisplayName)3 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 Var (com.google.errorprone.annotations.Var)1 AccountId (com.hedera.hashgraph.sdk.AccountId)1 AccountInfo (com.hedera.hashgraph.sdk.AccountInfo)1 Client (com.hedera.hashgraph.sdk.Client)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 PublicKey (com.hedera.hashgraph.sdk.PublicKey)1 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)1 TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)1 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)1 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)1 Instant (java.time.Instant)1