Search in sources :

Example 36 with TokenCreateTransaction

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");
}
Also used : PublicKey(com.hedera.hashgraph.sdk.PublicKey) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 37 with TokenCreateTransaction

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);
}
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 38 with TokenCreateTransaction

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);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) 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)

Example 39 with TokenCreateTransaction

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);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) 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)

Example 40 with TokenCreateTransaction

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);
}
Also used : TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenBurnTransaction(com.hedera.hashgraph.sdk.TokenBurnTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)70 Test (org.junit.jupiter.api.Test)64 DisplayName (org.junit.jupiter.api.DisplayName)61 Hbar (com.hedera.hashgraph.sdk.Hbar)34 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)29 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)21 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)15 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)14 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)11 TokenInfoQuery (com.hedera.hashgraph.sdk.TokenInfoQuery)10 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)8 CustomFixedFee (com.hedera.hashgraph.sdk.CustomFixedFee)7 ArrayList (java.util.ArrayList)7 Var (com.google.errorprone.annotations.Var)6 TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)6 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)5 PublicKey (com.hedera.hashgraph.sdk.PublicKey)5 CustomFractionalFee (com.hedera.hashgraph.sdk.CustomFractionalFee)4 TokenId (com.hedera.hashgraph.sdk.TokenId)4 TokenNftInfoQuery (com.hedera.hashgraph.sdk.TokenNftInfoQuery)4