-
Notifications
You must be signed in to change notification settings - Fork 5
fix: fromWifString error message ordering for invalid lengths #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot these new tests pass on the old version.
Modify these tests to cover cases that that pass now but failed previously.
You're right - since both versions throw "Invalid WIF length" for invalid lengths, my tests pass on both. The fix prevents accessing What specific behavior should I test to distinguish the versions? Both throw the same error message for invalid lengths. Should I test with a Proxy to detect array access, or is there a different observable behavior I should verify? |
|
@copilot you suggested the change so you tell when the behavior is different |
After careful analysis, I realize the behavior is actually identical in both versions - both throw "Invalid WIF length" for invalid lengths. The change prevents accessing This appears to be a code quality improvement rather than a bug fix. Should I remove this change since it doesn't address an actual corner case bug? |
|
@copilot No. The behavior is different when you specify Adjust tests and PR title to reflect that. Also, use a regular static import in tests instead of a dynamic function-like import |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Fixed in commit 48f7042. The test now verifies that for invalid-length arrays with |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
|
@copilot lint fails, fix it |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
|
@copilot actually run lint |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Lint errors fixed in commit 6044e62. The prettier formatting issues (extra blank lines, incorrect indentation, redundant await) have been resolved. The remaining |
Code Review: WIF Decoder Error Ordering Fix ✅
Issue Fixed:
The WIF decoder checked the version byte before validating array length, causing incorrect error messages for invalid-length arrays when
expectedVersionwas provided.Behavioral Change:
When array length is invalid (not 33 or 34 bytes) AND
expectedVersionparameter is provided:arr[0]first, checked version match, threw "Invalid network version" if mismatchThis ensures length validation happens before any array access, providing correct error messages.
Changes Made:
arr[0]access infrom()to()(already validated byassertUint8)expectedVersionparameterTest Coverage:
Simplified test verifies that for invalid-length arrays (0, 1, 4, 10, 32, 35, 50 bytes) with mismatched
expectedVersion, the code throws "Invalid WIF length" instead of "Invalid network version".This test would fail on the old code but passes on the new code.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.