-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_enhanced_buying.py
More file actions
212 lines (170 loc) Β· 7.19 KB
/
test_enhanced_buying.py
File metadata and controls
212 lines (170 loc) Β· 7.19 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python3
"""
Test script to verify enhanced token buying functionality
"""
import sys
import os
# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_comprehensive_token_info():
"""Test comprehensive token information retrieval"""
print("π§ͺ Testing Comprehensive Token Information")
print("=" * 50)
try:
from bot import get_comprehensive_token_info, format_token_info_message
print("β
Successfully imported token info functions")
except ImportError as e:
print(f"β Failed to import: {e}")
return False
# Test cases
test_cases = [
("USDC", "USD Coin"),
("usdc", "USD Coin"),
("WETH", "Wrapped Ether"),
("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "USD Coin"), # USDC CA
("0x4200000000000000000000000000000000000006", "Wrapped Ether"), # WETH CA
("PEPE", "Pepe"),
("DOGE", "Dogecoin"),
]
passed = 0
total = len(test_cases)
for i, (token_input, expected_name) in enumerate(test_cases, 1):
print(f"\nπ Test {i}/{total}: {token_input}")
try:
token_info, error = get_comprehensive_token_info(token_input)
if error:
print(f"β Error: {error}")
elif token_info:
print(f"β
Successfully retrieved token info:")
print(f" Name: {token_info.get('name', 'Unknown')}")
print(f" Symbol: {token_info.get('symbol', 'Unknown')}")
print(f" Contract: {token_info.get('contract_address', 'Unknown')}")
print(f" Price: ${token_info.get('price_usd', 0):.6f}")
print(f" Source: {token_info.get('source', 'Unknown')}")
# Test message formatting
message = format_token_info_message(token_info)
print(f" Message length: {len(message)} characters")
passed += 1
else:
print(f"β No token info returned")
except Exception as e:
print(f"β Error during test: {e}")
print(f"\nπ Results: {passed}/{total} tests passed")
if passed == total:
print("π All comprehensive token info tests passed!")
return True
else:
print("β οΈ Some tests failed. Check the implementation.")
return False
def test_price_data():
"""Test price data retrieval"""
print("\nπ° Testing Price Data Retrieval")
print("=" * 30)
try:
from bot import get_token_price_data
print("β
Successfully imported price data function")
except ImportError as e:
print(f"β Failed to import: {e}")
return False
# Test cases
test_cases = [
("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "USDC"), # USDC
("0x4200000000000000000000000000000000000006", "WETH"), # WETH
]
passed = 0
total = len(test_cases)
for i, (contract_address, symbol) in enumerate(test_cases, 1):
print(f"\nπ Test {i}/{total}: {symbol} ({contract_address[:10]}...)")
try:
price_data = get_token_price_data(contract_address, symbol)
print(f"β
Price data retrieved:")
print(f" Price USD: ${price_data.get('price_usd', 0):.6f}")
print(f" 24h Change: {price_data.get('price_change_24h', 0):.2f}%")
print(f" Market Cap: ${price_data.get('market_cap', 0):,.0f}")
print(f" 24h Volume: ${price_data.get('volume_24h', 0):,.0f}")
passed += 1
except Exception as e:
print(f"β Error during test: {e}")
print(f"\nπ Results: {passed}/{total} tests passed")
if passed == total:
print("π All price data tests passed!")
return True
else:
print("β οΈ Some tests failed. Check the implementation.")
return False
def test_buy_request_parsing():
"""Test buy request parsing"""
print("\nπ Testing Buy Request Parsing")
print("=" * 30)
import re
# Test cases
test_cases = [
("buy with ETH 0.1", ("ETH", 0.1)),
("buy with USDC 100", ("USDC", 100)),
("buy with USDT 50.5", ("USDT", 50.5)),
("BUY WITH ETH 0.05", ("ETH", 0.05)),
("invalid command", None),
("buy with BTC 1", None), # Invalid token
]
passed = 0
total = len(test_cases)
for i, (text, expected) in enumerate(test_cases, 1):
print(f"\nπ Test {i}/{total}: {text}")
try:
buy_match = re.search(r'buy with (\w+) (\d+\.?\d*)', text.lower())
if expected is None:
if buy_match is None:
print(f"β
Correctly failed to parse: {text}")
passed += 1
else:
# Check if the parsed token is valid
payment_token = buy_match.group(1).upper()
valid_tokens = ['ETH', 'USDC', 'USDT']
if payment_token not in valid_tokens:
print(f"β
Correctly failed to parse invalid token: {text}")
passed += 1
else:
print(f"β Should have failed but got: {buy_match.groups()}")
else:
if buy_match:
payment_token = buy_match.group(1).upper()
amount = float(buy_match.group(2))
if payment_token == expected[0] and amount == expected[1]:
print(f"β
Successfully parsed: {payment_token} {amount}")
passed += 1
else:
print(f"β Parsed incorrectly:")
print(f" Expected: {expected[0]} {expected[1]}")
print(f" Got: {payment_token} {amount}")
else:
print(f"β Failed to parse valid command")
except Exception as e:
print(f"β Error during test: {e}")
print(f"\nπ Results: {passed}/{total} tests passed")
if passed == total:
print("π All buy request parsing tests passed!")
return True
else:
print("β οΈ Some tests failed. Check the implementation.")
return False
def main():
"""Run all tests"""
print("π Starting Enhanced Token Buying Tests")
print("=" * 50)
# Test comprehensive token info
token_info_ok = test_comprehensive_token_info()
# Test price data
price_data_ok = test_price_data()
# Test buy request parsing
parsing_ok = test_buy_request_parsing()
print("\n" + "=" * 50)
if token_info_ok and price_data_ok and parsing_ok:
print("π All enhanced token buying tests passed!")
print("π‘ The bot can now show token info and handle enhanced buying flow.")
return True
else:
print("β Some tests failed. Please check the implementation.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)