Skip to content

Commit 14ea65f

Browse files
committed
test multiple products
1 parent 4a98e37 commit 14ea65f

File tree

2 files changed

+81
-57
lines changed

2 files changed

+81
-57
lines changed

pyth/tests/conftest.py

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,31 @@ def run_test(self, input_path: str, output_path: str, *, inplace: bool):
110110
assert actual == expected
111111

112112

113+
PRODUCTS = {
114+
'BTC': {
115+
'symbol': 'BTC/USD',
116+
'asset_type': 'Crypto',
117+
'country': 'US',
118+
'quote_currency': 'USD',
119+
'tenor': 'Spot',
120+
},
121+
'ETH': {
122+
'symbol': 'ETH/USD',
123+
'asset_type': 'Crypto',
124+
'country': 'US',
125+
'quote_currency': 'USD',
126+
'tenor': 'Spot',
127+
},
128+
'LTC': {
129+
'symbol': 'LTC/USD',
130+
'asset_type': 'Crypto',
131+
'country': 'US',
132+
'quote_currency': 'USD',
133+
'tenor': 'Spot',
134+
},
135+
}
136+
137+
113138
@pytest.fixture(scope='session')
114139
def solana_test_validator():
115140

@@ -220,35 +245,33 @@ def pyth_init_mapping(
220245
@pytest.fixture(scope='session')
221246
def pyth_add_product(solana_test_validator, pyth_dir, pyth_init_mapping):
222247

223-
cmd = [
224-
'pyth_admin', 'add_product',
225-
'-r', 'localhost',
226-
'-k', pyth_dir,
227-
'-c', 'finalized',
228-
]
229-
output = check_output(cmd)
230-
output = output.decode('ascii')
231-
output = output.splitlines()
232-
return output[0]
248+
result = {}
249+
for product in PRODUCTS.keys():
250+
cmd = [
251+
'pyth_admin', 'add_product',
252+
'-r', 'localhost',
253+
'-k', pyth_dir,
254+
'-c', 'finalized',
255+
]
256+
output = check_output(cmd)
257+
output = output.decode('ascii')
258+
output = output.splitlines()
259+
result[product] = output[0]
260+
return result
233261

234262

235263
@pytest.fixture(scope='session')
236264
def pyth_init_product(solana_test_validator, pyth_dir, pyth_add_product):
237265

238-
ltc = {
239-
'account': pyth_add_product,
240-
'attr_dict': {
241-
'symbol': 'LTC/USD',
242-
'asset_type': 'Crypto',
243-
'country': 'US',
244-
'quote_currency': 'USD',
245-
'tenor': 'Spot',
246-
'jlqd_symbol': 'LTCUSD',
247-
},
248-
}
249-
fd, path = mkstemp(suffix='.json', prefix='ltc_')
266+
products = []
267+
for product in pyth_add_product.keys():
268+
products.append({
269+
'account': pyth_add_product[product],
270+
'attr_dict': PRODUCTS[product],
271+
})
272+
fd, path = mkstemp(suffix='.json', prefix='products_')
250273
with fdopen(fd, 'w') as f:
251-
json.dump([ltc], f)
274+
json.dump(products, f)
252275
cmd = [
253276
'pyth_admin', 'upd_product', path,
254277
'-r', 'localhost',
@@ -263,32 +286,36 @@ def pyth_init_product(solana_test_validator, pyth_dir, pyth_add_product):
263286
@pytest.fixture(scope='session')
264287
def pyth_add_price(solana_test_validator, pyth_dir, pyth_init_product):
265288

266-
cmd = [
267-
'pyth_admin', 'add_price',
268-
pyth_init_product, 'price', '-e', '-5',
269-
'-r', 'localhost',
270-
'-k', pyth_dir,
271-
'-c', 'finalized',
272-
'-n',
273-
]
274-
output = check_output(cmd)
275-
output = output.decode('ascii')
276-
output = output.splitlines()
277-
return output[0]
278-
279-
280-
@pytest.fixture(scope='session')
289+
result = {}
290+
for product, key in pyth_init_product.items():
291+
cmd = [
292+
'pyth_admin', 'add_price',
293+
key, 'price', '-e', '-5',
294+
'-r', 'localhost',
295+
'-k', pyth_dir,
296+
'-c', 'finalized',
297+
'-n',
298+
]
299+
output = check_output(cmd)
300+
output = output.decode('ascii')
301+
output = output.splitlines()
302+
result[product] = output[0]
303+
return result
304+
305+
306+
@pytest.fixture(scope='function')
281307
def pyth_init_price(solana_test_validator, pyth_dir, pyth_add_price):
282308

283-
cmd = [
284-
'pyth_admin', 'init_price',
285-
pyth_add_price, '-e', '-5',
286-
'-r', 'localhost',
287-
'-k', pyth_dir,
288-
'-c', 'finalized',
289-
'-n',
290-
]
291-
check_call(cmd)
309+
for product, key in pyth_add_price.items():
310+
cmd = [
311+
'pyth_admin', 'init_price',
312+
key, '-e', '-5',
313+
'-r', 'localhost',
314+
'-k', pyth_dir,
315+
'-c', 'finalized',
316+
'-n',
317+
]
318+
check_call(cmd)
292319
return pyth_add_price
293320

294321

pyth/tests/test_get_product.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import json
33
import websockets
44

5+
from pyth.tests.conftest import PRODUCTS
6+
7+
58
def test_get_product_list(solana_test_validator, pythd, pyth_init_price):
69

710
data = {
@@ -10,6 +13,7 @@ def test_get_product_list(solana_test_validator, pythd, pyth_init_price):
1013
'method': 'get_product_list',
1114
}
1215
data = json.dumps(data)
16+
1317
async def f():
1418
async with websockets.connect('ws://localhost:8910/') as ws:
1519
await ws.send(data)
@@ -18,20 +22,13 @@ async def f():
1822
result = asyncio.run(f())
1923
result = json.loads(result)
2024
result = result['result']
21-
result = result[0]
25+
result = result[2]
2226
del result['account'] # TODO
2327
expected_result = {
24-
'attr_dict': {
25-
'symbol': 'LTC/USD',
26-
'asset_type': 'Crypto',
27-
'country': 'US',
28-
'quote_currency': 'USD',
29-
'tenor': 'Spot',
30-
'jlqd_symbol': 'LTCUSD',
31-
},
28+
'attr_dict': PRODUCTS['LTC'],
3229
'price': [
3330
{
34-
'account': pyth_init_price,
31+
'account': pyth_init_price['LTC'],
3532
'price_exponent': -5,
3633
'price_type': 'price',
3734
},

0 commit comments

Comments
 (0)