Skip to content

feat(tck): add token grant/revoke KYC handlers#2433

Merged
manishdait merged 4 commits into
hiero-ledger:mainfrom
iron-prog:fix/tck-token-kyc-handlers
Jul 15, 2026
Merged

feat(tck): add token grant/revoke KYC handlers#2433
manishdait merged 4 commits into
hiero-ledger:mainfrom
iron-prog:fix/tck-token-kyc-handlers

Conversation

@iron-prog

@iron-prog iron-prog commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Description:

Add TCK JSON-RPC support for grantTokenKyc and revokeTokenKyc.

  • Add grantTokenKyc TCK handler
  • Add revokeTokenKyc TCK handler
  • Add request parameter models
  • Add response models
  • Follow the existing token handler implementation pattern

Related issue(s):

Fixes #2422

Notes for reviewer:

Both TokenGrantKycTransaction and TokenRevokeKycTransaction are already implemented in the Python SDK. This PR wires them into the TCK by adding the corresponding JSON-RPC handlers, request parameter models, and response models, following the existing implementation used by other token operations.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@iron-prog
iron-prog requested a review from a team as a code owner July 12, 2026 03:55
@iron-prog
iron-prog requested a review from exploreriii July 12, 2026 03:55
@iron-prog

Copy link
Copy Markdown
Contributor Author

While working on this issue, I noticed both handlers were missing from the TCK. Since the implementations are analogous and the SDK support already exists, I included both to keep the TCK handlers consistent.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 648d5723-4858-4d3c-9e43-138e1dfd7477

📥 Commits

Reviewing files that changed from the base of the PR and between 5d01e66 and 205a8e8.

📒 Files selected for processing (7)
  • src/hiero_sdk_python/tokens/token_grant_kyc_transaction.py
  • src/hiero_sdk_python/tokens/token_revoke_kyc_transaction.py
  • tck/handlers/token.py
  • tck/param/token.py
  • tck/response/token.py
  • tests/unit/token_grant_kyc_transaction_test.py
  • tests/unit/token_revoke_kyc_transaction_test.py

Walkthrough

Adds grantTokenKyc and revokeTokenKyc TCK RPC operations, request and response models, optional identifier handling in SDK transaction bodies, token handler execution, and unit tests for missing identifiers.

Changes

Token KYC Operations

Layer / File(s) Summary
KYC request and response contracts
tck/param/token.py, tck/response/token.py
Adds parameter dataclasses for token and account identifiers and status-only response models for both operations.
Optional KYC transaction identifiers
src/hiero_sdk_python/tokens/token_*_kyc_transaction.py, tests/unit/token_*_kyc_transaction_test.py
Builds grant and revoke KYC protobuf bodies with only present identifiers, with tests covering omitted fields.
KYC transaction handlers
tck/handlers/token.py
Adds transaction builders and RPC handlers, applies common transaction parameters, executes transactions, validates receipt statuses, and returns responses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant JSONRPC
  participant TokenHandlers
  participant HederaSDK
  participant Receipt
  JSONRPC->>TokenHandlers: grantTokenKyc or revokeTokenKyc parameters
  TokenHandlers->>HederaSDK: build transaction with optional tokenId and accountId
  TokenHandlers->>HederaSDK: execute transaction
  HederaSDK->>Receipt: obtain receipt
  Receipt-->>TokenHandlers: transaction status
  TokenHandlers-->>JSONRPC: status-only response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding token KYC grant/revoke handlers.
Description check ✅ Passed The description matches the changeset by describing the new TCK grant/revoke KYC handlers, params, and responses.
Linked Issues check ✅ Passed The PR implements revokeTokenKyc via a new JSON-RPC handler and supporting models, satisfying issue #2422.
Out of Scope Changes check ✅ Passed The SDK and test changes support the new KYC handlers and do not appear unrelated to the issue scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #2422

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review labels Jul 12, 2026
@iron-prog
iron-prog requested a review from a team as a code owner July 12, 2026 08:19

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f211aad9-41fc-47b3-9c96-27e75b43d186

📥 Commits

Reviewing files that changed from the base of the PR and between aa45186 and a436cb8.

📒 Files selected for processing (1)
  • tests/tck/token_kyc_handlers_test.py

Comment thread tests/tck/token_kyc_handlers_test.py Outdated
@iron-prog

Copy link
Copy Markdown
Contributor Author

While testing, I noticed two pre-existing issues unrelated to this PR: (1) get_client() silently returns None for an unknown sessionId, leading to a misleading downstream error, and (2) the clear_handlers test fixture can affect other tests depending on collection order. I kept this PR focused on the KYC handlers, but I'm happy to open follow-up issues for these if that would be helpful

@Mounil2005

Copy link
Copy Markdown
Contributor

Thanks for wiring these up, the param/response models and builder pattern look correct and match the existing freezeToken/pauseToken handlers.

Before moving ahead, could you confirm whether you ran the hiero-sdk-tck conformance suite locally against this server for grantTokenKyc/revokeTokenKyc? Per the test spec, each method has 17 test cases....13 covering tokenId (invalid, empty, missing, deleted token, unsigned/wrong-key signatures, no KYC key, not associated, paused token, frozen account) and 4 covering accountId (nonexistent, empty, missing, deleted account). Matching the existing pattern and passing type checks doesn't guarantee those pass.

Comment thread tck/handlers/token.py
@iron-prog

Copy link
Copy Markdown
Contributor Author

thanks for the thorough review and for pointing out the distinction. I only ran the repository's local pytest suite , which covers parameter parsing, transaction building, mocked end-to-end dispatch, and error handling. I haven't yet run the full hiero-sdk-tck conformance suite against a local node or testnet, so I can't yet confirm all 17 TCK scenarios pass. I'll set up hiero-local-node, run the TCK client for grantTokenKyc and revokeTokenKyc, and update this thread with the results. If any scenarios fail, I'll address them in this PR. One possible issue is that the JSON-RPC layer currently wraps some exceptions into a generic internal error, which could affect TCK expectations even if the underlying transaction is correct. I'll note whether that's the cause in my follow-up.

Comment thread tck/handlers/token.py
@Mounil2005

Copy link
Copy Markdown
Contributor

thanks for the thorough review and for pointing out the distinction. I only ran the repository's local pytest suite , which covers parameter parsing, transaction building, mocked end-to-end dispatch, and error handling. I haven't yet run the full hiero-sdk-tck conformance suite against a local node or testnet, so I can't yet confirm all 17 TCK scenarios pass. I'll set up hiero-local-node, run the TCK client for grantTokenKyc and revokeTokenKyc, and update this thread with the results. If any scenarios fail, I'll address them in this PR. One possible issue is that the JSON-RPC layer currently wraps some exceptions into a generic internal error, which could affect TCK expectations even if the underlying transaction is correct. I'll note whether that's the cause in my follow-up.

Thanks for contributing this, @iron-prog

And appreciate the honest update on testing that's exactly the right way to handle it. Thanks for being upfront about where things stand instead of just checking the box, and for taking the extra step to spin up hiero-local-node and run the actual TCK client rather than stopping at the unit tests.

Your hunch about the generic internal-error wrapping is worth chasing, if the TCK driver expects a specific response code back and the JSON-RPC layer is flattening it to a generic internal error, that would explain a failure even when the underlying transaction logic is correct. Good instinct to check that first.

No rush take the time you need to run it properly, and just ping the thread when you've got results.

@iron-prog

Copy link
Copy Markdown
Contributor Author

Quick update: I managed to get the TCK running locally against testnet (I tried with Docker but due limited hardware it's becomes problem to me /local-node setup since I was running into unrelated environment issues).
While testing, I found two things that seem unrelated to this PR:

  1. setup/setOperator in tck/handlers/sdk.py currently uses PrivateKey.from_string(). With an ECDSA testnet account, that resulted in INVALID_SIGNATURE on every transaction until I switched to PrivateKey.from_string_ecdsa() locally. I'll open a separate issue with a minimal repro.

  2. Network-level errors (ReceiptStatusError/PrecheckError) correctly propagate the Hedera status via error.data.status, but locally raised validation errors (for example, a empty tokenId) are still wrapped as a generic Internal error. That also looks like a separate issue rather than something introduced by this PR.

With the ECDSA workaround applied locally, I was able to verify that grantTokenKyc behaves as expected against testnet (for example, returning INVALID_TOKEN_ID for an invalid token).
I'm still working through the full 13+4 TCK scenario run. Right now I'm hitting what looks like an unrelated stability issue in my local setup, so I didn't want to wait before posting an update. I'll keep digging and update this thread once I have a clean run or identify the root cause.

@aceppaluni

Copy link
Copy Markdown
Contributor

@iron-prog Thank you for the update!

Going to convert this to draft while the work is still going.

@aceppaluni
aceppaluni marked this pull request as draft July 13, 2026 17:05

@manishdait manishdait left a comment

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.

@iron-prog, Thanks for the PR. added some requested changes :)

Comment thread tests/tck/token_kyc_handlers_test.py Outdated
Comment thread tck/handlers/token.py
@iron-prog
iron-prog force-pushed the fix/tck-token-kyc-handlers branch from 8578522 to bf5d07d Compare July 14, 2026 04:55
@iron-prog

Copy link
Copy Markdown
Contributor Author

@manishdait I managed to run the full TokenGrantKycTransaction/TokenRevokeKycTransaction TCK suite against testnet.
28/32 scenarios are passing, including all of the cases this change is meant to address. In particular, missing tokenId/accountId now return INVALID_TOKEN_ID/INVALID_ACCOUNT_ID from the network instead of a generic internal error. The deleted token, wrong signature, paused, and frozen scenarios are all passing as well.
The remaining 4 failures are all in verifyTokenKyc. They appear to be timing out while waiting for mirror-node confirmation (30s Mocha timeout vs. ~20s retry budget). I saw the same behavior with two different testnet accounts, including a brand-new one, which makes me think this is related to testnet mirror-node propagation rather than this change itself. I also queried the mirror node directly and confirmed the KYC status is updated correctly (kyc_status:GRANTED).
I'll keep looking into it if it's useful, but It did looks like an external timing issue.

@manishdait

manishdait commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@iron-prog, that happen when we use the testnet for the tck test. I can verify the changes against solo. once you address the changes.

Comment thread src/hiero_sdk_python/tokens/token_grant_kyc_transaction.py Outdated
Comment thread src/hiero_sdk_python/tokens/token_revoke_kyc_transaction.py Outdated
Comment thread tck/handlers/token.py Outdated
@iron-prog
iron-prog force-pushed the fix/tck-token-kyc-handlers branch from bf5d07d to 5d01e66 Compare July 14, 2026 13:56
@iron-prog
iron-prog marked this pull request as ready for review July 14, 2026 13:59
@aceppaluni aceppaluni added the status: update branch developer needs to click update branch label Jul 14, 2026
aceppaluni
aceppaluni previously approved these changes Jul 14, 2026
Comment thread tck/handlers/token.py Outdated
@github-actions github-actions Bot added queue:maintainers PR awaiting maintainer final review and removed queue:junior-committer PR awaiting initial quality review labels Jul 14, 2026
Signed-off-by: iron-prog <dt915725@gmail.com>
…on-building helpers, full

end-to-end dispatch against a mocked network, and robustness checks for
unknown sessionId / wrong-type params (confirmed against freezeToken as
a control - pre-existing TCK-layer behavior)

Signed-off-by: iron-prog <dt915725@gmail.com>
Signed-off-by: iron-prog <dt915725@gmail.com>
Signed-off-by: iron-prog <dt915725@gmail.com>
@iron-prog
iron-prog force-pushed the fix/tck-token-kyc-handlers branch from 5d01e66 to 205a8e8 Compare July 15, 2026 00:52
@github-actions github-actions Bot added queue:junior-committer PR awaiting initial quality review and removed queue:maintainers PR awaiting maintainer final review labels Jul 15, 2026
@github-actions

Copy link
Copy Markdown

Hello, this is the OfficeHourBot.

This is a reminder that the Hiero Python SDK Office Hours will begin in approximately 3 hours and 28 minutes (14:00 UTC).

This session provides an opportunity to ask questions regarding this Pull Request.

Details:

Disclaimer: This is an automated reminder. Please verify the schedule here for any changes.

From,
The Python SDK Team

@danielmarv danielmarv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@manishdait manishdait left a comment

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.

lgtm

@github-actions github-actions Bot added queue:committers PR awaiting committer technical review and removed queue:junior-committer PR awaiting initial quality review labels Jul 15, 2026
@github-actions github-actions Bot added approved Issue has been approved by team member Good First Issue Issues which are ideal for a first time or new project contributor. labels Jul 15, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2433   +/-   ##
=======================================
  Coverage   94.99%   94.99%           
=======================================
  Files         164      164           
  Lines       10447    10449    +2     
=======================================
+ Hits         9924     9926    +2     
  Misses        523      523           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added status: ready-to-merge PR has 1+ maintainer and 2+ total approvals, ready to merge and removed queue:committers PR awaiting committer technical review labels Jul 15, 2026
@manishdait
manishdait merged commit 1b15756 into hiero-ledger:main Jul 15, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown

👋 Hi @iron-prog! Great work completing a Good First Issue issue! 🎉

Thanks for your contribution! 🚀

Here are some issues you might want to explore next:

🌟 Stay connected:

Happy coding! 🚀
— Hiero Python SDK Team

@iron-prog
iron-prog deleted the fix/tck-token-kyc-handlers branch July 15, 2026 13:48
@MonaaEid MonaaEid added this to the v0.2.9 milestone Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Issue has been approved by team member Good First Issue Issues which are ideal for a first time or new project contributor. open to community review PR is open for community review and feedback status: ready-to-merge PR has 1+ maintainer and 2+ total approvals, ready to merge status: update branch developer needs to click update branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(tck): implement revokeTokenKyc JSON-RPC method

7 participants