feat: add freeze_with method to TopicCreateTransaction for auto-renew account handling#2307
feat: add freeze_with method to TopicCreateTransaction for auto-renew account handling#2307danielmarv wants to merge 2 commits into
Conversation
… account handling Signed-off-by: Ntege Daniel <danientege785@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ 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:
|
There was a problem hiding this comment.
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-populateauto_renew_accountwhen unset. - Remove TCK handler-side defaulting of
autoRenewAccountIdto 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: |
| 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: |
| def _generate_transaction_id(account_id): | ||
| """Generate a unique transaction ID based on the account ID and the current timestamp.""" | ||
| import time |
| 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: |
| 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) |
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough
ChangesAuto-renew account freezing behavior
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/hiero_sdk_python/consensus/topic_create_transaction.pytck/handlers/topic.pytests/unit/topic_create_transaction_test.py
💤 Files with no reviewable changes (1)
- tck/handlers/topic.py
… account handling Signed-off-by: Ntege Daniel <danientege785@gmail.com>
Description:
This pull request enhances the handling of the
auto_renew_accountfield in theTopicCreateTransactionclass to ensure it is set to a sensible default if not explicitly provided. It introduces a newfreeze_withmethod that setsauto_renew_accountbased 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
TopicCreateTransactionauto-renew account logic:freeze_withmethod toTopicCreateTransactionthat automatically setsauto_renew_accountto the transaction'saccount_id(iftransaction_idis set) or falls back to the client'soperator_account_idif not explicitly set. This ensures that the field is always populated with a valid value before freezing the transaction.tck/handlers/topic.py) that previously set theauto_renew_account, as this is now handled within the transaction itself.Testing improvements:
tests/unit/topic_create_transaction_test.pyto verify thatfreeze_withsets or preserves theauto_renew_accountfield correctly in various scenarios, including when set explicitly, via setter, or derived from the transaction ID or client._generate_transaction_idin the test suite to facilitate testing scenarios involving transaction IDs.Codebase maintainability:
TYPE_CHECKINGimports to avoid circular dependencies and improve type hinting intopic_create_transaction.py. [1] [2]TransactionIdin the unit test file to support new test cases.Related issue(s):
Fixes #2299
Notes for reviewer:
Checklist