Skip to content

feat: add freeze_with method to TopicCreateTransaction for auto-renew account handling#2307

Open
danielmarv wants to merge 2 commits into
hiero-ledger:mainfrom
danielmarv:2299-sdk-br
Open

feat: add freeze_with method to TopicCreateTransaction for auto-renew account handling#2307
danielmarv wants to merge 2 commits into
hiero-ledger:mainfrom
danielmarv:2299-sdk-br

Conversation

@danielmarv
Copy link
Copy Markdown
Member

Description:
This pull request enhances the handling of the auto_renew_account field in the TopicCreateTransaction class to ensure it is set to a sensible default if not explicitly provided. It introduces a new freeze_with method that sets auto_renew_account based on the transaction or client context, removes redundant logic from the TCK handler, and adds comprehensive unit tests to verify the new behavior.

Enhancements to TopicCreateTransaction auto-renew account logic:

  • Added a freeze_with method to TopicCreateTransaction that automatically sets auto_renew_account to the transaction's account_id (if transaction_id is set) or falls back to the client's operator_account_id if not explicitly set. This ensures that the field is always populated with a valid value before freezing the transaction.
  • Removed redundant logic from the TCK handler (tck/handlers/topic.py) that previously set the auto_renew_account, as this is now handled within the transaction itself.

Testing improvements:

  • Added multiple unit tests to tests/unit/topic_create_transaction_test.py to verify that freeze_with sets or preserves the auto_renew_account field correctly in various scenarios, including when set explicitly, via setter, or derived from the transaction ID or client.
  • Introduced a helper function _generate_transaction_id in the test suite to facilitate testing scenarios involving transaction IDs.

Codebase maintainability:

  • Added TYPE_CHECKING imports to avoid circular dependencies and improve type hinting in topic_create_transaction.py. [1] [2]
  • Included missing import for TransactionId in the unit test file to support new test cases.

Related issue(s):

Fixes #2299

Notes for reviewer:

Checklist

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

… account handling

Signed-off-by: Ntege Daniel <danientege785@gmail.com>
@danielmarv danielmarv self-assigned this May 22, 2026
@github-actions github-actions Bot added lang: python Uses Python programming language skill: advanced requires knowledge of multiple areas in the codebase without defined steps to implement or examples labels May 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2307   +/-   ##
=======================================
  Coverage   93.99%   93.99%           
=======================================
  Files         163      163           
  Lines       10442    10447    +5     
=======================================
+ Hits         9815     9820    +5     
  Misses        627      627           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danielmarv danielmarv marked this pull request as ready for review May 22, 2026 22:58
@danielmarv danielmarv requested review from a team as code owners May 22, 2026 22:58
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

Moves default auto_renew_account assignment for topic creation from the TCK handler into the SDK transaction’s freeze_with, and adds unit tests to validate the new behavior.

Changes:

  • Add TopicCreateTransaction.freeze_with() override to auto-populate auto_renew_account when unset.
  • Remove TCK handler-side defaulting of autoRenewAccountId to the operator.
  • Add unit tests covering defaulting and preservation of explicitly set values.

Reviewed changes

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

File Description
tests/unit/topic_create_transaction_test.py Adds unit tests for freeze_with defaulting and explicit preservation behavior.
tck/handlers/topic.py Removes handler-level default auto_renew_account assignment, relying on SDK behavior.
src/hiero_sdk_python/consensus/topic_create_transaction.py Implements SDK-side defaulting for auto_renew_account during freeze_with.

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

self.fee_exempt_keys = keys
return self

def freeze_with(self, client: Client) -> TopicCreateTransaction:
Comment on lines +210 to +215
if client is not None and client.operator_account_id is not None and self.auto_renew_account is None:
self.auto_renew_account = (
self.transaction_id.account_id if self.transaction_id is not None else client.operator_account_id
)

return super().freeze_with(client)
self.fee_exempt_keys = keys
return self

def freeze_with(self, client: Client) -> TopicCreateTransaction:
Comment on lines +580 to +582
def _generate_transaction_id(account_id):
"""Generate a unique transaction ID based on the account ID and the current timestamp."""
import time
Comment on lines +586 to +591
current_time = time.time()
timestamp_seconds = int(current_time)
timestamp_nanos = int((current_time - timestamp_seconds) * 1e9)

tx_timestamp = timestamp_pb2.Timestamp(seconds=timestamp_seconds, nanos=timestamp_nanos)
return TransactionId(valid_start=tx_timestamp, account_id=account_id)
self.fee_exempt_keys = keys
return self

def freeze_with(self, client: Client) -> TopicCreateTransaction:
Comment on lines +210 to +215
if client is not None and client.operator_account_id is not None and self.auto_renew_account is None:
self.auto_renew_account = (
self.transaction_id.account_id if self.transaction_id is not None else client.operator_account_id
)

return super().freeze_with(client)
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Review Change Stack

Warning

Review limit reached

@danielmarv, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 2 reviews/hour. Refill in 18 minutes and 19 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b1d9474e-83ca-4d47-ad08-504d655bb7bb

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6e360 and b902aef.

📒 Files selected for processing (1)
  • tests/unit/topic_create_transaction_test.py

Walkthrough

TopicCreateTransaction now overrides freeze_with to auto-populate auto_renew_account when unset, preferring transaction_id.account_id over client.operator_account_id. The TCK handler's equivalent fallback is removed. Tests verify all selection scenarios.

Changes

Auto-renew account freezing behavior

Layer / File(s) Summary
freeze_with override and type-checking setup
src/hiero_sdk_python/consensus/topic_create_transaction.py
Adds TYPE_CHECKING conditional import of Client to avoid circular dependencies, then implements freeze_with override that auto-populates auto_renew_account using transaction_id.account_id if available, otherwise client.operator_account_id, before delegating to parent's freeze_with.
TCK handler default logic removal
tck/handlers/topic.py
Removes the fallback assignment of transaction.auto_renew_account from client.operator_account_id in create_topic, now relying entirely on the TopicCreateTransaction.freeze_with override to apply defaults.
freeze_with behavior test coverage
tests/unit/topic_create_transaction_test.py
Adds TransactionId import and _generate_transaction_id helper, then provides four unit tests verifying freeze_with selects defaults correctly: defaults to operator when unset, preserves explicit values, uses transaction_id.account_id when set, and preserves values set via setter method.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a freeze_with method to TopicCreateTransaction for handling auto-renew accounts.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about the auto_renew_account enhancements, freeze_with method implementation, test additions, and code maintenance improvements.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #2299: adds freeze_with method that defaults auto_renew_account to transaction_id.account_id or client.operator_account_id, preserves explicit values, includes comprehensive unit tests, and removes redundant TCK handler logic.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements in issue #2299: the freeze_with implementation, TCK handler cleanup, comprehensive unit tests, and necessary imports for type checking are all essential to fulfilling the linked issue objectives.
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

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

View plan used: #2299

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

Copy link
Copy Markdown
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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 00830f96-9520-490f-9d8e-488d47c27f6f

📥 Commits

Reviewing files that changed from the base of the PR and between 37f4bee and 1f6e360.

📒 Files selected for processing (3)
  • src/hiero_sdk_python/consensus/topic_create_transaction.py
  • tck/handlers/topic.py
  • tests/unit/topic_create_transaction_test.py
💤 Files with no reviewable changes (1)
  • tck/handlers/topic.py

Comment thread tests/unit/topic_create_transaction_test.py
@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 May 22, 2026
… account handling

Signed-off-by: Ntege Daniel <danientege785@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang: python Uses Python programming language open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review skill: advanced requires knowledge of multiple areas in the codebase without defined steps to implement or examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Override freeze_with() in TopicCreateTransaction to apply default autoRenewAccountId behavior

2 participants