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
There are no tests that validate
sum()output against the official multihash test vectors. go-multihash hasTestSpecVectorsthat runs vectors fromspec/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:
Proposed Solution
Add the multihash spec submodule:
Create test:
Related
spec_test.goTestSpecVectors