use of com.hedera.hashgraph.sdk.TokenCreateTransaction in project hedera-mirror-node by hashgraph.
the class TokenCreateTransactionSupplierTest method createWithNonFungibleData.
@Test
void createWithNonFungibleData() {
PublicKey key = PrivateKey.generate().getPublicKey();
TokenCreateTransactionSupplier tokenCreateTransactionSupplier = new TokenCreateTransactionSupplier();
tokenCreateTransactionSupplier.setTreasuryAccountId(ACCOUNT_ID.toString());
tokenCreateTransactionSupplier.setType(TokenType.NON_FUNGIBLE_UNIQUE);
TokenCreateTransaction actual = tokenCreateTransactionSupplier.get();
assertThat(actual).returns(null, TokenCreateTransaction::getAdminKey).returns(ACCOUNT_ID, TokenCreateTransaction::getAutoRenewAccountId).returns(0, TokenCreateTransaction::getDecimals).returns(null, TokenCreateTransaction::getFeeScheduleKey).returns(false, TokenCreateTransaction::getFreezeDefault).returns(null, TokenCreateTransaction::getFreezeKey).returns(0L, TokenCreateTransaction::getInitialSupply).returns(null, TokenCreateTransaction::getKycKey).returns(0L, TokenCreateTransaction::getMaxSupply).returns(MAX_TRANSACTION_FEE_HBAR, TokenCreateTransaction::getMaxTransactionFee).returns(null, TokenCreateTransaction::getSupplyKey).returns(TokenSupplyType.INFINITE, TokenCreateTransaction::getSupplyType).returns(TokenType.NON_FUNGIBLE_UNIQUE, TokenCreateTransaction::getTokenType).returns(ACCOUNT_ID, TokenCreateTransaction::getTreasuryAccountId).returns(null, TokenCreateTransaction::getWipeKey).extracting(TokenCreateTransaction::getTokenMemo, STRING).contains("Mirror node created test token");
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction 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);
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction in project hedera-sdk-java by hashgraph.
the class TokenAssociateIntegrationTest method cannotAssociateAccountWhenAccountDoesNotSignTransaction.
@Test
@DisplayName("Cannot associate account with tokens when account does not sign transaction")
void cannotAssociateAccountWhenAccountDoesNotSignTransaction() 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);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INVALID_SIGNATURE.toString());
testEnv.close(tokenId, accountId, key);
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction in project hedera-sdk-java by hashgraph.
the class TokenAssociateIntegrationTest method canAssociateAccountWithToken.
@Test
@DisplayName("Can associate account with token")
void canAssociateAccountWithToken() 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);
testEnv.close(tokenId, accountId, key);
}
use of com.hedera.hashgraph.sdk.TokenCreateTransaction in project hedera-sdk-java by hashgraph.
the class TokenBurnIntegrationTest method cannotBurnTokensWhenSupplyKeyDoesNotSignTransaction.
@Test
@DisplayName("Cannot burn tokens when supply key does not sign transaction")
void cannotBurnTokensWhenSupplyKeyDoesNotSignTransaction() throws Exception {
var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
var response = 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(PrivateKey.generate()).setFreezeDefault(false).execute(testEnv.client);
var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new TokenBurnTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INVALID_SIGNATURE.toString());
testEnv.close(tokenId);
}
Aggregations