theprotocol-sdk 0.7.2__tar.gz → 0.7.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/PKG-INFO +5 -1
  2. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/README.md +4 -0
  3. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/pyproject.toml +4 -2
  4. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/__init__.py +1 -1
  5. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/exchange/client.py +55 -18
  6. theprotocol_sdk-0.7.3/tests/test_exchange_launch.py +84 -0
  7. theprotocol_sdk-0.7.2/tests/test_exchange_launch.py +0 -41
  8. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/LICENSE +0 -0
  9. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/examples/simple_agent.py +0 -0
  10. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/agent/__init__.py +0 -0
  11. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/agent/base.py +0 -0
  12. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/agent/decorators.py +0 -0
  13. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/agent/router.py +0 -0
  14. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/agent/task_store.py +0 -0
  15. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/agent/well_known.py +0 -0
  16. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/auth/__init__.py +0 -0
  17. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/auth/did_jwt.py +0 -0
  18. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/auth/jws_card.py +0 -0
  19. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/auth/jwt_verifier.py +0 -0
  20. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/authz.py +0 -0
  21. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/__init__.py +0 -0
  22. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/acp.py +0 -0
  23. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/anp/__init__.py +0 -0
  24. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/anp/auth.py +0 -0
  25. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/anp/bridge.py +0 -0
  26. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/anp/did_wba.py +0 -0
  27. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/anp/translation.py +0 -0
  28. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/base.py +0 -0
  29. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/google_a2a.py +0 -0
  30. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/bridges/mcp.py +0 -0
  31. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/client/__init__.py +0 -0
  32. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/client/a2a_client.py +0 -0
  33. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/client/credentials.py +0 -0
  34. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/exceptions.py +0 -0
  35. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/exchange/__init__.py +0 -0
  36. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/forge.py +0 -0
  37. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/guild.py +0 -0
  38. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/messenger.py +0 -0
  39. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/models/__init__.py +0 -0
  40. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/models/a2a_protocol.py +0 -0
  41. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/models/agent_card.py +0 -0
  42. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/models/v1_compat.py +0 -0
  43. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/mtls.py +0 -0
  44. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/payment/__init__.py +0 -0
  45. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/payment/authenticator.py +0 -0
  46. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/payment/client.py +0 -0
  47. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/payment/mtls_client.py +0 -0
  48. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/payment/verifier.py +0 -0
  49. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/registry/__init__.py +0 -0
  50. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/registry/card_verify.py +0 -0
  51. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/registry/cost_composition.py +0 -0
  52. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/transfer/__init__.py +0 -0
  53. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/src/theprotocol/transfer/client.py +0 -0
  54. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/registry/__init__.py +0 -0
  55. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/registry/test_card_verify.py +0 -0
  56. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/registry/test_cost_composition.py +0 -0
  57. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_agent.py +0 -0
  58. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_artifact_roundtrip.py +0 -0
  59. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_auth.py +0 -0
  60. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_authz.py +0 -0
  61. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_bridge_acp.py +0 -0
  62. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_bridge_anp.py +0 -0
  63. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_bridge_google_a2a.py +0 -0
  64. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_bridge_mcp.py +0 -0
  65. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_credentials.py +0 -0
  66. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_did_jwt.py +0 -0
  67. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_forge.py +0 -0
  68. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_guild.py +0 -0
  69. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_jws_card.py +0 -0
  70. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_messenger.py +0 -0
  71. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_models.py +0 -0
  72. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_mtls_enroll.py +0 -0
  73. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_transfer.py +0 -0
  74. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_v1_compat.py +0 -0
  75. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_verifier_reuse.py +0 -0
  76. {theprotocol_sdk-0.7.2 → theprotocol_sdk-0.7.3}/tests/test_well_known.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: theprotocol-sdk
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: Build sovereign AI agents with DID identity on TheProtocol. Speaks the A2A protocol (v1.0) natively, with bridges for Google A2A, ANP, and MCP. Works with Vertex AI, AWS AgentCore, LangGraph, CrewAI.
5
5
  Project-URL: Homepage, https://theprotocol.cloud
6
6
  Project-URL: Documentation, https://docs.theprotocol.cloud
@@ -183,6 +183,10 @@ The private key is written `0600` into a `0700` directory, via a temp file and r
183
183
 
184
184
  ## Changelog
185
185
 
186
+ **0.7.3** (2026-09-22)
187
+ - `ExchangeClient` speaks the documented `/api/v1/agora` paths. Before its first call it asks the registry once whether it serves them; a registry older than V0419 (it does not know the route) is spoken to under `/api/v1/exchange` for the life of the client, so the client works against every registry, and keeps working after a later release drops the old paths. `launch_buy` posts to `launch/buy` (an older registry is sent its `ipo/buy`). `ExchangeClient.base` holds the resolved path.
188
+ - The build backend is pinned (`hatchling==1.27.0`), so every release carries the same package metadata version.
189
+
186
190
  **0.7.2** (2026-09-22)
187
191
  - AGORA words: `ExchangeClient.launch_buy` buys points at launch; `ipo_buy` still works and raises a `DeprecationWarning`. The client keeps calling the long-standing `/api/v1/exchange` paths, which every registry serves; registries from V0419 also answer the documented `/api/v1/agora` names.
188
192
 
@@ -142,6 +142,10 @@ The private key is written `0600` into a `0700` directory, via a temp file and r
142
142
 
143
143
  ## Changelog
144
144
 
145
+ **0.7.3** (2026-09-22)
146
+ - `ExchangeClient` speaks the documented `/api/v1/agora` paths. Before its first call it asks the registry once whether it serves them; a registry older than V0419 (it does not know the route) is spoken to under `/api/v1/exchange` for the life of the client, so the client works against every registry, and keeps working after a later release drops the old paths. `launch_buy` posts to `launch/buy` (an older registry is sent its `ipo/buy`). `ExchangeClient.base` holds the resolved path.
147
+ - The build backend is pinned (`hatchling==1.27.0`), so every release carries the same package metadata version.
148
+
145
149
  **0.7.2** (2026-09-22)
146
150
  - AGORA words: `ExchangeClient.launch_buy` buys points at launch; `ipo_buy` still works and raises a `DeprecationWarning`. The client keeps calling the long-standing `/api/v1/exchange` paths, which every registry serves; registries from V0419 also answer the documented `/api/v1/agora` names.
147
151
 
@@ -1,10 +1,12 @@
1
1
  [build-system]
2
- requires = ["hatchling"]
2
+ # Pinned (2026-09-22): hatchling 1.28+ writes Metadata-Version 2.5, which twine 6.2.0 refuses to upload
3
+ # ("'2.5' is not a valid metadata version"); 1.27.0 writes 2.4, the version every published release carries.
4
+ requires = ["hatchling==1.27.0"]
3
5
  build-backend = "hatchling.build"
4
6
 
5
7
  [project]
6
8
  name = "theprotocol-sdk"
7
- version = "0.7.2"
9
+ version = "0.7.3"
8
10
  description = "Build sovereign AI agents with DID identity on TheProtocol. Speaks the A2A protocol (v1.0) natively, with bridges for Google A2A, ANP, and MCP. Works with Vertex AI, AWS AgentCore, LangGraph, CrewAI."
9
11
  readme = "README.md"
10
12
  license = {text = "Apache-2.0"}
@@ -14,4 +14,4 @@ Usage:
14
14
  from theprotocol.messenger import MessengerClient # OurChat threads (poll/ack inbox, cards)
15
15
  """
16
16
 
17
- __version__ = "0.7.2"
17
+ __version__ = "0.7.3"
@@ -12,7 +12,7 @@ Money model (why you can trust it): points are registry-ledger entries; every
12
12
  money leg settles through the venue escrow on TEG rails — buy escrow is taken
13
13
  on placement, refunds/proceeds drain via the settlement worker. Fees come from
14
14
  SELLER proceeds (a buy never pays more than its escrow). Supply Δ=0 by
15
- construction; the venue self-checks via GET /exchange/admin/invariant.
15
+ construction; the venue self-checks via GET /api/v1/agora/admin/invariant.
16
16
  """
17
17
  import logging
18
18
  import warnings
@@ -23,17 +23,53 @@ import httpx
23
23
  logger = logging.getLogger(__name__)
24
24
 
25
25
 
26
+ AGORA_PREFIX = "/api/v1/agora"
27
+ LEGACY_PREFIX = "/api/v1/exchange"
28
+
29
+
30
+ def _route_missing(r: httpx.Response) -> bool:
31
+ """A 404 whose registry did not know the ROUTE (detail exactly "Not Found"), as opposed to an answer like an
32
+ unknown listing, whose detail names the listing."""
33
+ if r.status_code != 404:
34
+ return False
35
+ try:
36
+ body = r.json()
37
+ except ValueError:
38
+ return True
39
+ detail = body.get("detail") if isinstance(body, dict) else None
40
+ return detail in (None, "Not Found")
41
+
42
+
26
43
  class ExchangeClient:
27
44
  """Client for an AGORA market (one registry hosting an order book).
28
45
 
29
- The base path stays /api/v1/exchange in this release: every registry serves it, while the documented
30
- /api/v1/agora names exist only on registries running V0419 or newer (the switch comes in a later release)."""
46
+ 0.7.3: the documented base path /api/v1/agora (every registry since V0419). Before its first call a client asks
47
+ the registry once whether it serves that path; a registry that does not know the route at all (an older one)
48
+ is spoken to under /api/v1/exchange for the life of the client, and `launch_buy` uses that registry's older
49
+ `ipo/buy` path. `base` holds the resolved path."""
31
50
 
32
51
  def __init__(self, registry_url: str, timeout: float = 15.0):
33
- self.base = registry_url.rstrip("/") + "/api/v1/exchange"
52
+ self._root = registry_url.rstrip("/")
53
+ self.base = self._root + AGORA_PREFIX
54
+ self._resolved = False
34
55
  self._client: Optional[httpx.AsyncClient] = None
35
56
  self._timeout = timeout
36
57
 
58
+ async def _resolve(self) -> None:
59
+ """Ask once: GET <registry>/api/v1/agora/listings (public). A route-missing 404 means an older registry."""
60
+ try:
61
+ r = await self._c().get(self._root + AGORA_PREFIX + "/listings")
62
+ if _route_missing(r):
63
+ self.base = self._root + LEGACY_PREFIX
64
+ except httpx.HTTPError:
65
+ pass # keep the documented path: the real call raises with its own error
66
+ self._resolved = True
67
+
68
+ async def _url(self, path: str) -> str:
69
+ if not self._resolved:
70
+ await self._resolve()
71
+ return f"{self.base}{path}"
72
+
37
73
  def _c(self) -> httpx.AsyncClient:
38
74
  if self._client is None or self._client.is_closed:
39
75
  self._client = httpx.AsyncClient(
@@ -52,33 +88,33 @@ class ExchangeClient:
52
88
 
53
89
  # ── market data (public) ──────────────────────────────────────────
54
90
  async def listings(self) -> List[Dict[str, Any]]:
55
- r = await self._c().get(f"{self.base}/listings")
91
+ r = await self._c().get(await self._url(f"/listings"))
56
92
  r.raise_for_status()
57
93
  return r.json().get("listings", [])
58
94
 
59
95
  async def listing(self, ref: str) -> Dict[str, Any]:
60
- r = await self._c().get(f"{self.base}/listings/{ref}")
96
+ r = await self._c().get(await self._url(f"/listings/{ref}"))
61
97
  r.raise_for_status()
62
98
  return r.json()
63
99
 
64
100
  async def book(self, ref: str, depth: int = 12) -> Dict[str, Any]:
65
- r = await self._c().get(f"{self.base}/listings/{ref}/book", params={"depth": depth})
101
+ r = await self._c().get(await self._url(f"/listings/{ref}/book"), params={"depth": depth})
66
102
  r.raise_for_status()
67
103
  return r.json()
68
104
 
69
105
  async def trades(self, ref: str, limit: int = 50) -> List[Dict[str, Any]]:
70
- r = await self._c().get(f"{self.base}/listings/{ref}/trades", params={"limit": limit})
106
+ r = await self._c().get(await self._url(f"/listings/{ref}/trades"), params={"limit": limit})
71
107
  r.raise_for_status()
72
108
  return r.json().get("trades", [])
73
109
 
74
110
  async def candles(self, ref: str, tf: str = "1h", limit: int = 120) -> List[Dict[str, Any]]:
75
- r = await self._c().get(f"{self.base}/listings/{ref}/candles", params={"tf": tf, "limit": limit})
111
+ r = await self._c().get(await self._url(f"/listings/{ref}/candles"), params={"tf": tf, "limit": limit})
76
112
  r.raise_for_status()
77
113
  return r.json().get("candles", [])
78
114
 
79
115
  async def federation_tickers(self) -> List[Dict[str, Any]]:
80
116
  """Every live venue this registry can see (server-side aggregate)."""
81
- r = await self._c().get(f"{self.base}/federation-tickers")
117
+ r = await self._c().get(await self._url(f"/federation-tickers"))
82
118
  r.raise_for_status()
83
119
  return r.json().get("venues", [])
84
120
 
@@ -100,34 +136,35 @@ class ExchangeClient:
100
136
  body["client_order_id"] = client_order_id
101
137
  if ttl_seconds:
102
138
  body["ttl_seconds"] = ttl_seconds
103
- r = await self._c().post(f"{self.base}/orders", json=body, headers=self._auth(agent_jwt))
139
+ r = await self._c().post(await self._url(f"/orders"), json=body, headers=self._auth(agent_jwt))
104
140
  r.raise_for_status()
105
141
  return r.json()
106
142
 
107
143
  async def cancel_order(self, agent_jwt: str, order_id: str) -> Dict[str, Any]:
108
- r = await self._c().delete(f"{self.base}/orders/{order_id}", headers=self._auth(agent_jwt))
144
+ r = await self._c().delete(await self._url(f"/orders/{order_id}"), headers=self._auth(agent_jwt))
109
145
  r.raise_for_status()
110
146
  return r.json()
111
147
 
112
148
  async def my_orders(self, agent_jwt: str, listing: Optional[str] = None) -> List[Dict[str, Any]]:
113
- r = await self._c().get(f"{self.base}/orders/mine",
149
+ r = await self._c().get(await self._url(f"/orders/mine"),
114
150
  params={"listing": listing} if listing else {},
115
151
  headers=self._auth(agent_jwt))
116
152
  r.raise_for_status()
117
153
  return r.json().get("orders", [])
118
154
 
119
155
  async def portfolio(self, agent_jwt: str) -> Dict[str, Any]:
120
- r = await self._c().get(f"{self.base}/portfolio", headers=self._auth(agent_jwt))
156
+ r = await self._c().get(await self._url(f"/portfolio"), headers=self._auth(agent_jwt))
121
157
  r.raise_for_status()
122
158
  return r.json()
123
159
 
124
160
  async def launch_buy(self, agent_jwt: str, ref: str, qty: int) -> Dict[str, Any]:
125
161
  """Buy points at launch: from a listing's launch allocation, at the fixed launch price.
126
162
 
127
- The wire path is the long-standing `/listings/{ref}/ipo/buy`, which every registry serves; the new name
128
- `/api/v1/agora/listings/{ref}/launch/buy` exists only on registries running V0419 or newer."""
129
- r = await self._c().post(f"{self.base}/listings/{ref}/ipo/buy", json={"qty": qty},
130
- headers=self._auth(agent_jwt))
163
+ `/api/v1/agora/listings/{ref}/launch/buy`; an older registry (spoken to under /api/v1/exchange) is sent its
164
+ own `/listings/{ref}/ipo/buy`."""
165
+ url = await self._url(f"/listings/{ref}/")
166
+ url += "launch/buy" if self.base.endswith(AGORA_PREFIX) else "ipo/buy"
167
+ r = await self._c().post(url, json={"qty": qty}, headers=self._auth(agent_jwt))
131
168
  r.raise_for_status()
132
169
  return r.json()
133
170
 
@@ -0,0 +1,84 @@
1
+ """§AGORAWORDS (0.7.2): ExchangeClient.launch_buy is the name; ipo_buy still works and warns. Hermetic via MockTransport."""
2
+ import json
3
+
4
+ import httpx
5
+ import pytest
6
+
7
+ from theprotocol.exchange.client import ExchangeClient
8
+
9
+
10
+ def _client(handler):
11
+ c = ExchangeClient("https://reg.example")
12
+ c._client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
13
+ return c
14
+
15
+
16
+ @pytest.mark.asyncio
17
+ async def test_launch_buy_posts_the_documented_path_on_a_current_registry():
18
+ """0.7.3: /api/v1/agora (the probe answers 200), and the launch purchase under its own name."""
19
+ seen = {}
20
+
21
+ def handler(request: httpx.Request) -> httpx.Response:
22
+ if request.method == "GET":
23
+ return httpx.Response(200, json={"listings": []})
24
+ seen["url"], seen["auth"], seen["body"] = str(request.url), request.headers.get("authorization"), json.loads(request.content)
25
+ return httpx.Response(200, json={"purchase_id": 7, "status": "pending", "qty": 5, "amount": "5"})
26
+
27
+ c = _client(handler)
28
+ out = await c.launch_buy("jwt-a", "ALFW", 5)
29
+ await c.aclose()
30
+ assert seen["url"] == "https://reg.example/api/v1/agora/listings/ALFW/launch/buy"
31
+ assert seen["auth"] == "Bearer jwt-a" and seen["body"] == {"qty": 5}
32
+ assert out["purchase_id"] == 7
33
+
34
+
35
+ @pytest.mark.asyncio
36
+ async def test_an_older_registry_is_spoken_to_under_the_old_path():
37
+ """A registry before V0419 answers /api/v1/agora with a bare 404 "Not Found": the client keeps /api/v1/exchange
38
+ for its life, and the launch purchase goes to that registry's ipo/buy."""
39
+ seen = []
40
+
41
+ def handler(request: httpx.Request) -> httpx.Response:
42
+ seen.append((request.method, str(request.url)))
43
+ if "/api/v1/agora/" in str(request.url):
44
+ return httpx.Response(404, json={"detail": "Not Found"})
45
+ if request.method == "GET":
46
+ return httpx.Response(200, json={"listings": [{"symbol": "ALFW"}]})
47
+ return httpx.Response(200, json={"purchase_id": 9, "status": "pending", "qty": 1, "amount": "1"})
48
+
49
+ c = _client(handler)
50
+ rows = await c.listings()
51
+ out = await c.launch_buy("jwt-a", "ALFW", 1)
52
+ await c.aclose()
53
+ assert c.base == "https://reg.example/api/v1/exchange"
54
+ assert rows == [{"symbol": "ALFW"}] and out["purchase_id"] == 9
55
+ assert seen == [("GET", "https://reg.example/api/v1/agora/listings"),
56
+ ("GET", "https://reg.example/api/v1/exchange/listings"),
57
+ ("POST", "https://reg.example/api/v1/exchange/listings/ALFW/ipo/buy")]
58
+
59
+
60
+ @pytest.mark.asyncio
61
+ async def test_an_unknown_listing_is_an_answer_not_an_older_registry():
62
+ """A business 404 (the listing is unknown) keeps the documented path; the caller sees the 404."""
63
+ def handler(request: httpx.Request) -> httpx.Response:
64
+ if str(request.url).endswith("/api/v1/agora/listings"):
65
+ return httpx.Response(200, json={"listings": []})
66
+ return httpx.Response(404, json={"detail": "listing 'NOPE' not found"})
67
+
68
+ c = _client(handler)
69
+ with pytest.raises(httpx.HTTPStatusError):
70
+ await c.listing("NOPE")
71
+ await c.aclose()
72
+ assert c.base == "https://reg.example/api/v1/agora"
73
+
74
+
75
+ @pytest.mark.asyncio
76
+ async def test_ipo_buy_is_a_deprecated_alias_with_the_same_result():
77
+ def handler(request: httpx.Request) -> httpx.Response:
78
+ return httpx.Response(200, json={"purchase_id": 8, "status": "pending", "qty": 2, "amount": "2"})
79
+
80
+ c = _client(handler)
81
+ with pytest.warns(DeprecationWarning, match="launch_buy"):
82
+ out = await c.ipo_buy("jwt-a", "ALFW", 2)
83
+ await c.aclose()
84
+ assert out["purchase_id"] == 8
@@ -1,41 +0,0 @@
1
- """§AGORAWORDS (0.7.2): ExchangeClient.launch_buy is the name; ipo_buy still works and warns. Hermetic via MockTransport."""
2
- import json
3
-
4
- import httpx
5
- import pytest
6
-
7
- from theprotocol.exchange.client import ExchangeClient
8
-
9
-
10
- def _client(handler):
11
- c = ExchangeClient("https://reg.example")
12
- c._client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
13
- return c
14
-
15
-
16
- @pytest.mark.asyncio
17
- async def test_launch_buy_posts_the_path_every_registry_serves():
18
- seen = {}
19
-
20
- def handler(request: httpx.Request) -> httpx.Response:
21
- seen["url"], seen["auth"], seen["body"] = str(request.url), request.headers.get("authorization"), json.loads(request.content)
22
- return httpx.Response(200, json={"purchase_id": 7, "status": "pending", "qty": 5, "amount": "5"})
23
-
24
- c = _client(handler)
25
- out = await c.launch_buy("jwt-a", "ALFW", 5)
26
- await c.aclose()
27
- assert seen["url"] == "https://reg.example/api/v1/exchange/listings/ALFW/ipo/buy"
28
- assert seen["auth"] == "Bearer jwt-a" and seen["body"] == {"qty": 5}
29
- assert out["purchase_id"] == 7
30
-
31
-
32
- @pytest.mark.asyncio
33
- async def test_ipo_buy_is_a_deprecated_alias_with_the_same_result():
34
- def handler(request: httpx.Request) -> httpx.Response:
35
- return httpx.Response(200, json={"purchase_id": 8, "status": "pending", "qty": 2, "amount": "2"})
36
-
37
- c = _client(handler)
38
- with pytest.warns(DeprecationWarning, match="launch_buy"):
39
- out = await c.ipo_buy("jwt-a", "ALFW", 2)
40
- await c.aclose()
41
- assert out["purchase_id"] == 8
File without changes