Skip to content

Commit d89e6c4

Browse files
committed
test publish
1 parent 14ea65f commit d89e6c4

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

pyth/tests/conftest.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,28 @@ def pyth_add_price(solana_test_validator, pyth_dir, pyth_init_product):
303303
return result
304304

305305

306-
@pytest.fixture(scope='function')
307-
def pyth_init_price(solana_test_validator, pyth_dir, pyth_add_price):
306+
@pytest.fixture(scope='session')
307+
def pyth_add_publisher(
308+
solana_test_validator, solana_keygen, pyth_dir, pyth_add_price
309+
):
308310

309311
for product, key in pyth_add_price.items():
312+
cmd = [
313+
'pyth_admin', 'add_publisher',
314+
solana_keygen[0], key,
315+
'-r', 'localhost',
316+
'-k', pyth_dir,
317+
'-c', 'finalized',
318+
'-n',
319+
]
320+
check_call(cmd)
321+
return pyth_add_price
322+
323+
324+
@pytest.fixture(scope='function')
325+
def pyth_init_price(solana_test_validator, pyth_dir, pyth_add_publisher):
326+
327+
for product, key in pyth_add_publisher.items():
310328
cmd = [
311329
'pyth_admin', 'init_price',
312330
key, '-e', '-5',
@@ -316,7 +334,7 @@ def pyth_init_price(solana_test_validator, pyth_dir, pyth_add_price):
316334
'-n',
317335
]
318336
check_call(cmd)
319-
return pyth_add_price
337+
return pyth_add_publisher
320338

321339

322340
@pytest.fixture(scope='session')

pyth/tests/test_publish.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import json
2+
import time
3+
from subprocess import check_call, check_output
4+
5+
6+
def test_publish(solana_test_validator, pyth_dir,
7+
pyth_init_product, pyth_init_price):
8+
9+
def get_price_acct():
10+
cmd = [
11+
'pyth', 'get_product',
12+
pyth_init_product['LTC'], # TODO get_price method
13+
'-r', 'localhost',
14+
'-k', pyth_dir,
15+
'-c', 'finalized',
16+
'-j',
17+
]
18+
output = check_output(cmd)
19+
output = output.decode('ascii')
20+
output = json.loads(output)
21+
return output['price_accounts'][0]
22+
23+
before = get_price_acct()
24+
assert before['publisher_accounts'][0]['price'] == 0
25+
assert before['publisher_accounts'][0]['conf'] == 0
26+
assert before['publisher_accounts'][0]['status'] == 'unknown'
27+
28+
cmd = [
29+
'pyth', 'upd_price_val',
30+
pyth_init_price['LTC'],
31+
'150', '10', 'trading',
32+
'-r', 'localhost',
33+
'-k', pyth_dir,
34+
'-c', 'finalized',
35+
'-x',
36+
]
37+
check_call(cmd)
38+
39+
time.sleep(20)
40+
41+
cmd = [
42+
'pyth', 'upd_price',
43+
pyth_init_price['LTC'],
44+
'-r', 'localhost',
45+
'-k', pyth_dir,
46+
'-c', 'finalized',
47+
'-x',
48+
]
49+
check_call(cmd)
50+
51+
time.sleep(20)
52+
53+
after = get_price_acct()
54+
assert after['publisher_accounts'][0]['price'] == 150
55+
assert after['publisher_accounts'][0]['conf'] == 10
56+
assert after['publisher_accounts'][0]['status'] == 'trading'

0 commit comments

Comments
 (0)