Skip to content

[Intermediate]: Implement contractInfoQuery in the TCK contract service #1381

@rwalworth

Description

@rwalworth

🛠️ Intermediate Issue

This issue is a great fit for contributors who are ready to own a solution end-to-end.

Intermediate Issues involve exploring existing patterns, reasoning about trade-offs, and choosing an implementation approach with confidence. You'll navigate multiple related files and explain your decisions in review — the implementation details are yours to work out.

Important

Prerequisite: You must have completed at least 3 Beginner Issues in this repository before being assigned. The /assign bot enforces this automatically.


👾 Description of the Task

The Hiero C++ SDK TCK server does not yet implement the contractInfoQuery JSON-RPC method. This method is required by the TCK test suite to verify that the SDK can correctly retrieve full metadata about a deployed smart contract — including its admin key, staking info, expiration time, memo, and other properties.

This is the most field-rich of the contract query endpoints. The response must map all ContractInfo member fields to their expected JSON keys as defined by the TCK test suite.

The TCK server exposes a JSON-RPC interface that maps incoming method calls to SDK transactions and queries. The contract service scaffolding (ContractService.h, ContractService.cc) either already exists (from the createContract issue) or needs to be created following the same pattern as AccountService.

Relevant files to create:

src/tck/include/contract/params/ContractInfoQueryParams.h

Relevant files to modify:

src/tck/include/contract/ContractService.h
src/tck/src/contract/ContractService.cc
src/tck/src/TckServer.cc

Reference SDK classes:

src/sdk/main/include/ContractInfoQuery.h
src/sdk/main/include/ContractInfo.h

💡 Proposed Approach

Follow the query pattern established in AccountService::getAccountInfo — it is the closest existing parallel, since getAccountInfo also returns a rich info object with nested staking info, keys, and optional fields.

The main implementation challenge is correctly mapping all ContractInfo fields to their expected JSON keys. Investigate:

  • How mAdminKey (a std::shared_ptr<Key>) should be serialized to a string
  • How mStakingInfo should be serialized (it is a nested struct)
  • Which fields are optional and how to handle their absence in the response
  • How mContractAccountId (EVM address) should be formatted

Review the TCK test file to understand exactly which response keys are asserted and in what format before writing the JSON construction.

If ContractService.h and ContractService.cc do not yet exist, create them first following the pattern of AccountService.h and AccountService.cc, and ensure ContractService.cc is listed in src/tck/CMakeLists.txt.


👩‍💻 Implementation Steps

  • Check whether src/tck/include/contract/ContractService.h and src/tck/src/contract/ContractService.cc already exist
    • If not, create them following the pattern of AccountService.h and AccountService.cc, and add src/contract/ContractService.cc to src/tck/CMakeLists.txt
  • Read src/sdk/main/include/ContractInfo.h to understand all member fields and their types
  • Read src/tck/src/account/AccountService.cc (getAccountInfo) to understand how complex info objects are mapped to JSON responses in the TCK
  • Review the TCK test file (src/tests/contract-service/test-contract-info-query.ts in the hiero-sdk-tck repo) to confirm the exact expected JSON response keys and value formats
  • Create src/tck/include/contract/params/ContractInfoQueryParams.h with the following optional fields:
    • mContractId (std::optional<std::string>) — JSON key "contractId"
    • mMaxQueryPayment (std::optional<std::string>) — JSON key "maxQueryPayment" (tinybars as string)
    • mQueryPayment (std::optional<std::string>) — JSON key "queryPayment" (tinybars as string)
  • Add contractInfoQuery declaration to src/tck/include/contract/ContractService.h
  • Implement contractInfoQuery in src/tck/src/contract/ContractService.cc:
    • Construct a ContractInfoQuery
    • Set setGrpcDeadline(SdkClient::DEFAULT_TCK_REQUEST_TIMEOUT)
    • Apply mContractId, mMaxQueryPayment, mQueryPayment if present
    • Execute the query: ContractInfo info = query.execute(SdkClient::getClient())
    • Build and return the JSON response, mapping all relevant ContractInfo fields:
      • contractId, accountId, contractAccountId (EVM address)
      • adminKey (investigate correct serialization for optional shared_ptr)
      • expirationTime, autoRenewPeriod, autoRenewAccountId
      • storage, memo, balance, isDeleted
      • maxAutomaticTokenAssociations, ledgerId
      • stakingInfo as a nested JSON object
  • Add includes, addMethod call, and explicit template instantiation for ContractInfoQueryParams to src/tck/src/TckServer.cc
  • Build the project:
    cmake --preset linux-x64-debug && cmake --build --preset linux-x64-debug
  • Confirm the TCK server binary compiles and the new method is reachable
  • Open a pull request with the change

✔️ Acceptance Criteria

  • ContractInfoQueryParams.h is created following the established params pattern
  • contractInfoQuery is declared in ContractService.h and implemented in ContractService.cc
  • contractInfoQuery is registered in TckServer.cc with its explicit template instantiation
  • The TCK server compiles without errors or warnings introduced by this change
  • All ContractInfo fields are correctly mapped to their expected JSON keys and formats
  • Optional fields (e.g., adminKey, autoRenewAccountId) are omitted from the response when not present
  • No unrelated files are modified

📋 Step-by-Step Contribution Guide

  • Comment /assign to request the issue
  • Wait for assignment
  • Fork the repository and create a branch
  • Set up the project using the instructions in README.md
  • Make the requested changes
  • Sign each commit using -s -S
  • Push your branch and open a pull request

Read Workflow Guide for step-by-step workflow guidance. Read README.md for setup instructions.

❗ Pull requests cannot be merged without S and s signed commits. See the Signing Guide.


🤔 Additional Information

  • Reference query pattern in TCK: src/tck/src/account/AccountService.cc (getAccountInfo) — closely analogous
  • TCK test file (in the hiero-sdk-tck repo): src/tests/contract-service/test-contract-info-query.ts
  • SDK query class: src/sdk/main/include/ContractInfoQuery.h
  • SDK info class: src/sdk/main/include/ContractInfo.h

If you have questions while working on this issue, feel free to ask! Hiero-SDK-C++ Discord

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: testingAdding or improving unit tests, integration tests, or test infrastructurepriority: mediumNormal priority; to be addressed in the standard development cycleskill: intermediateRequires familiarity with the codebase structure and SDK conceptsstatus: ready for devThe issue is fully defined and ready for a contributor

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions