Skip to content

No fuzz testing #72

Description

@sumanjeet0012

Go has a fuzz test that exercises Cast(), Bytes(), String(), Prefix(), and JSON round-trip with random input. Python has no fuzz testing.

Proposed Solution

Add property-based tests using hypothesis:

from hypothesis import given, strategies as st, settings
from cid import make_cid, CIDv1, CIDv0

@given(st.binary(max_size=200))
@settings(max_examples=1000)
def test_from_bytes_never_crashes(data):
    """from_bytes should raise ValueError, 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

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions