forked from CoboGlobal/cobo-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
374 lines (323 loc) · 14.1 KB
/
test.py
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
from cobo_custody.config import DEV_ENV
from cobo_custody.config import DEV_TEST_DATA
from cobo_custody.config import PROD_ENV
from cobo_custody.config import PROD_TEST_DATA
import unittest
from cobo_custody.client import Client
from cobo_custody.model.enums import SortFlagEnum
from cobo_custody.signer.local_signer import LocalSigner
from parameterized import param, parameterized
import sys
import argparse
import time
from hashlib import sha256
class ClientTest(unittest.TestCase):
api_secret = "api_secret"
ENV = DEV_ENV
TEST_DATA = DEV_TEST_DATA
def setUp(self):
self.client = Client(signer=LocalSigner(self.api_secret),
env=self.ENV,
debug=False)
# account and address
def test_get_account_info(self):
response = self.client.get_account_info()
self.assertTrue(response.success)
@parameterized.expand(
[
param(coin="BTC"),
param(coin="ETH"),
param(coin="ETH_USDT"),
param(coin="XRP"),
]
)
def test_get_valid_coin_info(self, coin):
response = self.client.get_coin_info(coin)
self.assertTrue(response.success)
@parameterized.expand(
[
param(coin="BTTB")
]
)
def test_get_invalid_coin_info(self, coin):
response = self.client.get_coin_info(coin)
self.assertFalse(response.success)
self.assertEqual(response.exception.errorCode, 12002)
@parameterized.expand(
[
param(coin="BTC", native_segwit=True),
param(coin="BTC", native_segwit=False),
param(coin="ETH", native_segwit=False),
param(coin="ETH_USDT", native_segwit=False),
param(coin="XRP", native_segwit=False),
]
)
def test_new_valid_deposit_address(self, coin, native_segwit):
response = self.client.new_deposit_address(coin=coin, native_segwit=native_segwit)
self.assertTrue(response.success)
@parameterized.expand(
[
param(coin="BTTB", native_segwit=True),
param(coin="ETTE", native_segwit=False)
]
)
def test_new_invalid_deposit_address(self, coin, native_segwit):
response = self.client.new_deposit_address(coin=coin, native_segwit=native_segwit)
self.assertFalse(response.success)
self.assertEqual(response.exception.errorCode, 12002)
@parameterized.expand(
[
param(coin="BTC", native_segwit=True, count=2),
param(coin="BTC", native_segwit=False, count=2),
param(coin="ETH", native_segwit=False, count=2),
param(coin="ETH_USDT", native_segwit=False, count=2),
param(coin="XRP", native_segwit=False, count=2),
]
)
def test_batch_new_valid_deposit_address(self, coin, native_segwit, count):
response = self.client.batch_new_deposit_address(coin=coin, native_segwit=native_segwit, count=count)
self.assertTrue(response.success)
@parameterized.expand(
[
param(coin="BTTB", native_segwit=True, count=2),
param(coin="ETTE", native_segwit=False, count=2)
]
)
def test_batch_new_invalid_deposit_address(self, coin, native_segwit, count):
response = self.client.batch_new_deposit_address(coin=coin,native_segwit=native_segwit, count=count)
self.assertFalse(response.success)
self.assertEqual(response.exception.errorCode, 12002)
@parameterized.expand(
[
param(coin="BTC"),
param(coin="XRP")
]
)
def test_verify_valid_deposit_address(self, coin):
response = self.client.verify_deposit_address(coin=coin, address=self.TEST_DATA["deposit_address"][coin])
self.assertTrue(response.success)
@parameterized.expand(
[
param(coin="BTC", address="3Kd5rjiLtvpHv5nhYQNTTeRLgrz4om32PJ"),
param(coin="XRP", address="rndm7RphBZG6CpZvKcG9AjoFbSvcKhwLCx")
]
)
def test_verify_invalid_deposit_address(self, coin, address):
response = self.client.verify_deposit_address(coin=coin, address=address)
self.assertFalse(response.success)
self.assertEqual(response.exception.errorCode, 12015)
@parameterized.expand(
[
param(coin="BTC", count=2),
param(coin="XRP", count=2)
]
)
def test_batch_verify_valid_deposit_address(self, coin, count):
response = self.client.batch_verify_deposit_address(coin=coin, addresses= self.TEST_DATA["deposit_addresses"][coin])
self.assertTrue(response.success)
self.assertEqual(len(response.result["addresses"].split(",")), count)
@parameterized.expand(
[
param(coin="BTC", addresses="3Kd5rjiLtvpHv5nhYQNTTeRLgrz4om32PJ,bc1q9unqc738dxjg5mk8zqtz33zg59cahrj29s24lp", count=0),
param(coin="XRP", addresses="rndm7RphBZG6CpZvKcG9AjoFbSvcKhwLCx,rrBD4sBsxrpzbohAEYWH4moPSsoxupWLA|00000000", count=0)
]
)
def test_batch_verify_invalid_deposit_address(self, coin, addresses, count):
response = self.client.batch_verify_deposit_address(coin=coin, addresses=addresses)
self.assertTrue(response.success)
self.assertEqual(len(response.result["addresses"]), count)
@parameterized.expand(
[
param(coin="BTC", address="3Kd5rjiLtvpHv5nhYQNTTeRLgrz4om32PJ"),
param(coin="BTC", address="bc1q9unqc738dxjg5mk8zqtz33zg59cahrj29s24lp"),
param(coin="ETH", address="0xE410157345be56688F43FF0D9e4B2B38Ea8F7828"),
param(coin="ETH_USDT", address="0xEEACb7a5e53600c144C0b9839A834bb4b39E540c"),
param(coin="XRP", address="rndm7RphBZG6CpZvKcG9AjoFbSvcKhwLCx"),
param(coin="XRP", address="rGNXLMNHkUEtoo7qkCSHEm2sfMo8F969oZ|2200701580")
]
)
def test_verify_valid_address(self, coin, address):
response = self.client.verify_valid_address(coin=coin, address=address)
self.assertTrue(response.success)
@parameterized.expand(
[
param(coin="BTC", address="0xE410157345be56688F43FF0D9e4B2B38Ea8F7828"),
param(coin="XRP", address="rBWpYJhuJWBPAkzJ4kYQqHShSkkF3rgeDE"),
]
)
def test_verify_invalid_address(self, coin, address):
response = self.client.verify_valid_address(coin, address)
self.assertTrue(response.success)
self.assertFalse(response.result)
@parameterized.expand(
[
param(coin="BTC"),
param(coin="ETH"),
param(coin="ETH_USDT"),
param(coin="XRP"),
]
)
def test_get_valid_address_history(self, coin):
response = self.client.get_address_history(coin=coin)
self.assertTrue(response.success)
self.assertTrue(len(response.result) > 0)
@parameterized.expand(
[
param(coin="BTTB"),
]
)
def test_get_invalid_address_history(self, coin):
response = self.client.get_address_history(coin=coin)
self.assertFalse(response.success)
self.assertEqual(response.exception.errorCode, 12002)
@parameterized.expand(
[
param(coin="BTC", page_index=0, page_length=10),
]
)
def test_get_invalid_address_history_with_valid_page(self, coin, page_index, page_length):
response = self.client.get_address_history(coin=coin, page_index=page_index, page_length=page_length)
self.assertTrue(response.success)
self.assertTrue(len(response.result) > 0)
@parameterized.expand(
[
param(coin="BTC", page_index=0, page_length=51),
param(coin="BTC", page_index=0, page_length=0),
]
)
def test_get_invalid_address_history_with_invalid_page(self, coin, page_index, page_length):
response = self.client.get_address_history(coin=coin, page_index=page_index, page_length=page_length)
self.assertFalse(response.success)
self.assertEqual(response.exception.errorCode, 1011)
@parameterized.expand(
[
param(coin="BTC", page_index=0, page_length=10, sort_flag=SortFlagEnum.ASCENDING),
]
)
def test_get_address_history_with_sort(self, coin, page_index, page_length, sort_flag):
response = self.client.get_address_history(
coin=coin, page_index=page_index, page_length=page_length, sort_flag=sort_flag)
self.assertTrue(response.success)
self.assertTrue(len(response.result) > 0)
@parameterized.expand(
[
param(coin="BTC", memo=False),
param(coin="XRP", memo=True),
]
)
def test_check_loop_address_details(self, coin, memo=None):
if memo:
address = self.TEST_DATA["loop_address"][coin].split("|")[0]
mome_info = self.TEST_DATA["loop_address"][coin].split("|")[1]
else:
address = self.TEST_DATA["loop_address"][coin]
mome_info =None
response = self.client.check_loop_address_details(coin=coin, address=address, memo=mome_info)
self.assertTrue(response.success)
self.assertTrue(response.result["is_internal_address"])
@parameterized.expand(
[
param(coin="BTC"),
param(coin="XRP"),
]
)
def test_verify_loop_address_list(self, coin):
response = self.client.verify_loop_address_list(coin=coin, addresses=self.TEST_DATA["loop_addresses"][coin])
self.assertTrue(response.success)
for address_info in response.result:
self.assertTrue(address_info["is_internal_address"])
def test_get_transaction_details(self):
response = self.client.get_transaction_details(self.TEST_DATA["cobo_id"])
self.assertTrue(response.success)
def test_get_transaction_by_txid(self):
response = self.client.get_transaction_by_txid(self.TEST_DATA["tx_id"])
self.assertTrue(response.success)
def test_get_transactions_by_id(self):
response = self.client.get_transactions_by_id()
self.assertTrue(response.success)
def test_get_transactions_by_time(self):
response = self.client.get_transactions_by_time()
self.assertTrue(response.success)
def test_get_transactions_by_time_ex(self):
response = self.client.get_transactions_by_time_ex()
self.assertTrue(response.success)
def test_get_pending_transactions(self):
response = self.client.get_pending_transactions()
self.assertTrue(response.success)
def test_get_transaction_history(self):
response = self.client.get_transaction_history()
self.assertTrue(response.success)
def test_get_pending_transaction(self):
response = self.client.get_pending_transactions()
if len(response.result):
pending_id = response.result[0]["id"]
response = self.client.get_pending_transaction(id=pending_id)
self.assertTrue(response.success)
else:
self.skipTest("no pending transactions")
def test_get_transactions_by_request_ids(self):
request_ids = "web_send_by_user_1049_1677469364250,slp_uc_1559_1675822822477,web_send_by_user_1212_1678330749364"
response = self.client.get_transactions_by_request_ids(request_ids=request_ids)
print(response)
self.assertTrue(response.success)
@parameterized.expand(
[
param(coin="COBO_ETH", address="0xE410157345be56688F43FF0D9e4B2B38Ea8F7828", memo=None, amount=1),
param(coin="XLM", address="GBJDU6TPWHKGV7HRLNTIBA46MG3MB5DUG6BISHX3BF7I75H2HLPV6RJX", memo="4e73f03b", amount=1)
]
)
def test_withdraw(self, coin, address, memo, amount):
request_id = f"request_id_{sha256(address.encode()).digest().hex()[:8]}_{str(int(time.time() * 1000))}"
response = self.client.withdraw(coin=coin, address=address, memo=memo, amount=amount, request_id=request_id)
self.assertTrue(response.success)
def test_query_withdraw_info(self):
response = self.client.query_withdraw_info(self.TEST_DATA["withdraw_id"])
self.assertTrue(response.success)
def test_get_staking_product_list(self):
response = self.client.get_staking_product_list()
self.assertTrue(response.success)
def test_get_staking_product_details(self):
response = self.client.get_staking_product_list()
product_id = response.result[0]['product_id']
response = self.client.get_staking_product_details(product_id)
self.assertTrue(response.success)
def test_stake(self):
response = self.client.get_staking_product_list(coin="TETH")
if len(response.result)>0:
product_id = response.result[0]['product_id']
response = self.client.stake(product_id, 1000000)
self.assertTrue(response.success)
else:
self.skipTest("no TETH staking product")
def test_unstake(self):
response = self.client.get_staking_product_list(coin="TETH")
if len(response.result)>0:
product_id = response.result[0]['product_id']
response = self.client.unstake(product_id, 1000000)
self.assertTrue(response.success)
else:
self.skipTest("no TETH staking product")
def test_get_stakings(self):
response = self.client.get_stakings()
self.assertTrue(response.success)
def test_get_unstakings(self):
response = self.client.get_unstakings()
self.assertTrue(response.success)
def test_get_staking_history(self):
response = self.client.get_staking_history()
self.assertTrue(response.success)
if __name__ == '__main__':
if len(sys.argv) > 1:
parser = argparse.ArgumentParser()
parser.add_argument("--env", nargs='?', default="develop")
parser.add_argument("--secret", type=str, required=True)
args = parser.parse_args()
env = args.env if args.env else "develop"
api_secret = args.secret
ClientTest.api_secret = api_secret
ClientTest.ENV = DEV_ENV if env == "develop" else PROD_ENV
ClientTest.TEST_DATA = DEV_TEST_DATA if env == "develop" else PROD_TEST_DATA
# unittest.main()
runner = unittest.TextTestRunner()
suite = unittest.TestLoader().loadTestsFromTestCase(ClientTest)
runner.run(suite)