test: add comprehensive roundtrip tests and fix leading zeros bug - #55
Open
sumanjeet0012 wants to merge 3 commits into
Open
sumanjeet0012 wants to merge 3 commits into
sumanjeet0012 wants to merge 3 commits into
Conversation
sumanjeet0012
force-pushed
the
fix-issue-40
branch
from
July 13, 2026 13:40
f2bf2f3 to
4033614
Compare
acul71
requested changes
Sep 7, 2026
acul71
left a comment
Contributor
There was a problem hiding this comment.
Review (maintainer)
Thanks for the thorough round-trip coverage and the leading-zeros fix in BaseStringConverter / Base16StringConverter. This looks like the preferred fix relative to overlapping PR #48 (similar converter changes): #55 has green CI and broader tests aligned with #40.
Blocker
Missing newsfragment — please add newsfragments/40.bugfix.rst with a short user-facing note that leading zero bytes are preserved for integer-based multibase encodings, ending with a trailing newline. This is mandatory before approval.
Also note
- Branch is 6 commits behind
origin/master(dry-run merge is clean; please rebase/merge when convenient). - Minor:
encodestill shadows the builtin namebytes; Base16 decode comment still mentions case normalization after switching tobytes.fromhex.
Validation
Local make lint, typecheck, test (362 passed), and docs-ci all passed. GitHub checks are green.
Request changes until the newsfragment is added; happy to re-review promptly after that.
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.
Fixes #40
Description
This pull request adds comprehensive round-trip tests with random data to verify that all encodings in
py-multibasecorrectly handle various data shapes, including leading zero bytes and extreme sizes. In addition, it fixes a bug whereBaseStringConverterwas incorrectly dropping leading zeros upon encoding/decoding.Changes
tests/test_roundtrip.pywith random data generators covering all 24 supported encodings (e.g.base2,base8,base10,base16,base32z,base36,base58btc, etc.).b'\x00\x00'), all ones (b'\xff\xff'), and leading zeroes (b'\x00hello').BaseStringConverter.encodeanddecodeinmultibase/converters.pyto correctly preserve leading zero bytes manually, asint.from_bytesnaturally truncates them.Base16StringConverter.decodeinmultibase/converters.pyto usebytes.fromhex()instead of relying on the integer representation decoding.