|
1 | 1 | import argparse
|
2 | 2 | import glob
|
3 | 3 | import inspect
|
| 4 | +import json |
4 | 5 | import os
|
5 | 6 | import subprocess
|
6 | 7 | import time
|
| 8 | +from os import fdopen |
7 | 9 | from shutil import rmtree
|
8 | 10 | from subprocess import DEVNULL, Popen, check_call, check_output
|
9 |
| -from tempfile import mkdtemp |
| 11 | +from tempfile import mkdtemp, mkstemp |
10 | 12 |
|
11 | 13 | import pytest
|
12 | 14 |
|
@@ -228,3 +230,63 @@ def pyth_add_product(solana_test_validator, pyth_dir, pyth_init_mapping):
|
228 | 230 | output = output.decode('ascii')
|
229 | 231 | output = output.splitlines()
|
230 | 232 | return output[0]
|
| 233 | + |
| 234 | + |
| 235 | +@pytest.fixture(scope='session') |
| 236 | +def pyth_init_product(solana_test_validator, pyth_dir, pyth_add_product): |
| 237 | + |
| 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_') |
| 250 | + with fdopen(fd, 'w') as f: |
| 251 | + json.dump([ltc], f) |
| 252 | + cmd = [ |
| 253 | + 'pyth_admin', 'upd_product', path, |
| 254 | + '-r', 'localhost', |
| 255 | + '-k', pyth_dir, |
| 256 | + '-c', 'finalized', |
| 257 | + ] |
| 258 | + check_call(cmd) |
| 259 | + os.remove(path) |
| 260 | + return pyth_add_product |
| 261 | + |
| 262 | + |
| 263 | +@pytest.fixture(scope='session') |
| 264 | +def pyth_add_price(solana_test_validator, pyth_dir, pyth_init_product): |
| 265 | + |
| 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') |
| 281 | +def pyth_init_price(solana_test_validator, pyth_dir, pyth_add_price): |
| 282 | + |
| 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) |
| 292 | + return pyth_add_price |
0 commit comments