|
10 | 10 | ) |
11 | 11 |
|
12 | 12 |
|
13 | | -class TestnetContextTests(unittest.TestCase): |
| 13 | +class ContextTests(unittest.TestCase): |
14 | 14 | def test_safe_token_name_handles_invalid_indexes(self): |
15 | 15 | tokens = [{"name": "USDC"}, {"name": "BTC"}] |
16 | 16 |
|
@@ -87,6 +87,53 @@ def test_build_info_client_falls_back_to_sanitized_spot_meta(self): |
87 | 87 | {"skip_ws": True, "spot_meta": safe_spot_meta}, |
88 | 88 | ) |
89 | 89 |
|
| 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 | + |
90 | 137 |
|
91 | 138 | if __name__ == "__main__": |
92 | 139 | unittest.main() |
0 commit comments