From 180892830d0655eb4c6bd4ccea1ce0328411ea89 Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Mon, 13 Jul 2026 14:31:05 +0530 Subject: [PATCH 1/3] test: add fuzz testing using hypothesis --- pyproject.toml | 1 + tests/test_fuzz.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/test_fuzz.py diff --git a/pyproject.toml b/pyproject.toml index 01f775d..da7b0f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ dev = [ "Sphinx>=5.0.0", "build>=0.9.0", "bump-my-version>=1.2.0", + "hypothesis", "mypy", "pre-commit", "pytest", diff --git a/tests/test_fuzz.py b/tests/test_fuzz.py new file mode 100644 index 0000000..4152821 --- /dev/null +++ b/tests/test_fuzz.py @@ -0,0 +1,30 @@ +from hypothesis import given, strategies as st, settings +from multibase import decode, encode, ENCODINGS + +@given(st.binary(max_size=200)) +@settings(max_examples=1000) +def test_decode_never_crashes(data): + """decode() should raise an exception, not crash.""" + try: + decode(data) + except Exception: + pass # Any exception is fine, just no crashes + +@given(st.text(max_size=200)) +@settings(max_examples=1000) +def test_decode_string_never_crashes(data): + try: + decode(data) + except Exception: + pass + +@given(st.binary(min_size=1, max_size=100)) +@settings(max_examples=500) +def test_roundtrip_never_crashes(data): + """encode then decode should never crash.""" + for enc in ENCODINGS: + try: + encoded = encode(enc.encoding, data) + decode(encoded) + except Exception: + pass From 4cc5d292da7e0b12bdfab1361f02284e23a81776 Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Mon, 13 Jul 2026 19:10:07 +0530 Subject: [PATCH 2/3] style: fix formatting for fuzz tests --- tests/test_fuzz.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_fuzz.py b/tests/test_fuzz.py index 4152821..8717505 100644 --- a/tests/test_fuzz.py +++ b/tests/test_fuzz.py @@ -1,5 +1,8 @@ -from hypothesis import given, strategies as st, settings -from multibase import decode, encode, ENCODINGS +from hypothesis import given, settings +from hypothesis import strategies as st + +from multibase import ENCODINGS, decode, encode + @given(st.binary(max_size=200)) @settings(max_examples=1000) @@ -10,6 +13,7 @@ def test_decode_never_crashes(data): except Exception: pass # Any exception is fine, just no crashes + @given(st.text(max_size=200)) @settings(max_examples=1000) def test_decode_string_never_crashes(data): @@ -18,6 +22,7 @@ def test_decode_string_never_crashes(data): except Exception: pass + @given(st.binary(min_size=1, max_size=100)) @settings(max_examples=500) def test_roundtrip_never_crashes(data): From d4438246e3d6a8cd97c1bd6afb42274260efb7d2 Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Sat, 24 Oct 2026 12:42:53 +0530 Subject: [PATCH 3/3] Add newsfragment for #43 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- newsfragments/43.internal.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/43.internal.rst diff --git a/newsfragments/43.internal.rst b/newsfragments/43.internal.rst new file mode 100644 index 0000000..c198829 --- /dev/null +++ b/newsfragments/43.internal.rst @@ -0,0 +1 @@ +Add Hypothesis-based fuzz tests that exercise the decoder with arbitrary binary and text input.