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..8717505 --- /dev/null +++ b/tests/test_fuzz.py @@ -0,0 +1,35 @@ +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) +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