multiformats / multiformats/py-multihash
No spec vector tests validating `sum()` against official test vectors
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
-
Add the multihash spec submodule:
git submodule add https://github.com/multiformats/multihash spec/multihash -
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
- Go spec vector test: go-multihash
spec_test.goTestSpecVectors - Official vectors: multihash/tests/values/test_cases.csv
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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