feat(token): Add getTokenInfo request and response models, including custom fee serialization#2400
Conversation
…custom fee serialization Signed-off-by: Ntege Daniel <danientege785@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds a new TCK JSON-RPC endpoint (getTokenInfo) to query token details via TokenInfoQuery, along with new request/response dataclasses and serialization helpers to return rich token metadata (keys, statuses, custom fees, etc.) in the TCK response shape.
Changes:
- Add
GetTokenInfoParamsrequest model forgetTokenInfoquery inputs. - Add
GetTokenInfoResponse(and nestedCustomFeeResponse) response models for rich token info output. - Implement
get_token_infohandler + serialization/mapping helpers for keys, enums, timestamps, and custom fees.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tck/response/token.py | Adds response dataclasses for getTokenInfo, including nested custom fee representation. |
| tck/param/token.py | Adds GetTokenInfoParams for the new query endpoint. |
| tck/handlers/token.py | Implements the getTokenInfo RPC handler and serialization helpers to map SDK TokenInfo into TCK response fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a ChangesgetTokenInfo endpoint
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant get_token_info
participant Hbar
participant TokenInfoQuery
participant HederaNetwork
participant GetTokenInfoResponse
Client->>get_token_info: GetTokenInfoParams(tokenId, queryPayment, maxQueryPayment)
get_token_info->>Hbar: Convert tinybars to Hbar
get_token_info->>TokenInfoQuery: Set token id and query-payment limits
get_token_info->>TokenInfoQuery: Execute query
TokenInfoQuery->>HederaNetwork: Request token information
HederaNetwork-->>TokenInfoQuery: Return TokenInfo
TokenInfoQuery-->>get_token_info: Return TokenInfo
get_token_info->>GetTokenInfoResponse: Map metadata and custom fees
get_token_info-->>Client: Return serialized response
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8aea9b34-ce52-42c0-8f41-03962353ab03
📒 Files selected for processing (3)
tck/handlers/token.pytck/param/token.pytck/response/token.py
…st pauseStatus type in response models Signed-off-by: Ntege Daniel <danientege785@gmail.com>
|
Hi, this is WorkflowBot.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hiero_sdk_python/query/token_info_query.py (1)
55-65: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winStale docstring:
_make_requestno longer raisesValueErrorfor missingtoken_id.The docstring still states
Raises: ValueError: If the token ID is not set.(Line 56), but the implementation now silently skips settingtokenwhenself.token_idisNone(Line 64-65). Per theTokenGetInfoQueryproto contract, an unset/invalid token results in a server-sideINVALID_TOKEN_IDresponse, so allowing the request through is protocol-aligned — just update the docstring to match.📝 Suggested docstring fix
Returns: query_pb2.Query: The protobuf query message. Raises: - ValueError: If the token ID is not set. Exception: If any other error occurs during request construction.As per path instructions for
src/hiero_sdk_python/query/**/*.py, "_make_request()MUST: Validate all required identifiers"; here validation is intentionally deferred to the network perhedera-protobufs/services/token_get_info.proto, but the docstring should reflect the actual behavior.Source: Path instructions
♻️ Duplicate comments (1)
tck/handlers/token.py (1)
622-639: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winMissing session-not-found guard persists.
get_client(params.sessionId)at Line 625 can returnNone; there's still no check before it's used to execute the query at Line 638. This was already flagged in a prior review round for this same handler.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 97949b8c-d09d-4d6c-a98f-96a4ac67a2c7
📒 Files selected for processing (3)
src/hiero_sdk_python/query/token_info_query.pytck/handlers/token.pytck/response/token.py
…st pauseStatus type in response models Signed-off-by: Ntege Daniel <danientege785@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #2400 +/- ##
==========================================
- Coverage 95.01% 94.98% -0.03%
==========================================
Files 163 163
Lines 10465 10464 -1
==========================================
- Hits 9943 9939 -4
- Misses 522 525 +3 🚀 New features to boost your workflow:
|
aceppaluni
left a comment
There was a problem hiding this comment.
GIven the amount of mapping helpers _map_pause_status(), _map_token_type()
and _map_supply_type(), and having default_freeze = ... and default_kyc = ... handled inline,
Should we move freeze/KYC into _map_freeze_status() and _map_kyc_status()
Signed-off-by: Ntege Daniel <danientege785@gmail.com>
exploreriii
left a comment
There was a problem hiding this comment.
Might be a couple inconsistencies in the spec still
https://hiero-ledger.github.io/hiero-sdk-tck/test-specifications/token-service
Signed-off-by: Ntege Daniel <danientege785@gmail.com>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
tck/handlers/token.py (1)
626-643: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winGuard against
Noneclient before executing the query.
get_client(params.sessionId)can returnNone, andquery.execute(None)will raise anAttributeErrorthatdispatchturns into a genericinternal_errorinstead of a clear "session not found" response. This was flagged in a previous review and remains unaddressed.🛡️ Proposed fix
`@rpc_method`("getTokenInfo") def get_token_info(params: GetTokenInfoParams) -> GetTokenInfoResponse: """Query token info using TCK getTokenInfo parameters.""" client = get_client(params.sessionId) + if client is None: + raise JsonRpcError.invalid_params_error(data=f"Session not found: {params.sessionId}") query = TokenInfoQuery().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: fb819046-b3ba-433e-af7b-feebc671724b
📒 Files selected for processing (3)
tck/handlers/registry.pytck/handlers/token.pytests/tck/handlers_test.py
|
is this ready to review @danielmarv ? |
|
Yeah |
|
👋 Hi @danielmarv! Great work completing a Advanced issue! 🎉 Thanks for your contribution! 🚀 Here are some issues you might want to explore next:
🌟 Stay connected: Happy coding! 🚀 |
Description:
This pull request adds support for querying detailed token information through a new
getTokenInfoendpoint in the TCK (Test Client Kit). It introduces new parameter and response classes, serialization helpers for token-related data, and updates the handler logic to process and return comprehensive token details, including custom fees and key metadata.New endpoint and data structures:
GetTokenInfoParamsandGetTokenInfoResponsedataclasses to define the request and response payloads for the newgetTokenInfoRPC method, including nestedCustomFeeResponsefor detailed custom fee information. [1] [2]Handler logic and serialization:
get_token_infohandler intck/handlers/token.py, which usesTokenInfoQueryto fetch token details and serializes the result into the new response format, including comprehensive mapping and serialization of enums, keys, custom fees, and metadata.Dependency and import updates:
tck/handlers/token.pyto include all necessary classes and enums for token info querying and serialization, such asTokenInfo,TokenPauseStatus,TokenKycStatus, andTokenFreezeStatus. [1] [2] [3] [4]These changes collectively enable the TCK to support rich token info queries, facilitating more thorough testing and validation of token-related features.
Related issue(s):
Fixes #2399
Notes for reviewer:
Checklist