multiformats / multiformats/py-multihash

No spec vector tests validating `sum()` against official test vectors

Open
#53 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17
Forks
17
Avg merge
1h 5m
Merged PRs (30d)
3

Description

There are no tests that validate sum() output against the official multihash test vectors. go-multihash has TestSpecVectors that runs vectors from spec/multihash/tests/values/test_cases.csv.

Problem

The current test suite uses hardcoded test fixtures. There is no automated validation against the official test vectors that cover edge cases, truncation, and all supported hash functions.

go-multihash runs the official vectors:

func TestSpecVectors(t *testing.T) {
    file, _ := os.Open("spec/multihash/tests/values/test_cases.csv")
    // CSV format: algorithm, bits, input, multihash
    for _, testCase := range values[1:] {
        actual, _ := multihash.Sum([]byte(input), code, int(length/8))
        if actual.HexString() != expectedStr {
            t.Fatalf("got the wrong hash")
        }
    }
}
Proposed Solution
  1. Add the multihash spec submodule:

    git submodule add https://github.com/multiformats/multihash spec/multihash
    
  2. Create test:

    import csv
    import pytest
    from multihash import sum
    
    def test_spec_vectors():
        with open("spec/multihash/tests/values/test_cases.csv") as f:
            reader = csv.reader(f)
            header = next(reader)
            for algorithm, bits_str, input_str, expected_hex in reader:
                length_bits = int(bits_str)
                length_bytes = length_bits // 8
                try:
                    actual = sum(input_str.encode(), algorithm, length=length_bytes)
                except (KeyError, ValueError):
                    pytest.skip(f"Hash {algorithm} not supported")
                    continue
                assert actual.encode("hex").decode() == expected_hex
    
Related

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing test suite and the proposed multihash spec submodule path, spec/multihash/tests/values/test_cases.csv. Add a test that reads the CSV vectors, invokes sum(), and compares the encoded result while handling unsupported algorithms as described. Run the full test suite; done means the official vectors validate supported hash functions and edge cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.