Skip to content

Commit 8d8c3a5

Browse files
committed
fix: lint & tests
1 parent aa0022f commit 8d8c3a5

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/hl_cli/commands/asset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from queue import Empty, Queue
44
from typing import Optional
55

6+
from hyperliquid.info import Info
67
from hyperliquid.utils.types import L2BookData
78

89
from ..cli.runtime import CommandContext, cli_command, console, run_blocking

tests/test_testnet_context.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111

1212

13-
class TestnetContextTests(unittest.TestCase):
13+
class ContextTests(unittest.TestCase):
1414
def test_safe_token_name_handles_invalid_indexes(self):
1515
tokens = [{"name": "USDC"}, {"name": "BTC"}]
1616

@@ -87,6 +87,53 @@ def test_build_info_client_falls_back_to_sanitized_spot_meta(self):
8787
{"skip_ws": True, "spot_meta": safe_spot_meta},
8888
)
8989

90+
def test_build_info_client_falls_back_on_mainnet_malformed_spot_meta(self):
91+
safe_spot_meta = {
92+
"tokens": [{"name": "USDC"}, {"name": "BTC"}],
93+
"universe": [{"name": "BTC/USDC", "tokens": [1, 0]}],
94+
}
95+
created = object()
96+
97+
with patch(
98+
"hl_cli.core.context.Info", side_effect=[IndexError("bad"), created]
99+
) as info_cls:
100+
with patch(
101+
"hl_cli.core.context._load_safe_spot_meta", return_value=safe_spot_meta
102+
) as loader:
103+
client = _build_info_client(
104+
"https://api.hyperliquid.xyz", skip_ws=True
105+
)
106+
107+
self.assertIs(client, created)
108+
loader.assert_called_once_with("https://api.hyperliquid.xyz")
109+
self.assertEqual(
110+
info_cls.call_args_list[1].kwargs,
111+
{"skip_ws": True, "spot_meta": safe_spot_meta},
112+
)
113+
114+
def test_build_info_client_preloads_sanitized_spot_meta_for_websocket_client(self):
115+
safe_spot_meta = {
116+
"tokens": [{"name": "USDC"}, {"name": "BTC"}],
117+
"universe": [{"name": "BTC/USDC", "tokens": [1, 0]}],
118+
}
119+
created = object()
120+
121+
with patch("hl_cli.core.context.Info", return_value=created) as info_cls:
122+
with patch(
123+
"hl_cli.core.context._load_safe_spot_meta", return_value=safe_spot_meta
124+
) as loader:
125+
client = _build_info_client(
126+
"https://api.hyperliquid.xyz", skip_ws=False
127+
)
128+
129+
self.assertIs(client, created)
130+
loader.assert_called_once_with("https://api.hyperliquid.xyz")
131+
info_cls.assert_called_once_with(
132+
"https://api.hyperliquid.xyz",
133+
skip_ws=False,
134+
spot_meta=safe_spot_meta,
135+
)
136+
90137

91138
if __name__ == "__main__":
92139
unittest.main()

0 commit comments

Comments
 (0)