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