From f78ea1288e9a143488b9415c7dc33a086d0be19f Mon Sep 17 00:00:00 2001 From: dekun Date: Tue, 23 Jun 2026 18:17:42 +0800 Subject: [PATCH] Fix calculator instance auth header to X-Hub-Token. Market info fetch was rejected by instances because it sent the wrong bridge token header; align with hub monitor calls. Co-authored-by: Cursor --- hub_calculator_market_lib.py | 4 ++-- tests/test_hub_calculator_market_lib.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hub_calculator_market_lib.py b/hub_calculator_market_lib.py index d268c21..7615406 100644 --- a/hub_calculator_market_lib.py +++ b/hub_calculator_market_lib.py @@ -168,9 +168,9 @@ def list_calculator_exchanges() -> list[dict[str, Any]]: def _hub_headers() -> dict[str, str]: import os - token = (os.getenv("HUB_BRIDGE_TOKEN") or "").strip() + token = (os.getenv("HUB_BRIDGE_TOKEN") or os.getenv("CONTROL_TOKEN") or "").strip() if token: - return {"X-Hub-Bridge-Token": token} + return {"X-Hub-Token": token} return {} diff --git a/tests/test_hub_calculator_market_lib.py b/tests/test_hub_calculator_market_lib.py index 8d849d3..b5ca102 100644 --- a/tests/test_hub_calculator_market_lib.py +++ b/tests/test_hub_calculator_market_lib.py @@ -58,6 +58,12 @@ class HubCalculatorMarketLibTests(unittest.TestCase): self.assertEqual(fn(1.23456), 1.234) self.assertIsNone(fn(0.0001)) + @patch.dict("os.environ", {"HUB_BRIDGE_TOKEN": "test-token"}, clear=False) + def test_hub_headers_use_x_hub_token(self): + from hub_calculator_market_lib import _hub_headers + + self.assertEqual(_hub_headers(), {"X-Hub-Token": "test-token"}) + @patch("hub_calculator_market_lib.fetch_instance_market_sync") def test_get_calculator_market_from_instance(self, fetch_mock): fetch_mock.return_value = {