import pytest
from content_addressable import ContentId, content_id, from_canonical_dagcbor
FOREIGN_CID_BYTES = bytes.fromhex(
"017112200707070707070707070707070707070707070707070707070707070707070707"
)
FOREIGN_CID_STR = "bafyreiaha4dqobyha4dqobyha4dqobyha4dqobyha4dqobyha4dqobyha4"
FOREIGN_LINK_DAGCBOR = bytes.fromhex(
"d82a582500017112200707070707070707070707070707070707070707"
"070707070707070707070707070707"
)
def test_from_bytes_rejects_a_foreign_cid():
with pytest.raises(ValueError):
ContentId.from_bytes(FOREIGN_CID_BYTES)
def test_parse_rejects_a_foreign_cid():
with pytest.raises(ValueError):
ContentId.parse(FOREIGN_CID_STR)
def test_from_canonical_dagcbor_rejects_a_foreign_cid_link():
with pytest.raises(ValueError):
from_canonical_dagcbor(FOREIGN_LINK_DAGCBOR)
def test_an_on_profile_id_still_round_trips():
cid = content_id({"name": "alpha"})
assert ContentId.from_bytes(cid.to_bytes()) == cid
assert ContentId.parse(str(cid)) == cid