test(hbar): add unit tests for CoinTransferBuilder self-transfer#8742
Conversation
HBAR claim rewards uses a 1-tinybar self-transfer (sender == recipient). getTransferData() filtered out the positive-amount entry when its accountID matched the sender, leaving recipients[] empty. toJson() then crashed reading recipients[0].address. Fix: after the forEach loop, if transferData is still empty and transfers exist, include the positive-amount entry as the sole recipient. Normal transfers are unaffected. Also adds unit tests covering: build with source == recipient, two separate accountAmounts protobuf entries, serialisation round-trip, and signing. Ticket: SI-539
e17b3a6 to
fcf0884
Compare
HBAR Claim Rewards — Self-Transfer Implementation NotesBackgroundHedera has no dedicated "claim rewards" transaction type at the protocol level. Staking rewards are harvested automatically whenever a Data flowWhy no
|
| File | Change |
|---|---|
transaction.ts |
Self-transfer fallback in getTransferData() — when all positive-amount entries belong to the sender (sender == recipient), include the positive entry as the recipient instead of returning empty |
coinTransferBuilder.ts |
4 unit tests covering: build self-transfer, proto produces two separate accountAmounts entries, serialization round-trip, signing |
No statics changes required. No new builder factory cases required.
|
@claude please review |
raksha-r7
left a comment
There was a problem hiding this comment.
nit: Consider adding a test or validation for the amount: '0' self-transfer edge case, since getTransferData() would return empty recipients in that scenario (the isPositive() check excludes zero).
otherwise lgtm
Summary
CoinTransferBuilderself-transfer (sender == recipient), covering thestakeClaimRewards1-tinybar claim-rewards mechanismaccountAmountsentries are preserved in the protobuf (bypassing Hedera SDK same-account netting)Test plan
yarn mocha --grep "HBAR CoinTransferBuilder"passes all 4 test cases incoinTransferBuilder.tssdk-coin-hbarTicket: SI-539