forked from x10xchange/python_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_native_sync.py
More file actions
157 lines (126 loc) · 4.99 KB
/
test_native_sync.py
File metadata and controls
157 lines (126 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
Test script for Native Sync Extended SDK.
Verifies that the native sync implementation works without async/await issues.
"""
import sys
import traceback
from unittest.mock import Mock, patch
def test_import_structure():
"""Test that imports work without async dependencies."""
print("Testing import structure...")
try:
# Test core imports
from extended.api.base_native_sync import BaseNativeSyncClient
from extended.api.info_native_sync import NativeSyncInfoAPI
from extended.api.exchange_native_sync import NativeSyncExchangeAPI
# Test public API imports
from extended.api.info import InfoAPI
from extended.api.exchange import ExchangeAPI
from extended.client import Client
print("✅ All imports successful - no async dependencies detected")
return True
except Exception as e:
print(f"❌ Import failed: {e}")
traceback.print_exc()
return False
def test_client_instantiation():
"""Test that client can be created without async issues."""
print("\nTesting client instantiation...")
try:
# Mock the ExtendedAuth to avoid needing real credentials
with patch('extended.auth.ExtendedAuth') as mock_auth:
mock_auth_instance = Mock()
mock_auth_instance.address = "0x123456789"
mock_auth_instance.stark_public_key = "0x987654321"
mock_auth_instance.api_key = "test_api_key"
mock_auth.return_value = mock_auth_instance
# Mock the config
with patch('extended.config.MAINNET_CONFIG') as mock_config:
mock_config.api_base_url = "https://api.extended.com"
client = Client(
api_key="test_api_key",
vault=12345,
stark_private_key="0xprivate",
stark_public_key="0xpublic",
testnet=False
)
# Verify properties work
assert client.address == "0x123456789"
assert client.public_key == "0x987654321"
assert client.info is not None
assert client.exchange is not None
print("✅ Client instantiation successful - native sync working")
return True
except Exception as e:
print(f"❌ Client instantiation failed: {e}")
traceback.print_exc()
return False
def test_no_run_sync_usage():
"""Test that run_sync is not used anywhere in the new implementation."""
print("\nTesting for run_sync usage...")
import os
import re
sdk_path = "/tmp/extended-sdk-analysis/extended"
run_sync_pattern = r"run_sync\("
files_with_run_sync = []
for root, dirs, files in os.walk(sdk_path):
for file in files:
if file.endswith('.py') and not file.endswith('_old_async_wrapper.py'):
file_path = os.path.join(root, file)
try:
with open(file_path, 'r') as f:
content = f.read()
if re.search(run_sync_pattern, content):
files_with_run_sync.append(file_path)
except:
pass
if files_with_run_sync:
print(f"❌ Found run_sync usage in: {files_with_run_sync}")
return False
else:
print("✅ No run_sync usage found in native sync implementation")
return True
def test_requests_usage():
"""Test that requests is used instead of aiohttp."""
print("\nTesting HTTP client usage...")
try:
from extended.api.base_native_sync import BaseNativeSyncClient
# Check that BaseNativeSyncClient uses requests
import inspect
source = inspect.getsource(BaseNativeSyncClient.__init__)
if 'requests.Session()' in source:
print("✅ Uses requests.Session() - correct sync HTTP client")
return True
else:
print("❌ Does not use requests.Session()")
return False
except Exception as e:
print(f"❌ HTTP client test failed: {e}")
return False
def run_all_tests():
"""Run all tests and return overall success."""
print("🚀 Testing Native Sync Extended SDK Implementation")
print("=" * 60)
tests = [
test_import_structure,
test_client_instantiation,
test_no_run_sync_usage,
test_requests_usage,
]
results = []
for test in tests:
results.append(test())
print("\n" + "=" * 60)
if all(results):
print("🎉 ALL TESTS PASSED - Native Sync Extended SDK is ready!")
print("✅ No async/await dependencies")
print("✅ No run_sync() usage")
print("✅ Uses requests.Session() for HTTP")
print("✅ Same API surface as original SDK")
return True
else:
print("❌ Some tests failed - see details above")
return False
if __name__ == "__main__":
success = run_all_tests()
sys.exit(0 if success else 1)