Search in sources :

Example 36 with AccountCreateTransaction

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

the class ScheduleCreateIntegrationTest method cannotScheduleTwoTransactions.

@Test
@DisplayName("Cannot schedule two identical transactions")
void cannotScheduleTwoTransactions() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var accountId = new AccountCreateTransaction().setInitialBalance(new Hbar(10)).setKey(key).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    var transferTx = new TransferTransaction().addHbarTransfer(testEnv.operatorId, new Hbar(-10)).addHbarTransfer(accountId, new Hbar(10));
    var scheduleId1 = transferTx.schedule().execute(testEnv.client).getReceipt(testEnv.client).scheduleId;
    var info1 = new ScheduleInfoQuery().setScheduleId(scheduleId1).execute(testEnv.client);
    assertThat(info1.executedAt).isNotNull();
    var transferTxFromInfo = info1.getScheduledTransaction();
    var scheduleCreateTx1 = transferTx.schedule();
    var scheduleCreateTx2 = transferTxFromInfo.schedule();
    assertThat(scheduleCreateTx2.toString()).isEqualTo(scheduleCreateTx1.toString());
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        transferTxFromInfo.schedule().execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining("IDENTICAL_SCHEDULE_ALREADY_CREATED");
    testEnv.close(accountId, key);
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 37 with AccountCreateTransaction

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

the class ScheduleCreateIntegrationTest method canGetTransactionSchedule.

@Test
@Disabled
@DisplayName("Can get Transaction")
void canGetTransactionSchedule() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var transaction = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10));
    var response = new ScheduleCreateTransaction().setScheduledTransaction(transaction).setAdminKey(testEnv.operatorKey).setPayerAccountId(testEnv.operatorId).execute(testEnv.client);
    var scheduleId = Objects.requireNonNull(response.getReceipt(testEnv.client).scheduleId);
    var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
    assertThat(info.executedAt).isNotNull();
    assertThat(info.getScheduledTransaction()).isNotNull();
    testEnv.close();
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) ScheduleCreateTransaction(com.hedera.hashgraph.sdk.ScheduleCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

Example 38 with AccountCreateTransaction

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

the class ScheduleCreateIntegrationTest method canScheduleTokenTransfer.

@Test
@DisplayName("Can schedule token transfer")
void canScheduleTokenTransfer() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    PrivateKey key = PrivateKey.generateED25519();
    var accountId = new AccountCreateTransaction().setReceiverSignatureRequired(true).setKey(key).setInitialBalance(new Hbar(10)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    Objects.requireNonNull(accountId);
    var tokenId = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setInitialSupply(100).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
    Objects.requireNonNull(tokenId);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    var scheduleId = new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).schedule().execute(testEnv.client).getReceipt(testEnv.client).scheduleId;
    Objects.requireNonNull(scheduleId);
    var balanceQuery1 = new AccountBalanceQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(balanceQuery1.tokens.get(tokenId)).isEqualTo(0);
    new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    var balanceQuery2 = new AccountBalanceQuery().setAccountId(accountId).execute(testEnv.client);
    assertThat(balanceQuery2.tokens.get(tokenId)).isEqualTo(10);
    testEnv.close(tokenId, accountId, key);
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) ScheduleSignTransaction(com.hedera.hashgraph.sdk.ScheduleSignTransaction) AccountBalanceQuery(com.hedera.hashgraph.sdk.AccountBalanceQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 39 with AccountCreateTransaction

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

the class ScheduleCreateIntegrationTest method canSignSchedule2.

@Test
@DisplayName("Can sign schedule")
void canSignSchedule2() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    PrivateKey key1 = PrivateKey.generateED25519();
    PrivateKey key2 = PrivateKey.generateED25519();
    PrivateKey key3 = PrivateKey.generateED25519();
    KeyList keyList = new KeyList();
    keyList.add(key1.getPublicKey());
    keyList.add(key2.getPublicKey());
    keyList.add(key3.getPublicKey());
    // Creat the account with the `KeyList`
    TransactionResponse response = new AccountCreateTransaction().setKey(keyList).setInitialBalance(new Hbar(10)).execute(testEnv.client);
    // This will wait for the receipt to become available
    @Var TransactionReceipt receipt = response.getReceipt(testEnv.client);
    AccountId accountId = Objects.requireNonNull(receipt.accountId);
    // Generate a `TransactionId`. This id is used to query the inner scheduled transaction
    // after we expect it to have been executed
    TransactionId transactionId = TransactionId.generate(testEnv.operatorId);
    // Create a transfer transaction with 2/3 signatures.
    TransferTransaction transfer = new TransferTransaction().setTransactionId(transactionId).addHbarTransfer(accountId, new Hbar(1).negated()).addHbarTransfer(testEnv.operatorId, new Hbar(1));
    // Schedule the transactoin
    ScheduleCreateTransaction scheduled = transfer.schedule();
    receipt = scheduled.execute(testEnv.client).getReceipt(testEnv.client);
    // Get the schedule ID from the receipt
    ScheduleId scheduleId = Objects.requireNonNull(receipt.scheduleId);
    // Get the schedule info to see if `signatories` is populated with 2/3 signatures
    @Var ScheduleInfo info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
    assertThat(info.executedAt).isNull();
    // Finally send this last signature to Hedera. This last signature _should_ mean the transaction executes
    // since all 3 signatures have been provided.
    ScheduleSignTransaction signTransaction = new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(testEnv.client);
    signTransaction.sign(key1).sign(key2).sign(key3).execute(testEnv.client).getReceipt(testEnv.client);
    info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
    assertThat(info.executedAt).isNotNull();
    new AccountDeleteTransaction().setAccountId(accountId).setTransferAccountId(testEnv.operatorId).freezeWith(testEnv.client).sign(key1).sign(key2).sign(key3).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) AccountId(com.hedera.hashgraph.sdk.AccountId) Var(com.google.errorprone.annotations.Var) ScheduleSignTransaction(com.hedera.hashgraph.sdk.ScheduleSignTransaction) KeyList(com.hedera.hashgraph.sdk.KeyList) AccountDeleteTransaction(com.hedera.hashgraph.sdk.AccountDeleteTransaction) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) ScheduleId(com.hedera.hashgraph.sdk.ScheduleId) ScheduleInfo(com.hedera.hashgraph.sdk.ScheduleInfo) TransactionId(com.hedera.hashgraph.sdk.TransactionId) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) ScheduleCreateTransaction(com.hedera.hashgraph.sdk.ScheduleCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 40 with AccountCreateTransaction

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

the class TokenAssociateIntegrationTest method canExecuteTokenAssociateTransactionEvenWhenTokenIDsAreNotSet.

@Test
@Disabled
@DisplayName("Can execute token associate transaction even when token IDs are not set")
void canExecuteTokenAssociateTransactionEvenWhenTokenIDsAreNotSet() 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);
    new TokenAssociateTransaction().setAccountId(accountId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(accountId, key);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

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