Skip to content

feat: add staking_info fields to ContractInfo#1744

Draft
Mounil2005 wants to merge 4 commits intohiero-ledger:mainfrom
Mounil2005:add-staking-info-to-contract-info
Draft

feat: add staking_info fields to ContractInfo#1744
Mounil2005 wants to merge 4 commits intohiero-ledger:mainfrom
Mounil2005:add-staking-info-to-contract-info

Conversation

@Mounil2005
Copy link
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
Copy link
Contributor

Copilot AI left a comment

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 on lines 159 to 163
staking_info=StakingInfo(
staked_account_id=self.staked_account_id._to_proto() if self.staked_account_id else None,
staked_node_id=self.staked_node_id if self.staked_node_id else None,
decline_reward=self.decline_staking_reward
),
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

_to_proto() always constructs and populates staking_info, even when no staking fields are set. This makes staking_info appear present on the wire with default values, and the truthiness checks also drop valid values like staked_node_id=0. Build and set staking_info only when at least one of the staking fields is non-None, use is not None for staked_node_id, and avoid passing None for decline_reward (either omit it or coerce to bool when provided).

Copilot uses AI. Check for mistakes.
assert contract_info.decline_staking_reward is True


def test_to_proto_with_staked_account_id(token_relationship):
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

token_relationship fixture parameter is unused in this test, which causes unnecessary fixture setup and can hide accidental dependencies. Remove the parameter (or use it) to keep the test focused.

Suggested change
def test_to_proto_with_staked_account_id(token_relationship):
def test_to_proto_with_staked_account_id():

Copilot uses AI. Check for mistakes.
Comment on lines 390 to 405
def test_to_proto_with_staked_node_id():
"""Test to_proto with staked_node_id"""
contract_info = ContractInfo(
contract_id=ContractId(0, 0, 200),
account_id=AccountId(0, 0, 300),
balance=5000000,
staked_node_id=5,
decline_staking_reward=True,
)

proto = contract_info._to_proto()

assert proto.HasField('staking_info')
assert proto.staking_info.staked_node_id == 5
assert proto.staking_info.decline_reward is True

Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The new staking serialization logic would benefit from a regression test that covers the "no staking fields set" case during _to_proto() (e.g., ensure staking_info is not set/serialized when staked_account_id, staked_node_id, and decline_staking_reward are all None). This helps prevent round-trip conversions from turning None into default values unintentionally.

Copilot uses AI. Check for mistakes.

def test_from_proto_with_staked_node_id():
"""Test from_proto with staked_node_id (staked to node)"""
public_key = PrivateKey.generate_ed25519().public_key()
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

Variable public_key is not used.

Suggested change
public_key = PrivateKey.generate_ed25519().public_key()

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1744   +/-   ##
=======================================
  Coverage   93.29%   93.30%           
=======================================
  Files         141      141           
  Lines        9118     9112    -6     
=======================================
- Hits         8507     8502    -5     
+ Misses        611      610    -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Walkthrough

Adds three optional staking fields—staked_account_id, staked_node_id, and decline_staking_reward—to ContractInfo, updates _from_proto and _to_proto to handle staking_info, and includes these fields in __repr__/__str__. Unit tests and CHANGELOG updated to cover staking scenarios and absence of staking info.

Changes

Cohort / File(s) Summary
ContractInfo Implementation
src/hiero_sdk_python/contract/contract_info.py
Added public fields staked_account_id: Optional[AccountId], staked_node_id: Optional[int], decline_staking_reward: Optional[bool]. _from_proto extracts proto.staking_info when present to populate these fields; _to_proto emits staking_info with staked_account_id / staked_node_id and decline_reward derived from decline_staking_reward. __repr__/__str__ updated to include staking fields.
ContractInfo Unit Tests
tests/unit/contract_info_test.py
Tests updated/extended to initialize ContractInfo with new staking parameters, verify proto round-trip for both staked_node_id and staked_account_id cases, confirm correct omission when staking_info is absent, and assert decline_staking_reward handling.
Changelog
CHANGELOG.md
Documented addition of staked_account_id, staked_node_id, and decline_staking_reward to the public ContractInfo API.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The implementation diverges from the linked issue (#1365) requirement: it adds three individual fields instead of a single optional StakingInfo field as specified. The PR adds staked_account_id, staked_node_id, and decline_staking_reward as separate fields instead of wrapping them in a single StakingInfo field per issue #1365 requirements. Either restructure to use StakingInfo or clarify why the alternative approach was chosen.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (3 files):

⚔️ CHANGELOG.md (content)
⚔️ src/hiero_sdk_python/contract/contract_info.py (content)
⚔️ tests/unit/contract_info_test.py (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and specifically summarizes the main change: adding staking_info fields to ContractInfo class.
Description check ✅ Passed The pull request description is comprehensive and directly related to the changeset, detailing the new fields, implementation approach, and testing coverage.
Out of Scope Changes check ✅ Passed All changes are directly related to adding staking metadata to ContractInfo with appropriate updates to proto serialization, deserialization, and comprehensive unit tests.
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.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch add-staking-info-to-contract-info
  • Post resolved changes as copyable diffs in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 on lines 159 to 163
staking_info=StakingInfo(
staked_account_id=self.staked_account_id._to_proto() if self.staked_account_id else None,
staked_node_id=self.staked_node_id if self.staked_node_id else None,
decline_reward=self.decline_staking_reward
),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Bug: _to_proto always emits staking_info, breaking round-trips when no staking fields are set.

When all staking fields are None, this still creates a StakingInfo() message. Protobuf will then report HasField('staking_info') as true on deserialization, causing _from_proto to set decline_staking_reward = False (protobuf default) instead of None. This breaks the NoneNone round-trip invariant.

Additionally, on line 161, staked_node_id if self.staked_node_id else None uses a falsy check — node ID 0 is a valid value but would be silently dropped.

Proposed fix: conditionally build staking_info, use `is not None` checks
-            staking_info=StakingInfo(
-                staked_account_id=self.staked_account_id._to_proto() if self.staked_account_id else None,
-                staked_node_id=self.staked_node_id if self.staked_node_id else None,
-                decline_reward=self.decline_staking_reward
-            ),
+            staking_info=self._build_staking_info_proto(),

Then add a helper method:

def _build_staking_info_proto(self):
    """Build StakingInfo proto only if any staking field is set."""
    if (self.staked_account_id is None
            and self.staked_node_id is None
            and self.decline_staking_reward is None):
        return None
    kwargs = {}
    if self.staked_account_id is not None:
        kwargs['staked_account_id'] = self.staked_account_id._to_proto()
    if self.staked_node_id is not None:
        kwargs['staked_node_id'] = self.staked_node_id
    if self.decline_staking_reward is not None:
        kwargs['decline_reward'] = self.decline_staking_reward
    return StakingInfo(**kwargs)

Comment on lines 351 to 369
def test_from_proto_with_staked_node_id():
"""Test from_proto with staked_node_id (staked to node)"""
public_key = PrivateKey.generate_ed25519().public_key()
proto = ContractGetInfoResponse.ContractInfo(
contractID=ContractId(0, 0, 200)._to_proto(),
accountID=AccountId(0, 0, 300)._to_proto(),
storage=1024,
balance=5000000,
staking_info=StakingInfo(
staked_node_id=3,
decline_reward=True,
),
)

contract_info = ContractInfo._from_proto(proto)

assert contract_info.staked_account_id is None
assert contract_info.staked_node_id == 3
assert contract_info.decline_staking_reward is True
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Unused variable public_key (static analysis: Ruff F841).

public_key is assigned but never used in this test. Remove it to keep the test clean.

Proposed fix
 def test_from_proto_with_staked_node_id():
     """Test from_proto with staked_node_id (staked to node)"""
-    public_key = PrivateKey.generate_ed25519().public_key()
     proto = ContractGetInfoResponse.ContractInfo(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_from_proto_with_staked_node_id():
"""Test from_proto with staked_node_id (staked to node)"""
public_key = PrivateKey.generate_ed25519().public_key()
proto = ContractGetInfoResponse.ContractInfo(
contractID=ContractId(0, 0, 200)._to_proto(),
accountID=AccountId(0, 0, 300)._to_proto(),
storage=1024,
balance=5000000,
staking_info=StakingInfo(
staked_node_id=3,
decline_reward=True,
),
)
contract_info = ContractInfo._from_proto(proto)
assert contract_info.staked_account_id is None
assert contract_info.staked_node_id == 3
assert contract_info.decline_staking_reward is True
def test_from_proto_with_staked_node_id():
"""Test from_proto with staked_node_id (staked to node)"""
proto = ContractGetInfoResponse.ContractInfo(
contractID=ContractId(0, 0, 200)._to_proto(),
accountID=AccountId(0, 0, 300)._to_proto(),
storage=1024,
balance=5000000,
staking_info=StakingInfo(
staked_node_id=3,
decline_reward=True,
),
)
contract_info = ContractInfo._from_proto(proto)
assert contract_info.staked_account_id is None
assert contract_info.staked_node_id == 3
assert contract_info.decline_staking_reward is True
🧰 Tools
🪛 Ruff (0.14.14)

[error] 353-353: Local variable public_key is assigned to but never used

Remove assignment to unused variable public_key

(F841)

Comment on lines 372 to 387
def test_to_proto_with_staked_account_id(token_relationship):
"""Test to_proto with staked_account_id"""
contract_info = ContractInfo(
contract_id=ContractId(0, 0, 200),
account_id=AccountId(0, 0, 300),
balance=5000000,
staked_account_id=AccountId(0, 0, 500),
decline_staking_reward=False,
)

proto = contract_info._to_proto()

assert proto.HasField('staking_info')
assert proto.staking_info.HasField('staked_account_id')
assert proto.staking_info.staked_account_id == AccountId(0, 0, 500)._to_proto()
assert proto.staking_info.decline_reward is False
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Unused fixture argument token_relationship (static analysis: Ruff ARG001).

The token_relationship parameter is injected but never used. Remove it from the function signature.

Proposed fix
-def test_to_proto_with_staked_account_id(token_relationship):
+def test_to_proto_with_staked_account_id():
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_to_proto_with_staked_account_id(token_relationship):
"""Test to_proto with staked_account_id"""
contract_info = ContractInfo(
contract_id=ContractId(0, 0, 200),
account_id=AccountId(0, 0, 300),
balance=5000000,
staked_account_id=AccountId(0, 0, 500),
decline_staking_reward=False,
)
proto = contract_info._to_proto()
assert proto.HasField('staking_info')
assert proto.staking_info.HasField('staked_account_id')
assert proto.staking_info.staked_account_id == AccountId(0, 0, 500)._to_proto()
assert proto.staking_info.decline_reward is False
def test_to_proto_with_staked_account_id():
"""Test to_proto with staked_account_id"""
contract_info = ContractInfo(
contract_id=ContractId(0, 0, 200),
account_id=AccountId(0, 0, 300),
balance=5000000,
staked_account_id=AccountId(0, 0, 500),
decline_staking_reward=False,
)
proto = contract_info._to_proto()
assert proto.HasField('staking_info')
assert proto.staking_info.HasField('staked_account_id')
assert proto.staking_info.staked_account_id == AccountId(0, 0, 500)._to_proto()
assert proto.staking_info.decline_reward is False
🧰 Tools
🪛 Ruff (0.14.14)

[warning] 372-372: Unused function argument: token_relationship

(ARG001)

Copy link
Contributor

Choose a reason for hiding this comment

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

agree with this

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

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 on lines 61 to 63
staked_account_id: Optional[AccountId] = None
staked_node_id: Optional[int] = None
decline_staking_reward: Optional[bool] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

There is StakingInfo class in the python SDK. Why don't we use it instead?

Suggested change
staked_account_id: Optional[AccountId] = None
staked_node_id: Optional[int] = None
decline_staking_reward: Optional[bool] = None
staking_info: Optional[StakingInfo] = None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion! I have done it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Mounil2005,
I still don’t see the changes updated in the PR. could you please confirm whether you have pushed the latest updates?

@github-actions
Copy link

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
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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.

@exploreriii exploreriii added status: needs triage review PR needs a review from the triage team and removed status: in initial development labels Feb 11, 2026
@exploreriii exploreriii requested a review from a team February 11, 2026 13:45
@exploreriii exploreriii added status: needs developer revision PR has requested changes that the developer needs to implement and removed status: needs triage review PR needs a review from the triage team labels Feb 11, 2026
@exploreriii exploreriii marked this pull request as draft February 11, 2026 14:22
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 98115be to 8fe7319 Compare February 15, 2026 08:45
Signed-off-by: Mounil <mounilkankhara@gmail.com>
@exploreriii exploreriii marked this pull request as ready for review February 15, 2026 10:15
@exploreriii exploreriii removed the status: needs developer revision PR has requested changes that the developer needs to implement label Feb 15, 2026
@exploreriii exploreriii added status: needs triage review PR needs a review from the triage team status: needs committer review PR needs a review from the committer team labels Feb 15, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 on lines +14 to +15
### Added
- Add staking_info fields (`staked_account_id`, `staked_node_id`, `decline_staking_reward`) to ContractInfo class to expose staking metadata from protobuf. (#1365)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing blank line below heading (MD022).

The ### Added heading on line 14 needs a blank line below it before the list item, per Markdown lint rules (MD022).

Proposed fix
 ### Added
+
 - Add staking_info fields (`staked_account_id`, `staked_node_id`, `decline_staking_reward`) to ContractInfo class to expose staking metadata from protobuf. (`#1365`)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Added
- Add staking_info fields (`staked_account_id`, `staked_node_id`, `decline_staking_reward`) to ContractInfo class to expose staking metadata from protobuf. (#1365)
### Added
- Add staking_info fields (`staked_account_id`, `staked_node_id`, `decline_staking_reward`) to ContractInfo class to expose staking metadata from protobuf. (`#1365`)
🧰 Tools
🪛 markdownlint-cli2 (0.20.0)

[warning] 14-14: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)

Comment on lines 291 to 293
assert converted.staked_account_id == contract_info.staked_account_id
assert converted.staked_node_id == contract_info.staked_node_id
assert converted.decline_staking_reward == contract_info.decline_staking_reward
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Good round-trip assertions for staking fields on fully populated object.

Consider adding assert isinstance(converted.staked_account_id, AccountId) for type safety.

Comment on lines 407 to 444
def test_proto_conversion_staking_node_round_trip():
"""Test proto conversion round trip with staked_node_id"""
contract_info = ContractInfo(
contract_id=ContractId(0, 0, 200),
account_id=AccountId(0, 0, 300),
balance=5000000,
staked_node_id=7,
decline_staking_reward=False,
)

converted = ContractInfo._from_proto(contract_info._to_proto())

assert converted.contract_id == contract_info.contract_id
assert converted.account_id == contract_info.account_id
assert converted.balance == contract_info.balance
assert converted.staked_account_id is None
assert converted.staked_node_id == 7
assert converted.decline_staking_reward is False


def test_proto_conversion_staking_account_round_trip():
"""Test proto conversion round trip with staked_account_id"""
contract_info = ContractInfo(
contract_id=ContractId(0, 0, 200),
account_id=AccountId(0, 0, 300),
balance=5000000,
staked_account_id=AccountId(0, 0, 600),
decline_staking_reward=True,
)

converted = ContractInfo._from_proto(contract_info._to_proto())

assert converted.contract_id == contract_info.contract_id
assert converted.account_id == contract_info.account_id
assert converted.balance == contract_info.balance
assert converted.staked_account_id == AccountId(0, 0, 600)
assert converted.staked_node_id is None
assert converted.decline_staking_reward is True
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Missing edge-case tests: staked_node_id=0 and round-trip with no staking info.

Two important gaps:

  1. staked_node_id=0 — Node 0 is a valid Hedera node. The current _to_proto falsy check will silently drop it. A test with staked_node_id=0 would catch this regression.
  2. Round-trip with all staking fields None — A ContractInfo() with default staking fields should survive _to_proto() → _from_proto() with fields still None. This would surface the always-emitting staking_info bug in _to_proto.
  3. isinstance check — Add assert isinstance(converted.staked_account_id, AccountId) in round-trip tests to protect against type regressions.

As per coding guidelines, "Cover happy paths AND unhappy paths/edge cases" and "Assert return types where relevant (e.g., assert isinstance(result, AccountId))".


def test_from_proto_with_staked_node_id():
"""Test from_proto with staked_node_id (staked to node)"""
public_key = PrivateKey.generate_ed25519().public_key()
Copy link
Contributor

Choose a reason for hiding this comment

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

can be remove


### Examples

### Added
Copy link
Contributor

Choose a reason for hiding this comment

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

move this under Src section

@manishdait manishdait marked this pull request as draft February 15, 2026 10:32
@exploreriii exploreriii added status: needs developer revision PR has requested changes that the developer needs to implement and removed status: needs triage review PR needs a review from the triage team status: needs committer review PR needs a review from the committer team labels Feb 15, 2026
Signed-off-by: Mounil <mounilkankhara@gmail.com>
Comment on lines -59 to +57
staked_account_id: Optional[AccountId] = None
staked_node_id: Optional[int] = None
decline_staking_reward: Optional[bool] = None
staking_info: Optional[StakingInfo] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

the removal of staked_account_id and the other fields introduces breaking change. If someone (like in the integration tests) access the staked_account_id directly it will break for them. @exploreriii, what do you think?

@Dosik13
Copy link
Contributor

Dosik13 commented Feb 17, 2026

You should also add checks for the staked_info field in the account_info_query_e2e_test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs developer revision PR has requested changes that the developer needs to implement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add stacking_info field to ContractInfo

4 participants