Skip to content

Commit 4a98e37

Browse files
committed
test pythd
1 parent 8367b52 commit 4a98e37

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ RUN apt-get install -qq \
1616
libzstd1 \
1717
libzstd-dev \
1818
python3-pytest \
19+
python3-websockets \
1920
sudo \
2021
zlib1g \
2122
zlib1g-dev

pyth/tests/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,25 @@ def pyth_init_price(solana_test_validator, pyth_dir, pyth_add_price):
290290
]
291291
check_call(cmd)
292292
return pyth_add_price
293+
294+
295+
@pytest.fixture(scope='session')
296+
def pythd(solana_test_validator, pyth_dir):
297+
298+
cmd = [
299+
'pythd',
300+
'-r', 'localhost',
301+
'-k', pyth_dir,
302+
'-x',
303+
'-m', 'finalized',
304+
'-d',
305+
]
306+
kwargs = {
307+
'stdin': DEVNULL,
308+
'stdout': DEVNULL,
309+
'stderr': DEVNULL,
310+
}
311+
with Popen(cmd, **kwargs) as p:
312+
time.sleep(3)
313+
yield
314+
p.terminate()

pyth/tests/test_get_product.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import asyncio
2+
import json
3+
import websockets
4+
5+
def test_get_product_list(solana_test_validator, pythd, pyth_init_price):
6+
7+
data = {
8+
'jsonrpc': '2.0',
9+
'id': 1,
10+
'method': 'get_product_list',
11+
}
12+
data = json.dumps(data)
13+
async def f():
14+
async with websockets.connect('ws://localhost:8910/') as ws:
15+
await ws.send(data)
16+
result = await ws.recv()
17+
return result
18+
result = asyncio.run(f())
19+
result = json.loads(result)
20+
result = result['result']
21+
result = result[0]
22+
del result['account'] # TODO
23+
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+
},
32+
'price': [
33+
{
34+
'account': pyth_init_price,
35+
'price_exponent': -5,
36+
'price_type': 'price',
37+
},
38+
],
39+
}
40+
assert result == expected_result

0 commit comments

Comments
 (0)