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();
}
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();
}
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);
}
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);
}
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();
}
Aggregations