56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""CIP-25 v2 metadata envelope construction — pure unit tests, no network."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from cardano_checkout.mint import build_cip25_metadata
|
|
|
|
|
|
def test_basic_envelope_shape() -> None:
|
|
md = build_cip25_metadata(
|
|
policy_id="abc123",
|
|
asset_name="ExampleStudio-Order-0001",
|
|
name="Example Studio — Custom Order #0001",
|
|
image_cid="bafybeibgen",
|
|
description="Hand-stitched moth pendant",
|
|
properties={"order_id": "0001", "edition": "1 of 1"},
|
|
)
|
|
|
|
assert md["721"]["version"] == "2.0"
|
|
assert "abc123" in md["721"]
|
|
|
|
nft = md["721"]["abc123"]["ExampleStudio-Order-0001"]
|
|
assert nft["name"] == "Example Studio — Custom Order #0001"
|
|
assert nft["image"] == "ipfs://bafybeibgen"
|
|
assert nft["mediaType"] == "image/jpeg"
|
|
assert nft["description"] == "Hand-stitched moth pendant"
|
|
assert nft["order_id"] == "0001"
|
|
assert nft["edition"] == "1 of 1"
|
|
|
|
|
|
def test_description_under_64_chars_stays_a_string() -> None:
|
|
md = build_cip25_metadata(
|
|
policy_id="abc", asset_name="x", name="n",
|
|
image_cid="c", description="short",
|
|
)
|
|
assert md["721"]["abc"]["x"]["description"] == "short"
|
|
|
|
|
|
def test_description_over_64_chars_chunks_to_list() -> None:
|
|
long = "x" * 150
|
|
md = build_cip25_metadata(
|
|
policy_id="abc", asset_name="x", name="n",
|
|
image_cid="c", description=long,
|
|
)
|
|
desc = md["721"]["abc"]["x"]["description"]
|
|
assert isinstance(desc, list)
|
|
assert all(len(chunk) <= 64 for chunk in desc)
|
|
assert "".join(desc) == long
|
|
|
|
|
|
def test_image_uri_has_ipfs_prefix() -> None:
|
|
md = build_cip25_metadata(
|
|
policy_id="abc", asset_name="x", name="n",
|
|
image_cid="bafybeitestcid",
|
|
)
|
|
assert md["721"]["abc"]["x"]["image"].startswith("ipfs://")
|
|
assert "bafybeitestcid" in md["721"]["abc"]["x"]["image"]
|