Search in sources :

Example 31 with AccountCreateTransaction

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

the class ReceiptQueryIntegrationTest method getCostBigMaxTransactionRecord.

@Test
@DisplayName("Can get Record cost with big max set")
@SuppressWarnings("UnusedVariable")
void getCostBigMaxTransactionRecord() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).execute(testEnv.client);
    new TransactionReceiptQuery().setTransactionId(response.transactionId).execute(testEnv.client);
    var recordQuery = new TransactionRecordQuery().setTransactionId(response.transactionId).setMaxQueryPayment(new Hbar(1000));
    var cost = recordQuery.getCost(testEnv.client);
    var record = recordQuery.execute(testEnv.client);
    testEnv.close(record.receipt.accountId, key);
}
Also used : TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) TransactionReceiptQuery(com.hedera.hashgraph.sdk.TransactionReceiptQuery) 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 32 with AccountCreateTransaction

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

the class ReceiptQueryIntegrationTest method getCostInsufficientTxFeeTransactionRecord.

@Test
@DisplayName("Insufficient transaction fee error for transaction record query")
void getCostInsufficientTxFeeTransactionRecord() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).execute(testEnv.client);
    var receipt = new TransactionReceiptQuery().setTransactionId(response.transactionId).execute(testEnv.client);
    var recordQuery = new TransactionRecordQuery().setTransactionId(response.transactionId);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        recordQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    testEnv.close(receipt.accountId, key);
}
Also used : TransactionRecordQuery(com.hedera.hashgraph.sdk.TransactionRecordQuery) TransactionReceiptQuery(com.hedera.hashgraph.sdk.TransactionReceiptQuery) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 33 with AccountCreateTransaction

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

the class AccountCreateTransactionSupplierTest method createWithCustomData.

@Test
void createWithCustomData() {
    PublicKey key = PrivateKey.generate().getPublicKey();
    AccountCreateTransactionSupplier accountCreateTransactionSupplier = new AccountCreateTransactionSupplier();
    accountCreateTransactionSupplier.setInitialBalance(1);
    accountCreateTransactionSupplier.setMaxTransactionFee(1);
    accountCreateTransactionSupplier.setReceiverSignatureRequired(true);
    accountCreateTransactionSupplier.setPublicKey(key.toString());
    AccountCreateTransaction actual = accountCreateTransactionSupplier.get();
    assertThat(actual).returns(ONE_TINYBAR, AccountCreateTransaction::getInitialBalance).returns(key, AccountCreateTransaction::getKey).returns(ONE_TINYBAR, AccountCreateTransaction::getMaxTransactionFee).returns(true, AccountCreateTransaction::getReceiverSignatureRequired).extracting(AccountCreateTransaction::getAccountMemo, STRING).contains("Mirror node created test account");
}
Also used : PublicKey(com.hedera.hashgraph.sdk.PublicKey) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 34 with AccountCreateTransaction

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

the class AccountCreateTransactionSupplierTest method createWithMinimumData.

@Test
void createWithMinimumData() {
    AccountCreateTransactionSupplier accountCreateTransactionSupplier = new AccountCreateTransactionSupplier();
    AccountCreateTransaction actual = accountCreateTransactionSupplier.get();
    assertThat(actual).returns(Hbar.fromTinybars(10_000_000), AccountCreateTransaction::getInitialBalance).returns(MAX_TRANSACTION_FEE_HBAR, AccountCreateTransaction::getMaxTransactionFee).returns(false, AccountCreateTransaction::getReceiverSignatureRequired).satisfies(a -> assertThat(a.getKey()).isNotNull()).extracting(AccountCreateTransaction::getAccountMemo, STRING).contains("Mirror node created test account");
}
Also used : AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 35 with AccountCreateTransaction

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

the class AccountClient method createCryptoAccount.

public ExpandedAccountId createCryptoAccount(Hbar initialBalance, boolean receiverSigRequired, KeyList keyList, String memo) {
    // 1. Generate a Ed25519 private, public key pair
    PrivateKey privateKey = PrivateKey.generate();
    PublicKey publicKey = privateKey.getPublicKey();
    log.trace("Private key = {}", privateKey);
    log.trace("Public key = {}", publicKey);
    KeyList publicKeyList = KeyList.of(privateKey.getPublicKey());
    if (keyList != null) {
        publicKeyList.addAll(keyList);
    }
    AccountCreateTransaction accountCreateTransaction = getAccountCreateTransaction(initialBalance, publicKeyList, receiverSigRequired, memo == null ? "" : memo);
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(accountCreateTransaction, receiverSigRequired ? KeyList.of(privateKey) : null);
    TransactionReceipt receipt = networkTransactionResponse.getReceipt();
    AccountId newAccountId = receipt.accountId;
    // verify accountId
    if (receipt.accountId == null) {
        throw new NetworkException(String.format("Receipt for %s returned no accountId, receipt: %s", networkTransactionResponse.getTransactionId(), receipt));
    }
    log.debug("Created new account {}, receiverSigRequired: {}", newAccountId, receiverSigRequired);
    return new ExpandedAccountId(newAccountId, privateKey, privateKey.getPublicKey());
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) AccountId(com.hedera.hashgraph.sdk.AccountId) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) PublicKey(com.hedera.hashgraph.sdk.PublicKey) KeyList(com.hedera.hashgraph.sdk.KeyList) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction)

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