gabriel / musehub public
test_mpay_ledger_totals.py python
55 lines 2.8 KB
Raw
sha256:f19d5e4a89766fc91b926cdf801255e12dcd968041c0ece8adf6627760788d22 merge: next build — MCP (#291 #292 #295 #324), profiles/sit… Opus 5.5 minor ⚠ breaking 1 day ago
1 """MPay ledger and profile-manifest totals cover every claim, not the newest ``limit`` (musehub#301)."""
2
3 from __future__ import annotations
4
5 from datetime import datetime, timedelta, timezone
6
7 from httpx import AsyncClient
8 from sqlalchemy.ext.asyncio import AsyncSession
9
10 from musehub.db.musehub_identity_models import MusehubIdentity, MusehubMPayClaim
11
12
13 async def _seed_claims(db: AsyncSession) -> None:
14 start = datetime(2026, 11, 1, tzinfo=timezone.utc)
15 claims = [
16 # 1 × 500 (oldest) + 120 × 1 received by testuser; 3 × 7 sent by testuser; one voided 1000 received.
17 MusehubMPayClaim(claim_id=f"sha256:{0:064x}", sender="alice", recipient="testuser", amount_nano=500,
18 nonce_hex=f"{0:064x}", signature="ed25519:x", sender_public_key="ed25519:y",
19 created_at=start),
20 *[
21 MusehubMPayClaim(claim_id=f"sha256:{i:064x}", sender="alice", recipient="testuser", amount_nano=1,
22 nonce_hex=f"{i:064x}", signature="ed25519:x", sender_public_key="ed25519:y",
23 created_at=start + timedelta(minutes=i))
24 for i in range(1, 121)
25 ],
26 *[
27 MusehubMPayClaim(claim_id=f"sha256:{i:064x}", sender="testuser", recipient="alice", amount_nano=7,
28 nonce_hex=f"{i:064x}", signature="ed25519:x", sender_public_key="ed25519:y",
29 created_at=start + timedelta(minutes=i))
30 for i in range(200, 203)
31 ],
32 MusehubMPayClaim(claim_id=f"sha256:{999:064x}", sender="alice", recipient="testuser", amount_nano=1000,
33 nonce_hex=f"{999:064x}", signature="ed25519:x", sender_public_key="ed25519:y",
34 created_at=start, voided_at=start + timedelta(days=1)),
35 ]
36 db.add_all(claims)
37 await db.commit()
38
39
40 async def test_ledger_totals_ignore_the_limit(client: AsyncClient, db_session: AsyncSession, test_user: MusehubIdentity) -> None:
41 await _seed_claims(db_session)
42 for limit, rows in ((1, 1), (100, 100), (500, 121)):
43 response = await client.get(f"/api/profiles/testuser/mpay-ledger?limit={limit}")
44 assert response.status_code == 200, response.text
45 body = response.json()
46 assert len(body["received"]) == rows and len(body["sent"]) == min(limit, 3)
47 assert body["totalReceivedNano"] == 620 and body["totalSentNano"] == 21, limit
48
49
50 async def test_profile_manifest_totals_cover_every_claim(client: AsyncClient, db_session: AsyncSession, test_user: MusehubIdentity) -> None:
51 await _seed_claims(db_session)
52 response = await client.get("/api/profiles/testuser")
53 assert response.status_code == 200, response.text
54 body = response.json()
55 assert body["mpayTotalReceivedNano"] == 620 and body["mpayTotalSentNano"] == 21
File History 3 commits
sha256:f19d5e4a89766fc91b926cdf801255e12dcd968041c0ece8adf6627760788d22 merge: next build — MCP (#291 #292 #295 #324), profiles/sit… Opus 5.5 minor ⚠ 1 day ago
sha256:7a1f4dfd571e937cb1032574d5c0965ba04ad520adcf523dec123d7a34746236 merge: rc26 — profiles/site wave (#119 #301 #303 #307 #314;… Opus 5.5 minor ⚠ 1 day ago
sha256:d5a444bc3d2142a9e90f5dd56f4f51fdfccdd0e4c87d3b90702914c5d99470a3 fix(profiles): MPay totals cover every claim; org roster sh… Opus 5.5 minor ⚠ 2 days ago