Skip to content

feat: add staking_info fields to ContractInfo - #1744

Merged
manishdait merged 9 commits into
hiero-ledger:mainfrom
Mounil2005:add-staking-info-to-contract-info
Mar 4, 2026
Merged

feat: add staking_info fields to ContractInfo#1744
manishdait merged 9 commits into
hiero-ledger:mainfrom
Mounil2005:add-staking-info-to-contract-info

Conversation

@Mounil2005

Copy link
Copy Markdown
Contributor

Description:

Add staking_info fields to ContractInfo class to support staking metadata from blockchain

  • Add staked_account_id field for account staking
  • Add staked_node_id field for node staking
  • Add decline_staking_reward field for reward preference
  • Update _from_proto() to deserialize staking data
  • Update _to_proto() to serialize staking data
  • Add comprehensive unit tests for staking fields

Related issue(s):

Fixes #1365

Notes for reviewer:

Implementation follows the same pattern used in AccountInfo for consistency. All changes are isolated to ContractInfo and its unit tests. 17 unit tests pass including:

  • Tests for no staking info (None case)
  • Tests for staked to account
  • Tests for staked to node
  • Round-trip conversion tests (fromBytes/toBytes)

Checklist

  • Documented (Code comments, updated docstrings)
  • Tested (17 unit tests - all passing)

Copilot AI review requested due to automatic review settings February 7, 2026 12:05
@Mounil2005
Mounil2005 requested review from a team as code owners February 7, 2026 12:05
@Mounil2005
Mounil2005 requested review from Dosik13 and rbair23 February 7, 2026 12:05
@Mounil2005
Mounil2005 marked this pull request as draft February 7, 2026 12:06

Copilot AI 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.

Pull request overview

Adds staking-related metadata fields to ContractInfo so contract staking targets and reward preference can be round-tripped through protobuf serialization/deserialization.

Changes:

  • Add staked_account_id, staked_node_id, and decline_staking_reward fields to ContractInfo.
  • Update ContractInfo._from_proto() to deserialize staking_info into the new fields.
  • Update ContractInfo._to_proto() and add unit tests covering staking scenarios and round-trip conversions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/hiero_sdk_python/contract/contract_info.py Adds staking fields and (de)serialization logic for staking_info.
tests/unit/contract_info_test.py Extends unit tests to validate staking field initialization and proto round-trips.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hiero_sdk_python/contract/contract_info.py Outdated
Comment thread src/hiero_sdk_python/contract/contract_info.py
Comment thread tests/unit/contract_info_test.py Outdated
Comment thread tests/unit/contract_info_test.py
Comment thread tests/unit/contract_info_test.py Outdated
@codecov

codecov Bot commented Feb 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1744   +/-   ##
=======================================
  Coverage   93.35%   93.35%           
=======================================
  Files         141      141           
  Lines        9121     9124    +3     
=======================================
+ Hits         8515     8518    +3     
  Misses        606      606           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The PR adds support for the staking_info field to the ContractInfo class. This includes a new optional field with corresponding proto serialization and deserialization logic, comprehensive unit tests covering proto round-trip conversions, integration test assertions validating default values, and tooling configuration updates.

Changes

Cohort / File(s) Summary
ContractInfo Staking Field
src/hiero_sdk_python/contract/contract_info.py
Adds optional staking_info: Optional[StakingInfo] field with _from_proto deserialization using HasField check and _to_proto serialization when present. Updates string representation to include staking info.
ContractInfo Unit Tests
tests/unit/contract_info_test.py
Adds comprehensive test coverage for staking_info including initialization with staked_account_id and decline_reward, proto round-trip conversion tests for both staked_node_id and staked_account_id scenarios, edge case validation (staked_node_id = 0), and None-handling tests.
Documentation & Integration
CHANGELOG.md, tests/integration/contract_info_query_e2e_test.py
Documents the new staking_info field addition. Adds integration test assertions validating staking_info defaults (not None, staked_account_id is None, staked_node_id is None, decline_reward is False).
Tooling & Whitespace
pyproject.toml, tests/unit/account_info_test.py
Adds Bandit configuration block with tests directory exclusion. Adds trailing blank line in account_info_test.py.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding staking_info fields to the ContractInfo class, which is the primary objective of this PR.
Description check ✅ Passed The description is well-related to the changeset, detailing the new staking fields, serialization updates, comprehensive unit tests, and following AccountInfo patterns for consistency.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #1365: adds optional staking_info field to ContractInfo [#1365], implements _from_proto with HasField check [#1365], implements _to_proto with serialization [#1365], includes fromBytes/toBytes round-trip tests [#1365], and extends integration tests with staking_info validations.
Out of Scope Changes check ✅ Passed All changes are in-scope: contract_info.py modifications, comprehensive unit tests, integration test assertions, changelog entry, and bandit config. The bandit config addition is minimal and supports code quality.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #1365

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

@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: 5

Comment thread src/hiero_sdk_python/contract/contract_info.py Outdated
Comment thread src/hiero_sdk_python/contract/contract_info.py Outdated
Comment thread tests/unit/contract_info_test.py Outdated
Comment thread tests/unit/contract_info_test.py Outdated
@github-actions

github-actions Bot commented Feb 8, 2026

Copy link
Copy Markdown

Hi, this is MergeConflictBot.
Your pull request cannot be merged because it contains merge conflicts.

Please resolve these conflicts locally and push the changes.

Quick Fix for CHANGELOG.md Conflicts

If your conflict is only in CHANGELOG.md, you can resolve it easily using the GitHub web editor:

  1. Click on the "Resolve conflicts" button in the PR
  2. Accept both changes (keep both changelog entries)
  3. Click "Mark as resolved"
  4. Commit the merge

For all other merge conflicts, please read:

Thank you for contributing!

Comment thread src/hiero_sdk_python/contract/contract_info.py Outdated
@github-actions

Copy link
Copy Markdown

Hello, this is the OfficeHourBot.

This is a reminder that the Hiero Python SDK Office Hours are scheduled in approximately 4 hours (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

@Mounil2005
Mounil2005 force-pushed the add-staking-info-to-contract-info branch from bcbcd6f to 98115be Compare February 11, 2026 12:53
@Mounil2005
Mounil2005 marked this pull request as ready for review February 11, 2026 13:21

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/contract_info_test.py (1)

234-252: 🛠️ Refactor suggestion | 🟠 Major

Add staking assertions to the None-values _to_proto test.

This test exercises _to_proto with a default-constructed ContractInfo but doesn't verify staking behavior. Given the _to_proto bug (always emitting a StakingInfo), asserting here would document the expected behavior and catch regressions.

     assert proto.max_automatic_token_associations == 0  # 0 is default for protobuf int
+    # When all staking fields are None, staking_info should not be present
+    assert not proto.HasField('staking_info'), "staking_info should be absent when all staking fields are None"

This assertion will currently fail, confirming the _to_proto bug. Once the production code is fixed, this test will pass and serve as a regression guard.

@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: 3

Comment thread CHANGELOG.md Outdated
Comment thread tests/unit/contract_info_test.py Outdated
Comment thread tests/unit/contract_info_test.py Outdated
@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown

Hi, this is WorkflowBot.
Your pull request cannot be merged as it is not passing all our workflow checks.
Please click on each check to review the logs and resolve issues so all checks pass.
To help you:

@Mounil2005
Mounil2005 force-pushed the add-staking-info-to-contract-info branch from 919e2ff to 4233fb1 Compare March 3, 2026 04:53
@exploreriii
exploreriii marked this pull request as ready for review March 3, 2026 09:49
@exploreriii
exploreriii requested a review from a team as a code owner March 3, 2026 09:49

@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.

♻️ Duplicate comments (1)
src/hiero_sdk_python/contract/contract_info.py (1)

42-42: ⚠️ Potential issue | 🟡 Minor

Use StakingInfo | None for the newly added annotation.

Line 59 introduces Optional[StakingInfo] in modified code; this should follow the repository’s X | None style.

Proposed fix
-        staking_info (Optional[StakingInfo]): The staking information for this contract
+        staking_info (StakingInfo | None): The staking information for this contract
...
-    staking_info: Optional[StakingInfo] = None
+    staking_info: StakingInfo | None = None
#!/bin/bash
# Verify Python version supports union syntax and locate current annotation usage.
rg -n 'requires-python' pyproject.toml
rg -n 'staking_info\s*:\s*Optional\[StakingInfo\]' src/hiero_sdk_python/contract/contract_info.py

As per coding guidelines, "The codebase uses X | None union syntax (Python 3.10+). Flag any use of Optional[X] from typing in newly added or modified code."

Also applies to: 59-59


ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af873be and 4233fb1.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • pyproject.toml
  • src/hiero_sdk_python/contract/contract_info.py
  • tests/integration/contract_info_query_e2e_test.py
  • tests/unit/account_info_test.py
  • tests/unit/contract_info_test.py

@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.

@Mounil2005, Just a small change rest looks good to me

Comment thread pyproject.toml Outdated
@exploreriii

Copy link
Copy Markdown
Contributor

Have you rebased please @Mounil2005 ?

Signed-off-by: Mounil <mounilkankhara@gmail.com>
Signed-off-by: Mounil <mounilkankhara@gmail.com>
Signed-off-by: Mounil <mounilkankhara@gmail.com>
Signed-off-by: Mounil <mounilkankhara@gmail.com>
Signed-off-by: Mounil <mounilkankhara@gmail.com>
…e account_info changes

Signed-off-by: Mounil <mounilkankhara@gmail.com>
…ssert style

Signed-off-by: Mounil <mounilkankhara@gmail.com>
Signed-off-by: Mounil <mounilkankhara@gmail.com>
Signed-off-by: Mounil <mounilkankhara@gmail.com>
@Mounil2005
Mounil2005 force-pushed the add-staking-info-to-contract-info branch from 0b58031 to c59d031 Compare March 3, 2026 11:58
@Mounil2005

Copy link
Copy Markdown
Contributor Author

Have you rebased please @Mounil2005 ?

Done!

@exploreriii

Copy link
Copy Markdown
Contributor

Merge away please if we have enough approvals :D

@manishdait
manishdait merged commit 828adc1 into hiero-ledger:main Mar 4, 2026
25 of 26 checks passed
@Mounil2005
Mounil2005 deleted the add-staking-info-to-contract-info branch March 4, 2026 19:25
mizoz pushed a commit to mizoz/hiero-sdk-python that referenced this pull request Mar 10, 2026
Signed-off-by: Mounil <mounilkankhara@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add stacking_info field to ContractInfo

7 participants