Skip to content

test: add comprehensive roundtrip tests and fix leading zeros bug#55

Open
sumanjeet0012 wants to merge 3 commits into
multiformats:masterfrom
sumanjeet0012:fix-issue-40
Open

test: add comprehensive roundtrip tests and fix leading zeros bug#55
sumanjeet0012 wants to merge 3 commits into
multiformats:masterfrom
sumanjeet0012:fix-issue-40

Conversation

@sumanjeet0012

Copy link
Copy Markdown
Contributor

Fixes #40

Description

This pull request adds comprehensive round-trip tests with random data to verify that all encodings in py-multibase correctly handle various data shapes, including leading zero bytes and extreme sizes. In addition, it fixes a bug where BaseStringConverter was incorrectly dropping leading zeros upon encoding/decoding.

Changes

  • Created tests/test_roundtrip.py with random data generators covering all 24 supported encodings (e.g. base2, base8, base10, base16, base32z, base36, base58btc, etc.).
  • The tests check data integrity on edge-cases such as random sizes, all zeros (b'\x00\x00'), all ones (b'\xff\xff'), and leading zeroes (b'\x00hello').
  • Fixed BaseStringConverter.encode and decode in multibase/converters.py to correctly preserve leading zero bytes manually, as int.from_bytes naturally truncates them.
  • Fixed Base16StringConverter.decode in multibase/converters.py to use bytes.fromhex() instead of relying on the integer representation decoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No round-trip tests with random data and leading zeros

1 participant