Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dev = [
"Sphinx>=5.0.0",
"build>=0.9.0",
"bump-my-version>=1.2.0",
"hypothesis",
"mypy",
"pre-commit",
"pytest",
Expand Down
35 changes: 35 additions & 0 deletions tests/test_fuzz.py
Original file line number Diff line number Diff line change
@@ -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
Loading