Search in sources :

Example 1 with TokenUpdateTransaction

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

use of com.hedera.hashgraph.sdk.TokenUpdateTransaction in project hedera-mirror-node by hashgraph.

the class TokenClient method updateTokenTreasury.

public NetworkTransactionResponse updateTokenTreasury(TokenId tokenId, ExpandedAccountId newTreasuryId) {
    AccountId treasuryAccountId = newTreasuryId.getAccountId();
    String memo = getMemo("Update token");
    TokenUpdateTransaction tokenUpdateTransaction = new TokenUpdateTransaction().setTokenId(tokenId).setTokenMemo(memo).setTreasuryAccountId(treasuryAccountId).setTransactionMemo(memo);
    KeyList keyList = KeyList.of(newTreasuryId.getPrivateKey());
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(tokenUpdateTransaction, keyList);
    log.debug("Updated token {} treasury account {}.", tokenId, treasuryAccountId);
    return networkTransactionResponse;
}
Also used : AccountId(com.hedera.hashgraph.sdk.AccountId) ExpandedAccountId(com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) KeyList(com.hedera.hashgraph.sdk.KeyList) TokenUpdateTransaction(com.hedera.hashgraph.sdk.TokenUpdateTransaction)

Example 3 with TokenUpdateTransaction

use of com.hedera.hashgraph.sdk.TokenUpdateTransaction in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionSupplierTest method createWithCustomData.

@Test
void createWithCustomData() {
    Duration autoRenewPeriod = Duration.ofSeconds(1);
    Instant expirationTime = Instant.now().plus(1, ChronoUnit.DAYS);
    PublicKey key = PrivateKey.generate().getPublicKey();
    TokenUpdateTransactionSupplier tokenUpdateTransactionSupplier = new TokenUpdateTransactionSupplier();
    tokenUpdateTransactionSupplier.setAdminKey(key.toString());
    tokenUpdateTransactionSupplier.setAutoRenewPeriod(autoRenewPeriod);
    tokenUpdateTransactionSupplier.setMaxTransactionFee(1);
    tokenUpdateTransactionSupplier.setSymbol("TEST");
    tokenUpdateTransactionSupplier.setTokenId(TOKEN_ID.toString());
    tokenUpdateTransactionSupplier.setTreasuryAccountId(ACCOUNT_ID.toString());
    tokenUpdateTransactionSupplier.setTokenId(TOKEN_ID.toString());
    TokenUpdateTransaction actual = tokenUpdateTransactionSupplier.get();
    assertThat(actual).returns(key, TokenUpdateTransaction::getAdminKey).returns(ACCOUNT_ID, TokenUpdateTransaction::getAutoRenewAccountId).returns(autoRenewPeriod, TokenUpdateTransaction::getAutoRenewPeriod).returns(null, TokenUpdateTransaction::getExpirationTime).returns(key, TokenUpdateTransaction::getFeeScheduleKey).returns(key, TokenUpdateTransaction::getFreezeKey).returns(key, TokenUpdateTransaction::getKycKey).returns(ONE_TINYBAR, TokenUpdateTransaction::getMaxTransactionFee).returns(key, TokenUpdateTransaction::getSupplyKey).returns(TOKEN_ID, TokenUpdateTransaction::getTokenId).returns("TEST_name", TokenUpdateTransaction::getTokenName).returns("TEST", TokenUpdateTransaction::getTokenSymbol).returns(ACCOUNT_ID, TokenUpdateTransaction::getTreasuryAccountId).returns(key, TokenUpdateTransaction::getWipeKey).extracting(TokenUpdateTransaction::getTokenMemo, STRING).contains("Mirror node updated test token");
}
Also used : PublicKey(com.hedera.hashgraph.sdk.PublicKey) Instant(java.time.Instant) Duration(java.time.Duration) TokenUpdateTransaction(com.hedera.hashgraph.sdk.TokenUpdateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 4 with TokenUpdateTransaction

use of com.hedera.hashgraph.sdk.TokenUpdateTransaction in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionSupplierTest method createWithExpiration.

@Test
void createWithExpiration() {
    TokenUpdateTransactionSupplier tokenUpdateTransactionSupplier = new TokenUpdateTransactionSupplier();
    tokenUpdateTransactionSupplier.setTokenId(TOKEN_ID.toString());
    tokenUpdateTransactionSupplier.setExpirationTime(Instant.MAX);
    TokenUpdateTransaction actual = tokenUpdateTransactionSupplier.get();
    assertThat(actual).returns(null, TokenUpdateTransaction::getAdminKey).returns(null, TokenUpdateTransaction::getAutoRenewAccountId).returns(null, TokenUpdateTransaction::getAutoRenewPeriod).returns(Instant.MAX, TokenUpdateTransaction::getExpirationTime).returns(null, TokenUpdateTransaction::getFeeScheduleKey).returns(null, TokenUpdateTransaction::getFreezeKey).returns(null, TokenUpdateTransaction::getKycKey).returns(MAX_TRANSACTION_FEE_HBAR, TokenUpdateTransaction::getMaxTransactionFee).returns(null, TokenUpdateTransaction::getSupplyKey).returns(TOKEN_ID, TokenUpdateTransaction::getTokenId).returns("HMNT_name", TokenUpdateTransaction::getTokenName).returns("HMNT", TokenUpdateTransaction::getTokenSymbol).returns(null, TokenUpdateTransaction::getTreasuryAccountId).returns(null, TokenUpdateTransaction::getWipeKey).extracting(TokenUpdateTransaction::getTokenMemo, STRING).contains("Mirror node updated test token");
}
Also used : TokenUpdateTransaction(com.hedera.hashgraph.sdk.TokenUpdateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 5 with TokenUpdateTransaction

use of com.hedera.hashgraph.sdk.TokenUpdateTransaction in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionSupplier method get.

@Override
public TokenUpdateTransaction get() {
    TokenUpdateTransaction tokenUpdateTransaction = new TokenUpdateTransaction().setMaxTransactionFee(Hbar.fromTinybars(maxTransactionFee)).setTokenMemo(Utility.getMemo("Mirror node updated test token")).setTokenName(symbol + "_name").setTokenSymbol(symbol).setTokenId(TokenId.fromString(tokenId));
    if (adminKey != null) {
        PublicKey key = PublicKey.fromString(adminKey);
        tokenUpdateTransaction.setAdminKey(key).setFeeScheduleKey(key).setFreezeKey(key).setKycKey(key).setSupplyKey(key).setWipeKey(key);
    }
    if (treasuryAccountId != null) {
        AccountId treastury = AccountId.fromString(treasuryAccountId);
        tokenUpdateTransaction.setAutoRenewAccountId(treastury).setTreasuryAccountId(treastury);
    }
    if (expirationTime != null) {
        tokenUpdateTransaction.setExpirationTime(expirationTime);
    } else {
        tokenUpdateTransaction.setAutoRenewPeriod(autoRenewPeriod);
    }
    return tokenUpdateTransaction;
}
Also used : AccountId(com.hedera.hashgraph.sdk.AccountId) PublicKey(com.hedera.hashgraph.sdk.PublicKey) TokenUpdateTransaction(com.hedera.hashgraph.sdk.TokenUpdateTransaction)

Aggregations

TokenUpdateTransaction (com.hedera.hashgraph.sdk.TokenUpdateTransaction)8 Test (org.junit.jupiter.api.Test)5 PublicKey (com.hedera.hashgraph.sdk.PublicKey)3 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)3 AccountId (com.hedera.hashgraph.sdk.AccountId)2 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)2 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Var (com.google.errorprone.annotations.Var)1 Hbar (com.hedera.hashgraph.sdk.Hbar)1 KeyList (com.hedera.hashgraph.sdk.KeyList)1 TokenInfoQuery (com.hedera.hashgraph.sdk.TokenInfoQuery)1 ExpandedAccountId (com.hedera.mirror.test.e2e.acceptance.props.ExpandedAccountId)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1