Search in sources :

Example 6 with Hbar

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

the class TokenInfoIntegrationTest method canQueryTokenInfoWhenTokenIsCreatedWithMinimalProperties.

@Test
@DisplayName("Can query token with minimal properties")
void canQueryTokenInfoWhenTokenIsCreatedWithMinimalProperties() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount(new Hbar(10));
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    var info = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client);
    assertThat(info.tokenId).isEqualTo(tokenId);
    assertThat(info.name).isEqualTo("ffff");
    assertThat(info.symbol).isEqualTo("F");
    assertThat(info.decimals).isEqualTo(0);
    assertThat(info.totalSupply).isEqualTo(0);
    assertThat(info.treasuryAccountId).isEqualTo(testEnv.operatorId);
    assertThat(info.adminKey).isNull();
    assertThat(info.freezeKey).isNull();
    assertThat(info.wipeKey).isNull();
    assertThat(info.kycKey).isNull();
    assertThat(info.supplyKey).isNull();
    assertThat(info.defaultFreezeStatus).isNull();
    assertThat(info.defaultKycStatus).isNull();
    assertThat(info.tokenType).isEqualTo(TokenType.FUNGIBLE_COMMON);
    assertThat(info.supplyType).isEqualTo(TokenSupplyType.INFINITE);
    testEnv.close();
}
Also used : TokenInfoQuery(com.hedera.hashgraph.sdk.TokenInfoQuery) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with Hbar

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

the class TokenUpdateIntegrationTest method cannotUpdateImmutableToken.

@Test
@DisplayName("Cannot update immutable token")
void cannotUpdateImmutableToken() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount(new Hbar(10));
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setFreezeDefault(false).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenUpdateTransaction().setTokenId(tokenId).setTokenName("aaaa").setTokenSymbol("A").execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString());
    testEnv.close();
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenUpdateTransaction(com.hedera.hashgraph.sdk.TokenUpdateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with Hbar

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

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

use of com.hedera.hashgraph.sdk.Hbar 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)

Aggregations

Hbar (com.hedera.hashgraph.sdk.Hbar)106 Test (org.junit.jupiter.api.Test)77 DisplayName (org.junit.jupiter.api.DisplayName)75 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)62 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)34 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)31 Client (com.hedera.hashgraph.sdk.Client)22 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)22 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)19 Var (com.google.errorprone.annotations.Var)18 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)16 AccountId (com.hedera.hashgraph.sdk.AccountId)15 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)13 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)13 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)12 AccountInfoQuery (com.hedera.hashgraph.sdk.AccountInfoQuery)11 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)11 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)11 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)9 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)9