The only test for Code.tag() checks 4 codecs out of 603. There is no parametrized test that verifies every codec returns the correct tag, which is why 6 missing tags went undetected.
Problem
The current test in tests/test_code.py only covers 4 codecs:
def test_code_tag(self):
code = Code(0x12) # sha2-256
assert code.tag() == "multihash"
code = Code(0x04) # ip4
assert code.tag() == "multiaddr"
code = Code(0x01) # cidv1
assert code.tag() == "cid"
code = Code(0x55) # raw
assert code.tag() == "ipld"
This covers 4 out of 603 codecs and 4 out of 23 tags. The 6 missing tags (multikey, multisig, nonce, shelter, softhash, vlad) went undetected because no test exercises codecs from those categories.
Proposed Solution
Add a parametrized test that checks at least one codec from every tag category:
TAG_TEST_CASES = [
# (code, expected_tag)
(0x12, "multihash"), # sha2-256
(0x04, "multiaddr"), # ip4
(0x70, "ipld"), # dag-pb
(0x01, "cid"), # cidv1
(0x50, "serialization"), # protobuf
(0x30, "multiformat"), # multicodec
(0xE7, "key"), # secp256k1-pub
(0x2F, "namespace"), # path
(0x22, "hash"), # murmur3-x64-64
(0x1A14, "holochain"), # (if applicable)
(0x900, "transport"), # transport-bitswap
(0xD0E7, "varsig"), # es256k
(0xF101, "filecoin"), # fil-commitment-unsealed
(0x2000, "encryption"), # aes-gcm-256
(0xCE11, "zeroxcert"), # zeroxcert-imprint-256
(0x1100, "libp2p"), # (if applicable)
(0xA000, "multikey"), # chacha20-poly1305
(0x123B, "nonce"), # nonce
(0xCC01, "softhash"), # iscc
(0x1207, "vlad"), # vlad
# multisig + shelter codecs...
]
@pytest.mark.parametrize("code,expected_tag", TAG_TEST_CASES)
def test_code_tag_all_categories(code, expected_tag):
assert Code(code).tag() == expected_tag
Additionally, add a test that verifies no codec returns "<unknown>":
def test_no_unknown_tags():
"""Every codec in CODECS should have a recognized tag."""
for name, info in CODECS.items():
code = Code(info["prefix"])
assert code.tag() != "<unknown>", f"Codec {name} (0x{info['prefix']:x}) has unknown tag"
Related
- Test file:
tests/test_code.py
- Function under test:
_get_tag() in multicodec/code.py
The only test for
Code.tag()checks 4 codecs out of 603. There is no parametrized test that verifies every codec returns the correct tag, which is why 6 missing tags went undetected.Problem
The current test in
tests/test_code.pyonly covers 4 codecs:This covers 4 out of 603 codecs and 4 out of 23 tags. The 6 missing tags (
multikey,multisig,nonce,shelter,softhash,vlad) went undetected because no test exercises codecs from those categories.Proposed Solution
Add a parametrized test that checks at least one codec from every tag category:
Additionally, add a test that verifies no codec returns
"<unknown>":Related
tests/test_code.py_get_tag()inmulticodec/code.py