Search in sources :

Example 56 with AccountCreateTransaction

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

the class AccountInfoIntegrationTest method accountInfoFlowVerifyFunctions.

@Test
@DisplayName("AccountInfoFlow.verify functions")
void accountInfoFlowVerifyFunctions() throws Throwable {
    var testEnv = new IntegrationTestEnv(1);
    var newKey = PrivateKey.generateED25519();
    var newPublicKey = newKey.getPublicKey();
    Transaction<?> signedTx = new AccountCreateTransaction().setKey(newPublicKey).setInitialBalance(Hbar.fromTinybars(1000)).freezeWith(testEnv.client).signWithOperator(testEnv.client);
    Transaction<?> unsignedTx = new AccountCreateTransaction().setKey(newPublicKey).setInitialBalance(Hbar.fromTinybars(1000)).freezeWith(testEnv.client);
    assertThat(AccountInfoFlow.verifyTransactionSignature(testEnv.client, testEnv.operatorId, signedTx)).isTrue();
    assertThat(AccountInfoFlow.verifyTransactionSignature(testEnv.client, testEnv.operatorId, unsignedTx)).isFalse();
    testEnv.close();
}
Also used : AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 57 with AccountCreateTransaction

use of com.hedera.hashgraph.sdk.AccountCreateTransaction 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 58 with AccountCreateTransaction

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

the class AccountCreateIntegrationTest method managesExpiration.

@Test
@DisplayName("Regenerates TransactionIds in response to expiration")
void managesExpiration() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generate();
    var accountCreateTx = new AccountCreateTransaction().setKey(key).setTransactionValidDuration(Duration.ofSeconds(25)).freezeWith(testEnv.client);
    Thread.sleep(30000);
    var response = accountCreateTx.execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(info.accountId).isEqualTo(accountId);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.key.toString()).isEqualTo(key.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, key);
}
Also used : 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 59 with AccountCreateTransaction

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

the class AccountCreateIntegrationTest method canCreateAccountWithNoInitialBalance.

@Test
@DisplayName("Can create account with no initial balance")
void canCreateAccountWithNoInitialBalance() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(info.accountId).isEqualTo(accountId);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.key.toString()).isEqualTo(key.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, key);
}
Also used : 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 60 with AccountCreateTransaction

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

the class TokenDissociateIntegrationTest method cannotDissociateAccountFromTokenWhenAccountWasNotAssociatedWith.

@Test
@DisplayName("Cannot dissociate account from token when account was not associated with")
void cannotDissociateAccountFromTokenWhenAccountWasNotAssociatedWith() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    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);
    var tokenId = Objects.requireNonNull(new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenDissociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenDissociateTransaction(com.hedera.hashgraph.sdk.TokenDissociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)73 Hbar (com.hedera.hashgraph.sdk.Hbar)62 Test (org.junit.jupiter.api.Test)59 DisplayName (org.junit.jupiter.api.DisplayName)57 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)29 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)26 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)23 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)16 AccountId (com.hedera.hashgraph.sdk.AccountId)15 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)15 Var (com.google.errorprone.annotations.Var)12 Client (com.hedera.hashgraph.sdk.Client)12 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)12 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)11 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)10 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)9 KeyList (com.hedera.hashgraph.sdk.KeyList)9 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)8 AccountInfoQuery (com.hedera.hashgraph.sdk.AccountInfoQuery)7 PublicKey (com.hedera.hashgraph.sdk.PublicKey)7