Skip to content

_add_token_transfer silently ignores is_approved when merging transfers for the same account #2253

Description

@mohityadav8

Description

When _add_token_transfer() is called multiple times for the same (token_id, account_id) pair, the transfer amount is accumulated correctly, but the is_approved flag is never updated in the accumulation branch.

This causes approved transfers to silently lose their approval state depending on call order.

Example:

tx.add_token_transfer(token_a, sender, 500)
# is_approved=False (default)

tx.add_approved_token_transfer(token_a, sender, 200)
# expected accumulated transfer to become approved

### Steps to reproduce

1. Create a transaction.
2. Add a normal token transfer for a `(token_id, account_id)` pair.
3. Add an approved token transfer for the same `(token_id, account_id)` pair.
4. Inspect the accumulated transfer object.

Example:

```python
tx.add_token_transfer(token_a, sender, 500)
tx.add_approved_token_transfer(token_a, sender, 200)

Observed result:

is_approved == False

Expected result:

is_approved == True

Additional context

Root cause appears to be inside _add_token_transfer() where the accumulation branch updates amount and expected_decimals, but never updates is_approved.

Current logic:

for transfer in self.token_transfers[token_id]:
    if transfer.account_id == account_id:
        transfer.amount += amount
        transfer.expected_decimals = expected_decimals
        return

Suggested fix:

transfer.is_approved = is_approved

before returning from the accumulation branch.

This can affect allowance-based transfer flows where regular and approved transfers are combined in the same transaction.

Hedera network

No response

Version

v0.2.5

Operating system

None

Metadata

Metadata

Assignees

Labels

skill: beginnerAchievable by a fairly new comer that has already completed a couple of good first issues

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions