Search in sources :

Example 6 with AccountCreateTransaction

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

the class TokenWipeIntegrationTest method canWipeAccountsBalance.

@Test
@DisplayName("Can wipe accounts balance")
void canWipeAccountsBalance() 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);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with AccountCreateTransaction

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

the class TokenWipeIntegrationTest method cannotWipeAccountsBalanceWhenAccountIDIsNotSet.

@Test
@DisplayName("Cannot wipe accounts balance when account ID is not set")
void cannotWipeAccountsBalanceWhenAccountIDIsNotSet() 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);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).execute(testEnv.client).getReceipt(testEnv.client);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenWipeTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_ACCOUNT_ID.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with AccountCreateTransaction

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

the class ScheduleCreateIntegrationTest method canScheduleTopicMessage.

@Test
@DisplayName("Can schedule topic message")
void canScheduleTopicMessage() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    // Generate 3 random keys
    var key1 = PrivateKey.generateED25519();
    // This is the submit key
    var key2 = PrivateKey.generateED25519();
    var key3 = PrivateKey.generateED25519();
    var keyList = new KeyList();
    keyList.add(key1.getPublicKey());
    keyList.add(key2.getPublicKey());
    keyList.add(key3.getPublicKey());
    var response = new AccountCreateTransaction().setInitialBalance(new Hbar(100)).setKey(keyList).execute(testEnv.client);
    assertThat(response.getReceipt(testEnv.client).accountId).isNotNull();
    var topicId = Objects.requireNonNull(new TopicCreateTransaction().setAdminKey(testEnv.operatorKey).setAutoRenewAccountId(testEnv.operatorId).setTopicMemo("HCS Topic_").setSubmitKey(key2.getPublicKey()).execute(testEnv.client).getReceipt(testEnv.client).topicId);
    var transaction = new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage("scheduled hcs message".getBytes(StandardCharsets.UTF_8));
    // create schedule
    var scheduledTx = transaction.schedule().setAdminKey(testEnv.operatorKey).setPayerAccountId(testEnv.operatorId).setScheduleMemo("mirror scheduled E2E signature on create and sign_" + Instant.now());
    var scheduled = scheduledTx.freezeWith(testEnv.client);
    var scheduleId = Objects.requireNonNull(scheduled.execute(testEnv.client).getReceipt(testEnv.client).scheduleId);
    // verify schedule has been created and has 1 of 2 signatures
    @Var var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
    assertThat(info).isNotNull();
    assertThat(info.scheduleId).isEqualTo(scheduleId);
    var infoTransaction = (TopicMessageSubmitTransaction) info.getScheduledTransaction();
    assertThat(transaction.getTopicId()).isEqualTo(infoTransaction.getTopicId());
    assertThat(transaction.getNodeAccountIds()).isEqualTo(infoTransaction.getNodeAccountIds());
    var scheduleSign = new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(testEnv.client);
    scheduleSign.sign(key2).execute(testEnv.client).getReceipt(testEnv.client);
    info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
    assertThat(info.executedAt).isNotNull();
    testEnv.close();
}
Also used : TopicCreateTransaction(com.hedera.hashgraph.sdk.TopicCreateTransaction) Var(com.google.errorprone.annotations.Var) ScheduleSignTransaction(com.hedera.hashgraph.sdk.ScheduleSignTransaction) KeyList(com.hedera.hashgraph.sdk.KeyList) Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) TopicMessageSubmitTransaction(com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with AccountCreateTransaction

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

the class ScheduleCreateIntegrationTest method canCreateWithSchedule.

@Test
@Disabled
@DisplayName("Can create schedule with schedule()")
void canCreateWithSchedule() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var transaction = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10));
    var tx = transaction.schedule();
    var response = tx.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) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

Example 10 with AccountCreateTransaction

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

the class TokenMintIntegrationTest method cannotMintTokensWhenSupplyKeyDoesNotSignTransaction.

@Test
@DisplayName("Cannot mint tokens when supply key does not sign transaction")
void cannotMintTokensWhenSupplyKeyDoesNotSignTransaction() 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(key).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenMintTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_SIGNATURE.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) 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