fix: update is_approved in _add_token_transfer accumulation branch#2290
fix: update is_approved in _add_token_transfer accumulation branch#2290mohityadav8 wants to merge 6 commits into
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAggregation now requires both account_id and is_approved to match before merging a fungible TokenTransfer; transfers with differing is_approved values remain separate. Tests were updated to assert separate entries for approved vs normal transfers and to verify accumulation when is_approved matches. ChangesToken Transfer Aggregation
🎯 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 PlannerLet us write the prompt for your AI agent so you can ship faster (with fewer bugs). View plan for ticket: ✨ 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/unit/transfer_transaction_test.py (1)
481-481:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winIncorrect assertion: last-call-wins should update is_approved to True.
After adding an approved transfer at line 475 (
add_approved_token_transfer_with_decimals), the last-call-wins semantics should updatetransfer_1.is_approvedtoTrue. The assertion and comment"# unchanged"are both incorrect—the fix explicitly updatesis_approvedduring accumulation.🐛 Proposed fix
- assert transfer_1.is_approved is False # unchanged + assert transfer_1.is_approved is True # updated by last-call-wins
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c9143b75-35f9-45e7-9328-5af95ab8de95
📒 Files selected for processing (2)
src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.pytests/unit/transfer_transaction_test.py
4c06024 to
667c305
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.py (1)
154-161:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winCritical: Double accumulation bug — remove the old condition.
Lines 155-157 (the old condition checking only
account_id) were not removed, causing amount to be accumulated twice when bothaccount_idandis_approvedmatch:
- Line 156 adds
amountwhenaccount_idmatches- Line 159 adds
amountagain when bothaccount_idandis_approvedmatchThis contradicts the PR objective ("accumulate only when account_id and is_approved both match") and the past review guidance. The tests in
test_same_approved_transfers_accumulateexpect 500 but would receive 700 with this implementation.🐛 Proposed fix: remove lines 155-157
for transfer in self.token_transfers[token_id]: - if transfer.account_id == account_id: - transfer.amount += amount - transfer.expected_decimals = expected_decimals if transfer.account_id == account_id and transfer.is_approved == is_approved: transfer.amount += amount transfer.expected_decimals = expected_decimals return
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7163efcf-87c4-4ef8-a59d-c3cb6cb0a3b2
📒 Files selected for processing (2)
src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.pytests/unit/transfer_transaction_test.py
|
cc @manishdait |
AntonioCeppellini
left a comment
There was a problem hiding this comment.
Seems good to me, thank you for your contribution :D 🧇
|
please update the branch @mohityadav8 :D and then is ready to go |
|
@AntonioCeppellini done🙂 |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #2290 +/- ##
=======================================
Coverage 93.97% 93.97%
=======================================
Files 163 163
Lines 10408 10408
=======================================
Hits 9781 9781
Misses 627 627 🚀 New features to boost your workflow:
|
|
Hi, this is WorkflowBot.
|
299d289
2205e9e to
299d289
Compare
Signed-off-by: Mohit Yadav <ymohit799057@gmail.com>
Fixes hiero-ledger#2253 Signed-off-by: Mohit Yadav <ymohit799057@gmail.com>
|
Moving this to draft until we decide which approach to go with. |
ahh i thik thhis is good i was thinking same |
|
Hi @mohityadav8, This pull request has had no commit activity for 10 days. Are you still working on it?
If you're no longer working on this, please comment Reach out on discord or join our office hours if you need assistance. From the Python SDK Team |
| Requesting triage review from: @hiero-ledger/hiero-sdk-python-triage |
|
@exploreriii What is your opinion on this? |
|
Since this PR is currently in discussion and marked as draft pending a decision on the expected behavior, I noticed the inactivity bot still posts reminders asking for new commits after 10 days. Would it make sense to update the workflow so inactivity reminders are skipped for PRs that have labels such as "status: discussion" or for draft PRs? In cases like this, the PR is intentionally waiting for feedback rather than code changes. Just a thought that might help reduce unnecessary notifications. |
|
yes! i think we tried to do something like that in the past, unsure if it worked/we resolved it |
|
Hi @mohityadav8, this is CronInactivityBot 👋 This pull request has had no new commits for 21 days, so I'm closing it and unassigning you from the linked issue to keep the backlog healthy. If you're no longer interested, no action is needed. Tip: You can comment If you'd like to continue working on this later, feel free to comment |
|
@AntonioCeppellini @manishdait why this is closed |
@exploreriii @aceppaluni @exploreriii i think we do not have news about this one @mohityadav8 sorry for this, we are in a stale situation on this right now i think |
|
Hi sorry it was the bot, we have a PR to fix it -- need to get back to you |
exploreriii
left a comment
There was a problem hiding this comment.
Great work! Issue was relevant, fix is correct and nearly merge ready
| is_approved: bool = False, | ||
| ) -> None: | ||
| """Adds a fungible token transfer to the transaction's list. | ||
|
|
There was a problem hiding this comment.
should add a comment here eg
Transfers for the same (token_id, account_id) pair are merged into a single
entry only when their approval status matches; a regular and an approved
transfer for the same account are kept as separate entries, since spending
an allowance is semantically different from spending the account's own
balance. When merging, an explicitly provided expected_decimals updates the
entry; passing None leaves the previously set value unchanged.
| if transfer.account_id == account_id: | ||
| if transfer.account_id == account_id and transfer.is_approved == is_approved: | ||
| transfer.amount += amount | ||
| transfer.expected_decimals = expected_decimals |
There was a problem hiding this comment.
We should avoid this being overwritten by none eg
if expected_decimals is not None:
transfer.expected_decimals = expected_decimals
| @@ -453,7 +453,7 @@ def test_approved_token_transfer_with_decimals(mock_account_ids): | |||
|
|
|||
|
|
|||
| def test_approved_token_transfer_accumulation(mock_account_ids): | |||
There was a problem hiding this comment.
can add a test for the new features
def test_merge_preserves_expected_decimals(mock_account_ids):
"""Merging a transfer without decimals must not clear a previously set expected_decimals."""
|
Hi @mohityadav8, this is CronInactivityBot 👋 This pull request has had no new commits for 38 days, so I'm closing it and unassigning you from the linked issue to keep the backlog healthy. If you're no longer interested, no action is needed. Tip: You can comment If you'd like to continue working on this later, feel free to comment |

Description:
Fix
_add_token_transfersilently ignoringis_approvedwhen mergingtransfers for the same
(token_id, account_id)pair.transfer.is_approved = is_approvedin the accumulation branch of_add_token_transferto implement last-call-wins semanticstest_approved_token_transfer_accumulationto assertthe corrected behaviour
test_is_approved_updated_normal_then_approvedto cover normal → approved ordertest_is_approved_updated_approved_then_normalto cover approved → normal ordertest_add_approved_token_transfer_no_decimalsfor the non-decimal variantRelated issue(s):
Fixes #2253
Notes for reviewer:
The fix is a single line added to the accumulation branch in
_add_token_transfer(), consistent with how expected_decimals is
already handled. Semantics are last-call-wins for is_approved.
Checklist