"""Tests for Issue #1 — Profile Page Reimagination. Covers: 1. Genesis ID functions for attestation and MPay 2. Canonical form / determinism / collision resistance 3. Attestation signature verification (pure, no DB) 4. MPay signature verification (pure, no DB) 5. Pydantic schema validation (ProfileManifest, AttestationResponse, MPayClaimResponse) 6. Service layer — attestation CRUD (async DB mocks) 7. Service layer — MPay claim record + ledger (async DB mocks) 8. Service layer — profile manifest builder (async DB mocks) 9. API route smoke tests (FastAPI TestClient) """ from __future__ import annotations import json from datetime import datetime, timezone from unittest.mock import AsyncMock, MagicMock, patch import pytest from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey from muse.core.types import encode_pubkey, encode_sig, long_id, split_sig from musehub.core.genesis import compute_attestation_id, compute_mpay_claim_id from musehub.models.musehub import ( ActivityDomain, AttestationBadge, AttestationRequest, AttestationResponse, MPayClaimRequest, MPayClaimResponse, MPayLedgerResponse, OrgManifest, ProfileManifest, ProfileRepoSummary, TrustChainEntry, ) from musehub.services.musehub_attestations import ( attestation_to_badge, verify_attestation_signature, ) from musehub.services.musehub_mpay import verify_mpay_signature # --------------------------------------------------------------------------- # Shared fixtures # --------------------------------------------------------------------------- _TS = "2026-04-21T12:00:00+00:00" _ATTESTER = "gabriel" _SUBJECT = "aria" _CLAIM = '{"type":"human","confidence":0.99}' _ATTESTER2 = "maestro" _SENDER = "gabriel" _RECIPIENT = "aria" _AMOUNT_NANO = 1_000_000 _NONCE_HEX = "a" * 64 def _make_ed25519_pair() -> tuple[Ed25519PrivateKey, str]: """Return (privkey, pubkey_prefixed).""" privkey = Ed25519PrivateKey.generate() pubkey_bytes = privkey.public_key().public_bytes_raw() return privkey, encode_pubkey("ed25519", pubkey_bytes) def _sign_attest( privkey: Ed25519PrivateKey, attester: str, subject: str, claim: str, ts: str, ) -> str: msg = f"ATTEST\n{attester}\n{subject}\n{claim}\n{ts}".encode() return encode_sig("ed25519", privkey.sign(msg)) def _sign_mpay( privkey: Ed25519PrivateKey, sender: str, recipient: str, amount_nano: int, nonce_hex: str, ) -> str: msg = f"MPAY\n{sender}\n{recipient}\n{amount_nano}\n{nonce_hex}".encode() return encode_sig("ed25519", privkey.sign(msg)) # --------------------------------------------------------------------------- # 1 & 2. Genesis ID canonical form, determinism, collision resistance # --------------------------------------------------------------------------- class TestAttestationGenesisId: def test_canonical_form(self) -> None: aid = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) assert aid.startswith("sha256:") assert len(aid) == 71 def test_deterministic(self) -> None: a1 = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) a2 = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) assert a1 == a2 def test_distinct_attester(self) -> None: a1 = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) a2 = compute_attestation_id(_ATTESTER2, _SUBJECT, _CLAIM, _TS) assert a1 != a2 def test_distinct_subject(self) -> None: a1 = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) a2 = compute_attestation_id(_ATTESTER, "other_subject", _CLAIM, _TS) assert a1 != a2 def test_distinct_claim(self) -> None: a1 = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) a2 = compute_attestation_id(_ATTESTER, _SUBJECT, '{"type":"org"}', _TS) assert a1 != a2 def test_distinct_timestamp(self) -> None: a1 = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) a2 = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, "2026-05-01T00:00:00+00:00") assert a1 != a2 class TestMPayGenesisId: def test_canonical_form(self) -> None: cid = compute_mpay_claim_id(_SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) assert cid.startswith("sha256:") assert len(cid) == 71 def test_deterministic(self) -> None: c1 = compute_mpay_claim_id(_SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) c2 = compute_mpay_claim_id(_SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) assert c1 == c2 def test_distinct_amount(self) -> None: c1 = compute_mpay_claim_id(_SENDER, _RECIPIENT, 1_000_000, _NONCE_HEX) c2 = compute_mpay_claim_id(_SENDER, _RECIPIENT, 2_000_000, _NONCE_HEX) assert c1 != c2 def test_distinct_nonce(self) -> None: c1 = compute_mpay_claim_id(_SENDER, _RECIPIENT, _AMOUNT_NANO, "a" * 64) c2 = compute_mpay_claim_id(_SENDER, _RECIPIENT, _AMOUNT_NANO, "b" * 64) assert c1 != c2 # --------------------------------------------------------------------------- # 3. Attestation signature verification # --------------------------------------------------------------------------- class TestAttestationSignatureVerification: def test_valid_signature(self) -> None: privkey, pubkey = _make_ed25519_pair() sig = _sign_attest(privkey, _ATTESTER, _SUBJECT, _CLAIM, _TS) ok, reason = verify_attestation_signature( _ATTESTER, _SUBJECT, _CLAIM, _TS, sig, pubkey ) assert ok is True assert reason == "" def test_wrong_message_fails(self) -> None: privkey, pubkey = _make_ed25519_pair() # Sign with different claim sig = _sign_attest(privkey, _ATTESTER, _SUBJECT, '{"type":"org"}', _TS) ok, reason = verify_attestation_signature( _ATTESTER, _SUBJECT, _CLAIM, _TS, sig, pubkey ) assert ok is False def test_missing_prefix_fails(self) -> None: privkey, pubkey = _make_ed25519_pair() sig = _sign_attest(privkey, _ATTESTER, _SUBJECT, _CLAIM, _TS) bare_sig = split_sig(sig)[1] ok, reason = verify_attestation_signature( _ATTESTER, _SUBJECT, _CLAIM, _TS, bare_sig, pubkey ) assert ok is False assert "ed25519:" in reason def test_wrong_public_key_fails(self) -> None: privkey, _ = _make_ed25519_pair() _, other_pubkey = _make_ed25519_pair() sig = _sign_attest(privkey, _ATTESTER, _SUBJECT, _CLAIM, _TS) ok, _ = verify_attestation_signature( _ATTESTER, _SUBJECT, _CLAIM, _TS, sig, other_pubkey ) assert ok is False # --------------------------------------------------------------------------- # 4. MPay signature verification # --------------------------------------------------------------------------- class TestMPaySignatureVerification: def test_valid_signature(self) -> None: privkey, pubkey = _make_ed25519_pair() sig = _sign_mpay(privkey, _SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) ok, reason = verify_mpay_signature( _SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX, sig, pubkey ) assert ok is True assert reason == "" def test_tampered_amount_fails(self) -> None: privkey, pubkey = _make_ed25519_pair() sig = _sign_mpay(privkey, _SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) # Verify with different amount ok, _ = verify_mpay_signature( _SENDER, _RECIPIENT, _AMOUNT_NANO + 1, _NONCE_HEX, sig, pubkey ) assert ok is False def test_missing_prefix_fails(self) -> None: privkey, pubkey = _make_ed25519_pair() sig = _sign_mpay(privkey, _SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) bare_sig = split_sig(sig)[1] ok, reason = verify_mpay_signature( _SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX, bare_sig, pubkey ) assert ok is False # --------------------------------------------------------------------------- # 5. Pydantic schema validation # --------------------------------------------------------------------------- class TestPydanticSchemas: def _make_repo_summary(self) -> ProfileRepoSummary: return ProfileRepoSummary( repo_id=long_id("a" * 64), name="test-repo", owner="gabriel", slug="test-repo", visibility="public", last_activity_at=None, created_at=datetime(2026, 1, 1, tzinfo=timezone.utc), ) def test_profile_manifest_human(self) -> None: manifest = ProfileManifest( identity_id=long_id("a" * 64), handle="gabriel", identity_type="human", avax_address="0xABCDEF", created_at=datetime(2026, 1, 1, tzinfo=timezone.utc), updated_at=datetime(2026, 1, 1, tzinfo=timezone.utc), ) assert manifest.identity_type == "human" assert manifest.avax_address == "0xABCDEF" assert manifest.org is None assert manifest.trust_chain == [] def test_profile_manifest_agent(self) -> None: manifest = ProfileManifest( identity_id=long_id("b" * 64), handle="aria", identity_type="agent", agent_model="claude-sonnet-4-6", agent_capabilities=["push", "pull"], trust_chain=[ TrustChainEntry(handle="aria", identity_type="agent", spawned_by="gabriel"), TrustChainEntry(handle="gabriel", identity_type="human", spawned_by=None), ], created_at=datetime(2026, 1, 1, tzinfo=timezone.utc), updated_at=datetime(2026, 1, 1, tzinfo=timezone.utc), ) assert manifest.identity_type == "agent" assert len(manifest.trust_chain) == 2 assert manifest.trust_chain[-1].identity_type == "human" def test_profile_manifest_org(self) -> None: manifest = ProfileManifest( identity_id=long_id("c" * 64), handle="acme", identity_type="org", org=OrgManifest(members=["gabriel", "aria"], quorum=2), created_at=datetime(2026, 1, 1, tzinfo=timezone.utc), updated_at=datetime(2026, 1, 1, tzinfo=timezone.utc), ) assert manifest.org is not None assert manifest.org.quorum == 2 def test_activity_domain_grid_length(self) -> None: grid = [0] * 364 domain = ActivityDomain(domain="code", grid=grid, peak=0, total=0) assert len(domain.grid) == 364 def test_attestation_response(self) -> None: issued = datetime(2026, 4, 21, 12, 0, 0, tzinfo=timezone.utc) resp = AttestationResponse( attestation_id=long_id("d" * 64), attester="gabriel", subject="aria", claim='{"type":"human"}', signature="ed25519:fakesig", attester_public_key="ed25519:fakepubkey", issued_at=issued, ) assert resp.revoked_at is None def test_attestation_badge_claim_type(self) -> None: issued = datetime(2026, 4, 21, 12, 0, 0, tzinfo=timezone.utc) a = AttestationResponse( attestation_id=long_id("e" * 64), attester="gabriel", subject="aria", claim='{"type":"human","confidence":0.99}', signature="ed25519:sig", attester_public_key="ed25519:pk", issued_at=issued, ) badge = attestation_to_badge(a) assert badge.claim_type == "human" def test_mpay_claim_response(self) -> None: now = datetime(2026, 4, 21, tzinfo=timezone.utc) resp = MPayClaimResponse( claim_id=long_id("f" * 64), sender="gabriel", recipient="aria", amount_nano=1_000_000, nonce_hex="a" * 64, signature="ed25519:sig", sender_public_key="ed25519:pk", created_at=now, ) assert resp.confirmed_at is None assert resp.voided_at is None def test_mpay_ledger_totals(self) -> None: now = datetime(2026, 4, 21, tzinfo=timezone.utc) def _claim(amount: int) -> MPayClaimResponse: return MPayClaimResponse( claim_id=long_id("a" * 64), sender="gabriel", recipient="aria", amount_nano=amount, nonce_hex="b" * 64, signature="ed25519:sig", sender_public_key="ed25519:pk", created_at=now, ) ledger = MPayLedgerResponse( handle="gabriel", sent=[_claim(500_000), _claim(250_000)], received=[_claim(1_000_000)], total_sent_nano=750_000, total_received_nano=1_000_000, ) assert ledger.total_sent_nano == 750_000 assert ledger.total_received_nano == 1_000_000 # --------------------------------------------------------------------------- # 6. Service layer — attestation (async DB mocks) # --------------------------------------------------------------------------- class TestAttestationService: @pytest.mark.asyncio async def test_issue_attestation_valid_sig(self) -> None: privkey, pubkey = _make_ed25519_pair() issued_at = datetime(2026, 4, 21, 12, 0, 0, tzinfo=timezone.utc) sig = _sign_attest(privkey, _ATTESTER, _SUBJECT, _CLAIM, issued_at.isoformat()) req = AttestationRequest( attester=_ATTESTER, subject=_SUBJECT, claim=_CLAIM, signature=sig, attester_public_key=pubkey, issued_at=issued_at, ) # Mock DB: no existing record → insert mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = None mock_db.execute.return_value = mock_result from musehub.services.musehub_attestations import issue_attestation result = await issue_attestation(mock_db, req) assert result.attester == _ATTESTER assert result.subject == _SUBJECT assert result.revoked_at is None mock_db.commit.assert_called_once() @pytest.mark.asyncio async def test_issue_attestation_invalid_sig_raises(self) -> None: _, pubkey = _make_ed25519_pair() issued_at = datetime(2026, 4, 21, 12, 0, 0, tzinfo=timezone.utc) req = AttestationRequest( attester=_ATTESTER, subject=_SUBJECT, claim=_CLAIM, signature="ed25519:invalidsignaturedata", attester_public_key=pubkey, issued_at=issued_at, ) mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = None mock_db.execute.return_value = mock_result from musehub.services.musehub_attestations import issue_attestation with pytest.raises(ValueError, match="Invalid attestation signature"): await issue_attestation(mock_db, req) @pytest.mark.asyncio async def test_issue_attestation_idempotent(self) -> None: privkey, pubkey = _make_ed25519_pair() issued_at = datetime(2026, 4, 21, 12, 0, 0, tzinfo=timezone.utc) sig = _sign_attest(privkey, _ATTESTER, _SUBJECT, _CLAIM, issued_at.isoformat()) aid = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, issued_at.isoformat()) req = AttestationRequest( attester=_ATTESTER, subject=_SUBJECT, claim=_CLAIM, signature=sig, attester_public_key=pubkey, issued_at=issued_at, ) existing_row = { "attestation_id": aid, "attester": _ATTESTER, "subject": _SUBJECT, "claim": _CLAIM, "signature": sig, "attester_public_key": pubkey, "issued_at": issued_at, "revoked_at": None, } mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = existing_row mock_db.execute.return_value = mock_result from musehub.services.musehub_attestations import issue_attestation result = await issue_attestation(mock_db, req) # Should return existing without insert assert result.attestation_id == aid mock_db.commit.assert_not_called() @pytest.mark.asyncio async def test_revoke_attestation_wrong_revoker_raises(self) -> None: aid = compute_attestation_id(_ATTESTER, _SUBJECT, _CLAIM, _TS) existing_row = { "attestation_id": aid, "attester": _ATTESTER, "subject": _SUBJECT, "claim": _CLAIM, "signature": "ed25519:sig", "attester_public_key": "ed25519:pk", "issued_at": datetime(2026, 4, 21, tzinfo=timezone.utc), "revoked_at": None, } mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = existing_row mock_db.execute.return_value = mock_result from musehub.services.musehub_attestations import revoke_attestation with pytest.raises(PermissionError): await revoke_attestation(mock_db, aid, revoker="not_gabriel") @pytest.mark.asyncio async def test_revoke_attestation_not_found_raises(self) -> None: mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = None mock_db.execute.return_value = mock_result from musehub.services.musehub_attestations import revoke_attestation with pytest.raises(KeyError): await revoke_attestation(mock_db, long_id("x" * 64), revoker=_ATTESTER) # --------------------------------------------------------------------------- # 7. Service layer — MPay claim (async DB mocks) # --------------------------------------------------------------------------- class TestMPayService: @pytest.mark.asyncio async def test_record_claim_valid_sig(self) -> None: privkey, pubkey = _make_ed25519_pair() sig = _sign_mpay(privkey, _SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) req = MPayClaimRequest( sender=_SENDER, recipient=_RECIPIENT, amount_nano=_AMOUNT_NANO, nonce_hex=_NONCE_HEX, signature=sig, sender_public_key=pubkey, ) mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = None mock_db.execute.return_value = mock_result from musehub.services.musehub_mpay import record_mpay_claim result = await record_mpay_claim(mock_db, req) assert result.sender == _SENDER assert result.recipient == _RECIPIENT assert result.amount_nano == _AMOUNT_NANO mock_db.commit.assert_called_once() @pytest.mark.asyncio async def test_record_claim_invalid_sig_raises(self) -> None: _, pubkey = _make_ed25519_pair() req = MPayClaimRequest( sender=_SENDER, recipient=_RECIPIENT, amount_nano=_AMOUNT_NANO, nonce_hex=_NONCE_HEX, signature="ed25519:badsig", sender_public_key=pubkey, ) mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = None mock_db.execute.return_value = mock_result from musehub.services.musehub_mpay import record_mpay_claim with pytest.raises(ValueError, match="Invalid MPay signature"): await record_mpay_claim(mock_db, req) @pytest.mark.asyncio async def test_record_claim_idempotent(self) -> None: privkey, pubkey = _make_ed25519_pair() sig = _sign_mpay(privkey, _SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) claim_id = compute_mpay_claim_id(_SENDER, _RECIPIENT, _AMOUNT_NANO, _NONCE_HEX) now = datetime(2026, 4, 21, tzinfo=timezone.utc) existing_row = { "claim_id": claim_id, "sender": _SENDER, "recipient": _RECIPIENT, "amount_nano": _AMOUNT_NANO, "nonce_hex": _NONCE_HEX, "signature": sig, "sender_public_key": pubkey, "memo": None, "created_at": now, "confirmed_at": None, "voided_at": None, } mock_db = AsyncMock() mock_result = MagicMock() mock_result.mappings.return_value.one_or_none.return_value = existing_row mock_db.execute.return_value = mock_result req = MPayClaimRequest( sender=_SENDER, recipient=_RECIPIENT, amount_nano=_AMOUNT_NANO, nonce_hex=_NONCE_HEX, signature=sig, sender_public_key=pubkey, ) from musehub.services.musehub_mpay import record_mpay_claim result = await record_mpay_claim(mock_db, req) assert result.claim_id == claim_id mock_db.commit.assert_not_called() # --------------------------------------------------------------------------- # 8. Service layer — profile manifest builder # --------------------------------------------------------------------------- class TestProfileManifestBuilder: def _make_identity( self, handle: str = "gabriel", identity_type: str = "human", spawned_by: str | None = None, ) -> MagicMock: identity = MagicMock() identity.identity_id = long_id("a" * 64) identity.handle = handle identity.identity_type = identity_type identity.display_name = f"Display {handle}" identity.bio = None identity.avatar_url = None identity.location = None identity.website_url = None identity.social_url = None identity.is_verified = False identity.cc_license = None identity.pinned_repo_ids = [] identity.avax_address = "0xABC" if identity_type == "human" else None identity.agent_model = "claude-sonnet-4-6" if identity_type == "agent" else None identity.agent_capabilities = ["push"] if identity_type == "agent" else [] identity.org_members = ["gabriel", "aria"] if identity_type == "org" else None identity.org_quorum = 2 if identity_type == "org" else None identity.org_treasury_address = None identity.spawned_by = spawned_by identity.deleted_at = None identity.created_at = datetime(2026, 1, 1, tzinfo=timezone.utc) identity.updated_at = datetime(2026, 1, 1, tzinfo=timezone.utc) return identity @pytest.mark.asyncio async def test_manifest_returns_none_for_unknown_handle(self) -> None: from musehub.services.musehub_profile import build_profile_manifest with patch( "musehub.services.musehub_profile.get_profile_by_username", new=AsyncMock(return_value=None), ): result = await build_profile_manifest(AsyncMock(), "unknown") assert result is None @pytest.mark.asyncio async def test_manifest_human_fields(self) -> None: from musehub.services.musehub_profile import build_profile_manifest identity = self._make_identity("gabriel", "human") with ( patch("musehub.services.musehub_profile.get_profile_by_username", new=AsyncMock(return_value=identity)), patch("musehub.services.musehub_profile.get_public_repos", new=AsyncMock(return_value=[])), patch("musehub.services.musehub_profile.build_activity_canvas", new=AsyncMock(return_value=[])), ): result = await build_profile_manifest(AsyncMock(), "gabriel") assert result is not None assert result.identity_type == "human" assert result.avax_address == "0xABC" assert result.org is None assert result.trust_chain == [] @pytest.mark.asyncio async def test_manifest_org_fields(self) -> None: from musehub.services.musehub_profile import build_profile_manifest identity = self._make_identity("acme", "org") with ( patch("musehub.services.musehub_profile.get_profile_by_username", new=AsyncMock(return_value=identity)), patch("musehub.services.musehub_profile.get_public_repos", new=AsyncMock(return_value=[])), patch("musehub.services.musehub_profile.build_activity_canvas", new=AsyncMock(return_value=[])), ): result = await build_profile_manifest(AsyncMock(), "acme") assert result is not None assert result.org is not None assert result.org.members == ["gabriel", "aria"] assert result.org.quorum == 2 assert result.avax_address is None @pytest.mark.asyncio async def test_manifest_mpay_totals_passed_through(self) -> None: from musehub.services.musehub_profile import build_profile_manifest identity = self._make_identity("gabriel", "human") with ( patch("musehub.services.musehub_profile.get_profile_by_username", new=AsyncMock(return_value=identity)), patch("musehub.services.musehub_profile.get_public_repos", new=AsyncMock(return_value=[])), patch("musehub.services.musehub_profile.build_activity_canvas", new=AsyncMock(return_value=[])), ): result = await build_profile_manifest( AsyncMock(), "gabriel", mpay_sent_nano=500_000, mpay_received_nano=1_000_000 ) assert result is not None assert result.mpay_total_sent_nano == 500_000 assert result.mpay_total_received_nano == 1_000_000 # --------------------------------------------------------------------------- # 9. Activity canvas unit tests # --------------------------------------------------------------------------- class TestActivityCanvas: def test_grid_index_today_is_last(self) -> None: from musehub.services.musehub_profile import _date_to_grid_index, _GRID_DAYS today = datetime(2026, 4, 21, tzinfo=timezone.utc) idx = _date_to_grid_index(today, today) assert idx == _GRID_DAYS - 1 def test_grid_index_out_of_range_returns_none(self) -> None: from musehub.services.musehub_profile import _date_to_grid_index today = datetime(2026, 4, 21, tzinfo=timezone.utc) past = datetime(2025, 1, 1, tzinfo=timezone.utc) # >364 days ago idx = _date_to_grid_index(today, past) assert idx is None def test_grid_index_future_returns_none(self) -> None: from musehub.services.musehub_profile import _date_to_grid_index today = datetime(2026, 4, 21, tzinfo=timezone.utc) future = datetime(2026, 5, 1, tzinfo=timezone.utc) idx = _date_to_grid_index(today, future) assert idx is None def test_empty_grid_length(self) -> None: from musehub.services.musehub_profile import _empty_grid, _GRID_DAYS assert len(_empty_grid()) == _GRID_DAYS def test_grid_to_domain(self) -> None: from musehub.services.musehub_profile import _grid_to_domain grid = [0] * 363 + [5] domain = _grid_to_domain("code", grid) assert domain.peak == 5 assert domain.total == 5 assert domain.domain == "code"