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 4 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>
299d289 to
98b2ca3
Compare
aceppaluni
left a comment
There was a problem hiding this comment.
@mohityadav8 This is looking great!
Can you update your branch when you have a moment?
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 when both conditions match.
Lines 155-157 should have been removed when lines 158-161 were added. Currently, when both
account_idandis_approvedmatch an existing transfer, the amount is accumulated twice:
- Line 156 executes:
transfer.amount += amount- Line 159 executes again:
transfer.amount += amountThis causes the amount to be doubled incorrectly.
🐛 Proposed fix: Remove the old accumulation logic
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 returnAs per coding guidelines, this is a correctness issue that breaks the fundamental accumulation logic for approved token transfers, which is critical for allowance-based transfer flows.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 26996619-0519-4d82-a3df-25a064b8077e
📒 Files selected for processing (2)
src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.pytests/unit/transfer_transaction_test.py
Signed-off-by: Mohit Yadav <ymohit799057@gmail.com>
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: 584e9fd2-5bc5-48b1-a7eb-cebae61b0470
📒 Files selected for processing (1)
src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.py
| for transfer in self.token_transfers[token_id]: | ||
| 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 | ||
| return |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Document the last-call-wins semantics for expected_decimals within aggregation groups.
The aggregation logic now requires both account_id and is_approved to match, but expected_decimals is still overwritten (line 157) rather than validated for consistency. This means multiple calls with the same (token_id, account_id, is_approved) will accumulate amounts but the last call's expected_decimals wins.
Consider adding a docstring note or inline comment explaining this behavior, since callers might expect either:
- Validation that all calls use the same
expected_decimals, or - Aggregation only when all three fields match
📝 Suggested inline comment
for transfer in self.token_transfers[token_id]:
if transfer.account_id == account_id and transfer.is_approved == is_approved:
+ # Accumulate amount; overwrite expected_decimals with latest value (last-call-wins)
transfer.amount += amount
transfer.expected_decimals = expected_decimals
return|
|
||
| for transfer in self.token_transfers[token_id]: | ||
| if transfer.account_id == account_id: | ||
| if transfer.account_id == account_id and transfer.is_approved == is_approved: |
There was a problem hiding this comment.
Previously, these changes caused the e2e test tests/integration/transfer_transaction_e2e_test.py::test_integration_transfer_transaction_approved_token_transfer to fail with ACCOUNT_REPEATED_IN_ACCOUNT_AMOUNTS.
This happens cause fro single token within one TransferTransaction you cannot have both a standard transfer entry and an approved transfer entry for the same (tokenId, accountId) pair they are treated as separate entries and are not merged.
One workaround is to keep the previous behavior, where both transfers are merged into a single entry (either fully standard or fully approved). Since the approval flag is only set once, the later value is effectively ignored.
The other option is to update the e2e test to completely use the standard transfer instead.
Would like to get an opinion from @exploreriii on which direction makes more sense.
There was a problem hiding this comment.
@aceppaluni @manishdait what change i have to do in this ??
|
Hello, this is the OfficeHourBot. This is a reminder that the Hiero Python SDK Office Hours will begin in approximately 3 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, |
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