Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions tck/handlers/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from hiero_sdk_python.tokens.token_reject_transaction import TokenRejectTransaction
from hiero_sdk_python.tokens.token_revoke_kyc_transaction import TokenRevokeKycTransaction
from hiero_sdk_python.tokens.token_type import TokenType
from hiero_sdk_python.tokens.token_update_transaction import TokenUpdateTransaction
from hiero_sdk_python.tokens.token_wipe_transaction import TokenWipeTransaction
from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt
from tck.handlers.registry import rpc_method
Expand All @@ -52,6 +53,7 @@
PauseTokenParams,
RejectTokenParams,
RevokeTokenKycParams,
UpdateTokenParams,
WipeTokenParams,
)
from tck.response.token import (
Expand All @@ -69,6 +71,7 @@
PauseTokenResponse,
RejectTokenResponse,
RevokeTokenKycResponse,
UpdateTokenResponse,
WipeTokenResponse,
)
from tck.util.client_utils import get_client
Expand Down Expand Up @@ -781,6 +784,80 @@ def reject_token(params: RejectTokenParams) -> RejectTokenResponse:
)


def _build_update_token_transaction(params: UpdateTokenParams) -> TokenUpdateTransaction:
"""Build a TokenUpdateTransaction from TCK params."""
transaction = TokenUpdateTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)

if params.tokenId is not None:
transaction.set_token_id(TokenId.from_string(params.tokenId))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to remove the fail fast check for token id in the TokenUpdateTransaction _build_proto_body()


if params.name is not None:
transaction.set_token_name(params.name)

if params.symbol is not None:
transaction.set_token_symbol(params.symbol)

if params.treasuryAccountId is not None:
transaction.set_treasury_account_id(AccountId.from_string(params.treasuryAccountId))

if params.adminKey is not None:
transaction.set_admin_key(get_key_from_string(params.adminKey))

if params.kycKey is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also some tck tests pass a keyList with an empty list of keys, which is valid. however, current generate_key currently has this check:

if params.type in {KeyType.THRESHOLD_KEY, KeyType.LIST_KEY} and not params.keys:
        raise JsonRpcError.invalid_params_error(
            "invalid parameters: keys must be provided for keyList or thresholdKey types."
        )

if params.type in {KeyType.THRESHOLD_KEY, KeyType.LIST_KEY} and not params.keys:

since not params.keys is also True for an empty list, it raises an error for a valid input.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should check for the pramas.keys is None

transaction.set_kyc_key(get_key_from_string(params.kycKey))

if params.freezeKey is not None:
transaction.set_freeze_key(get_key_from_string(params.freezeKey))

if params.wipeKey is not None:
transaction.set_wipe_key(get_key_from_string(params.wipeKey))

if params.supplyKey is not None:
transaction.set_supply_key(get_key_from_string(params.supplyKey))

if params.feeScheduleKey is not None:
transaction.set_fee_schedule_key(get_key_from_string(params.feeScheduleKey))

if params.pauseKey is not None:
transaction.set_pause_key(get_key_from_string(params.pauseKey))

if params.metadataKey is not None:
transaction.set_metadata_key(get_key_from_string(params.metadataKey))

if params.memo is not None:
transaction.set_token_memo(params.memo)

if params.expirationTime is not None:
transaction.set_expiration_time(Timestamp(seconds=to_int(params.expirationTime), nanos=0))

if params.autoRenewAccountId is not None:
transaction.set_auto_renew_account_id(AccountId.from_string(params.autoRenewAccountId))

if params.autoRenewPeriod is not None:
transaction.set_auto_renew_period(Duration(seconds=to_int(params.autoRenewPeriod)))

if params.metadata is not None:
transaction.set_metadata(params.metadata.encode())

return transaction


@rpc_method("updateToken")
def update_token(params: UpdateTokenParams) -> UpdateTokenResponse:
"""Update a token using TCK updateToken parameters."""
client = get_client(params.sessionId)

transaction = _build_update_token_transaction(params)

if params.commonTransactionParams is not None:
params.commonTransactionParams.apply_common_params(transaction, client)

response = transaction.execute(client, wait_for_receipt=False)
receipt: TransactionReceipt = response.get_receipt(client, validate_status=True)

return UpdateTokenResponse(status=ResponseCode(receipt.status).name)


def _build_wipe_token_transaction(params: WipeTokenParams) -> TokenWipeTransaction:
"""Build a TokenWipeTransaction from TCK params."""

Expand Down
48 changes: 48 additions & 0 deletions tck/param/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,51 @@ def parse_json_params(cls, params: dict) -> WipeTokenParams:
sessionId=parse_session_id(params),
commonTransactionParams=parse_common_transaction_params(params),
)


@dataclass
class UpdateTokenParams(BaseTransactionParams):
"""Request parameters for the updateToken endpoint."""

tokenId: str | None = None
name: str | None = None
symbol: str | None = None
treasuryAccountId: str | None = None
adminKey: str | None = None
kycKey: str | None = None
freezeKey: str | None = None
wipeKey: str | None = None
supplyKey: str | None = None
feeScheduleKey: str | None = None
pauseKey: str | None = None
metadataKey: str | None = None
memo: str | None = None
expirationTime: str | None = None
autoRenewAccountId: str | None = None
autoRenewPeriod: str | None = None
metadata: str | None = None

@classmethod
def parse_json_params(cls, params: dict) -> UpdateTokenParams:
"""Parse JSON-RPC params into an UpdateTokenParams instance."""
return cls(
tokenId=params.get("tokenId"),
name=params.get("name"),
symbol=params.get("symbol"),
treasuryAccountId=params.get("treasuryAccountId"),
adminKey=params.get("adminKey"),
kycKey=params.get("kycKey"),
freezeKey=params.get("freezeKey"),
wipeKey=params.get("wipeKey"),
supplyKey=params.get("supplyKey"),
feeScheduleKey=params.get("feeScheduleKey"),
pauseKey=params.get("pauseKey"),
metadataKey=params.get("metadataKey"),
memo=params.get("memo"),
expirationTime=params.get("expirationTime"),
autoRenewAccountId=params.get("autoRenewAccountId"),
autoRenewPeriod=params.get("autoRenewPeriod"),
metadata=params.get("metadata"),
sessionId=parse_session_id(params),
commonTransactionParams=parse_common_transaction_params(params),
)
5 changes: 5 additions & 0 deletions tck/response/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@ class GetTokenInfoResponse:
@dataclass
class WipeTokenResponse(StatusOnlyResponse):
"""Response payload for wipeToken."""


@dataclass
class UpdateTokenResponse(StatusOnlyResponse):
"""Response payload for updateToken."""
Loading