fix(sdk-coin-etc): fix hex validation in queryAddressBalance and getAddressNonce#9154
Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Draft
fix(sdk-coin-etc): fix hex validation in queryAddressBalance and getAddressNonce#9154bitgo-ai-agent-dev[bot] wants to merge 1 commit into
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Conversation
…ddressNonce Replace isNaN() checks with a strict hex regex validator. isNaN() returns true for bare '0x' (valid zero-balance response from some RPC nodes), causing the recovery flow to throw instead of returning zero. Also guard against BN parsing empty string by falling back to '0' when the hex suffix is absent. Add unit tests covering standard hex, '0x0', bare '0x', missing result, RPC error, and non-hex result cases. Ticket: SPT-78 Session-Id: f9f4d3e1-2080-4145-88f2-ff2c4dbb6718 Task-Id: 569e8750-ba8b-4ce0-95af-935c9fd486d6
f8c16ad to
c800e16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
isNaN(result.result)checks with a proper hex regex validator (/^0x[0-9a-fA-F]*$/) inqueryAddressBalanceandgetAddressNonce|| '0'when parsing the hex suffix so that a bare'0x'response (valid zero in some RPC nodes) parses as zero instead of throwing'0x0', bare'0x'(zero balance edge case), missing result, RPC error, and non-hex garbageWhy
'0x'rather than'0x0'for a zero balance.isNaN('0x')returnstruein JavaScript, so the recovery flow threw an opaque "Incorrect Balance Hex" error instead of treating the address as having a zero balance.isNaNis not the right tool for validating Ethereum hex strings; the regex^0x[0-9a-fA-F]*$is explicit and handles all valid cases.Test plan
yarn unit-test --scope @bitgo/sdk-coin-etc— 30 tests passingyarn lint --scope @bitgo/sdk-coin-etc— no lint errorsTicket: SPT-78