76
76
asyncio .set_event_loop (asyncio .new_event_loop ())
77
77
78
78
79
- class PythdClient :
79
+ class PythAgentClient :
80
80
81
81
def __init__ (self , address : str ) -> None :
82
82
self .address : str = address
@@ -86,15 +86,16 @@ async def connect(self) -> Server:
86
86
self .server = Server (self .address )
87
87
task = await self .server .ws_connect ()
88
88
task .add_done_callback (self ._on_connection_done )
89
- LOGGER .debug ("connected to pythd websocket server at %s" , self .address )
89
+ LOGGER .debug (
90
+ "connected to pyth agent websocket server at %s" , self .address )
90
91
91
92
async def close (self ) -> None :
92
93
await self .server .close ()
93
- LOGGER .debug ("closed pythd connection" )
94
+ LOGGER .debug ("closed pyth agent websocket connection" )
94
95
95
96
@staticmethod
96
97
def _on_connection_done (task ):
97
- LOGGER .debug ("pythd connection closed" )
98
+ LOGGER .debug ("pyth agent connection closed" )
98
99
if not task .cancelled () and task .exception () is not None :
99
100
e = task .exception ()
100
101
LOGGER .error (e , exc_info = 1 )
@@ -311,19 +312,19 @@ def agent(self, sync_accounts, agent_keystore, tmp_path):
311
312
yield
312
313
313
314
@pytest_asyncio .fixture
314
- async def pythd (self , agent ):
315
- pythd = PythdClient (address = "ws://localhost:8910" )
316
- await pythd .connect ()
317
- yield pythd
318
- await pythd .close ()
315
+ async def client (self , agent ):
316
+ client = PythAgentClient (address = "ws://localhost:8910" )
317
+ await client .connect ()
318
+ yield client
319
+ await client .close ()
319
320
320
321
321
322
class TestUpdatePrice (PythTest ):
322
323
323
324
@pytest .mark .asyncio
324
- async def test_update_price_simple (self , pythd : PythdClient ):
325
+ async def test_update_price_simple (self , client : PythAgentClient ):
325
326
# Fetch all products
326
- products = {product ["attr_dict" ]["symbol" ]: product for product in await pythd .get_all_products ()}
327
+ products = {product ["attr_dict" ]["symbol" ]: product for product in await client .get_all_products ()}
327
328
328
329
# Find the product account ID corresponding to the BTC/USD symbol
329
330
product = products [BTC_USD ["attr_dict" ]["symbol" ]]
@@ -333,15 +334,15 @@ async def test_update_price_simple(self, pythd: PythdClient):
333
334
price_account = product ["price_accounts" ][0 ]["account" ]
334
335
335
336
# Send an "update_price" request
336
- await pythd .update_price (price_account , 42 , 2 , "trading" )
337
+ await client .update_price (price_account , 42 , 2 , "trading" )
337
338
time .sleep (2 )
338
339
339
340
# Send another "update_price" request to trigger aggregation
340
- await pythd .update_price (price_account , 81 , 1 , "trading" )
341
+ await client .update_price (price_account , 81 , 1 , "trading" )
341
342
time .sleep (2 )
342
343
343
344
# Confirm that the price account has been updated with the values from the first "update_price" request
344
- product = await pythd .get_product (product_account )
345
+ product = await client .get_product (product_account )
345
346
price_account = product ["price_accounts" ][0 ]
346
347
assert price_account ["price" ] == 42
347
348
assert price_account ["conf" ] == 2
0 commit comments