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 newsfragments/72.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add property-based fuzz testing using `hypothesis` to ensure CID parsing and encoding are robust against arbitrary input and do not crash.
30 changes: 30 additions & 0 deletions tests/test_fuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from hypothesis import (
given,
settings,
strategies as st,
)

from cid import make_cid


@given(st.binary(max_size=200))
@settings(max_examples=1000)
def test_from_bytes_never_crashes(data):
"""from_bytes should raise ValueError, KeyError, or TypeError, not crash."""
try:
make_cid(data)
except (ValueError, KeyError, TypeError):
pass # Any exception is fine, just no crashes


@given(st.binary(min_size=34, max_size=100))
@settings(max_examples=500)
def test_cid_roundtrip_never_crashes(data):
"""CID encode/decode should never crash."""
try:
cid = make_cid(data)
_ = cid.encode()
_ = str(cid)
_ = cid.prefix()
except (ValueError, KeyError, TypeError):
pass
Loading