Skip to content

Commit cbb2433

Browse files
committed
remove default value for first_mapping_account_key in PythClient
1 parent 4337d74 commit cbb2433

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

examples/dump.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from loguru import logger
1111

1212
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13-
from pythclient.pythclient import PythClient, V2_PROGRAM_KEY, V2_FIRST_MAPPING_ACCOUNT_KEY # noqa
13+
from pythclient.pythclient import PythClient # noqa
1414
from pythclient.ratelimit import RateLimit # noqa
1515
from pythclient.pythaccounts import PythPriceAccount # noqa
16+
from pythclient.utils import get_key # noqa
1617

1718
logger.enable("pythclient")
1819

@@ -32,9 +33,11 @@ def set_to_exit(sig: Any, frame: Any):
3233
async def main():
3334
global to_exit
3435
use_program = len(sys.argv) >= 2 and sys.argv[1] == "program"
36+
v2_first_mapping_account_key = get_key("devnet", "mapping")
37+
v2_program_key = get_key("devnet", "program")
3538
async with PythClient(
36-
first_mapping_account_key=V2_FIRST_MAPPING_ACCOUNT_KEY,
37-
program_key=V2_PROGRAM_KEY if use_program else None,
39+
first_mapping_account_key=v2_first_mapping_account_key,
40+
program_key=v2_program_key if use_program else None,
3841
) as c:
3942
await c.refresh_all_prices()
4043
products = await c.get_products()
@@ -57,7 +60,7 @@ async def main():
5760
await ws.connect()
5861
if use_program:
5962
print("Subscribing to program account")
60-
await ws.program_subscribe(V2_PROGRAM_KEY, await c.get_all_accounts())
63+
await ws.program_subscribe(v2_program_key, await c.get_all_accounts())
6164
else:
6265
print("Subscribing to all prices")
6366
for account in all_prices:
@@ -88,7 +91,7 @@ async def main():
8891

8992
print("Unsubscribing...")
9093
if use_program:
91-
await ws.program_unsubscribe(V2_PROGRAM_KEY)
94+
await ws.program_unsubscribe(v2_program_key)
9295
else:
9396
for account in all_prices:
9497
await ws.unsubscribe(account)

pythclient/pythclient.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313
from .solana import SolanaAccount, SolanaClient, SolanaPublicKey, SOLANA_DEVNET_HTTP_ENDPOINT, SOLANA_DEVNET_WS_ENDPOINT, SolanaPublicKeyOrStr
1414
from .pythaccounts import PythAccount, PythMappingAccount, PythProductAccount, PythPriceAccount
1515
from . import exceptions, config, ratelimit
16-
from .utils import get_key
17-
18-
V2_FIRST_MAPPING_ACCOUNT_KEY = get_key("devnet", "mapping")
19-
V2_PROGRAM_KEY = get_key("devnet", "program")
2016

2117

2218
class PythClient:
2319
def __init__(self, *,
2420
solana_client: Optional[SolanaClient] = None,
2521
solana_endpoint: str = SOLANA_DEVNET_HTTP_ENDPOINT,
2622
solana_ws_endpoint: str = SOLANA_DEVNET_WS_ENDPOINT,
27-
first_mapping_account_key: str = V2_FIRST_MAPPING_ACCOUNT_KEY,
23+
first_mapping_account_key: str,
2824
program_key: Optional[str] = None,
2925
aiohttp_client_session: Optional[aiohttp.ClientSession] = None) -> None:
3026
self._first_mapping_account_key = SolanaPublicKey(first_mapping_account_key)

tests/test_pyth_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
_ACCOUNT_HEADER_BYTES, _VERSION_2, PythMappingAccount, PythPriceType, PythProductAccount, PythPriceAccount
77
)
88

9-
from pythclient.pythclient import PythClient, V2_FIRST_MAPPING_ACCOUNT_KEY, V2_PROGRAM_KEY, WatchSession
9+
from pythclient.pythclient import PythClient, WatchSession
1010
from pythclient.solana import (
1111
SolanaClient,
1212
SolanaCommitment,
@@ -16,14 +16,17 @@
1616

1717
from pytest_mock import MockerFixture
1818

19-
from mock import AsyncMock
19+
from mock import AsyncMock, Mock
2020

2121

2222
# Using constants instead of fixtures because:
2323
# 1) these values are not expected to be mutated
2424
# 2) these values are used in get_account_info_resp() and get_program_accounts_resp()
2525
# and so if they are passed in as fixtures, the functions will complain for the args
2626
# while mocking the respective functions
27+
V2_FIRST_MAPPING_ACCOUNT_KEY = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'
28+
V2_PROGRAM_KEY = 'gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s'
29+
2730
BCH_PRODUCT_ACCOUNT_KEY = '89GseEmvNkzAMMEXcW9oTYzqRPXTsJ3BmNerXmgA1osV'
2831
BCH_PRICE_ACCOUNT_KEY = '4EQrNZYk5KR1RnjyzbaaRbHsv8VqZWzSUtvx58wLsZbj'
2932

0 commit comments

Comments
 (0)