diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ec054b..3cecfcd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file. ### Added - Added support for all queries in the chain 'tendermint' module +### Changed +- Refactored cookies management logic to use all gRPC calls' responses to update the current cookies + ## [1.4.1] - 2024-03-12 ### Changed - Updates example scripts that were still using deprecated methods diff --git a/pyinjective/async_client.py b/pyinjective/async_client.py index 86c74833..dc1968e7 100644 --- a/pyinjective/async_client.py +++ b/pyinjective/async_client.py @@ -3,7 +3,7 @@ import time from copy import deepcopy from decimal import Decimal -from typing import Any, Callable, Coroutine, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, Union from warnings import warn import grpc @@ -166,169 +166,115 @@ def __init__( self.bank_api = ChainGrpcBankApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.auth_api = ChainGrpcAuthApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.authz_api = ChainGrpcAuthZApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.distribution_api = ChainGrpcDistributionApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.chain_exchange_api = ChainGrpcExchangeApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.tendermint_api = TendermintGrpcApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.token_factory_api = ChainGrpcTokenFactoryApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.tx_api = TxGrpcApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.wasm_api = ChainGrpcWasmApi( channel=self.chain_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.chain_stream_api = ChainGrpcChainStream( channel=self.chain_stream_channel, - metadata_provider=lambda: self.network.chain_metadata( - metadata_query_provider=self._chain_cookie_metadata_requestor - ), + cookie_assistant=network.chain_cookie_assistant, ) self.exchange_account_api = IndexerGrpcAccountApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_auction_api = IndexerGrpcAuctionApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_derivative_api = IndexerGrpcDerivativeApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_insurance_api = IndexerGrpcInsuranceApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_meta_api = IndexerGrpcMetaApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_oracle_api = IndexerGrpcOracleApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_portfolio_api = IndexerGrpcPortfolioApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_spot_api = IndexerGrpcSpotApi( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_account_stream_api = IndexerGrpcAccountStream( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_auction_stream_api = IndexerGrpcAuctionStream( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_derivative_stream_api = IndexerGrpcDerivativeStream( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_meta_stream_api = IndexerGrpcMetaStream( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_oracle_stream_api = IndexerGrpcOracleStream( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_portfolio_stream_api = IndexerGrpcPortfolioStream( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_spot_stream_api = IndexerGrpcSpotStream( channel=self.exchange_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ), + cookie_assistant=network.exchange_cookie_assistant, ) self.exchange_explorer_api = IndexerGrpcExplorerApi( channel=self.explorer_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._explorer_cookie_metadata_requestor - ), + cookie_assistant=network.explorer_cookie_assistant, ) self.exchange_explorer_stream_api = IndexerGrpcExplorerStream( channel=self.explorer_channel, - metadata_provider=lambda: self.network.exchange_metadata( - metadata_query_provider=self._explorer_cookie_metadata_requestor - ), + cookie_assistant=network.explorer_cookie_assistant, ) async def all_tokens(self) -> Dict[str, Token]: @@ -404,7 +350,7 @@ async def get_account(self, address: str) -> Optional[account_pb2.EthAccount]: warn("This method is deprecated. Use fetch_account instead", DeprecationWarning, stacklevel=2) try: - metadata = await self.network.chain_metadata(metadata_query_provider=self._chain_cookie_metadata_requestor) + metadata = self.network.chain_cookie_assistant.metadata() account_any = ( await self.stubAuth.Account(auth_query.QueryAccountRequest(address=address), metadata=metadata) ).account @@ -460,7 +406,7 @@ async def simulate_tx(self, tx_byte: bytes) -> Tuple[Union[abci_type.SimulationR warn("This method is deprecated. Use simulate instead", DeprecationWarning, stacklevel=2) try: req = tx_service.SimulateRequest(tx_bytes=tx_byte) - metadata = await self.network.chain_metadata(metadata_query_provider=self._chain_cookie_metadata_requestor) + metadata = self.network.chain_cookie_assistant.metadata() return await self.stubTx.Simulate(request=req, metadata=metadata), True except grpc.RpcError as err: return err, False @@ -474,7 +420,7 @@ async def send_tx_sync_mode(self, tx_byte: bytes) -> abci_type.TxResponse: """ warn("This method is deprecated. Use broadcast_tx_sync_mode instead", DeprecationWarning, stacklevel=2) req = tx_service.BroadcastTxRequest(tx_bytes=tx_byte, mode=tx_service.BroadcastMode.BROADCAST_MODE_SYNC) - metadata = await self.network.chain_metadata(metadata_query_provider=self._chain_cookie_metadata_requestor) + metadata = self.network.chain_cookie_assistant.metadata() result = await self.stubTx.BroadcastTx(request=req, metadata=metadata) return result.tx_response @@ -487,7 +433,7 @@ async def send_tx_async_mode(self, tx_byte: bytes) -> abci_type.TxResponse: """ warn("This method is deprecated. Use broadcast_tx_async_mode instead", DeprecationWarning, stacklevel=2) req = tx_service.BroadcastTxRequest(tx_bytes=tx_byte, mode=tx_service.BroadcastMode.BROADCAST_MODE_ASYNC) - metadata = await self.network.chain_metadata(metadata_query_provider=self._chain_cookie_metadata_requestor) + metadata = self.network.chain_cookie_assistant.metadata() result = await self.stubTx.BroadcastTx(request=req, metadata=metadata) return result.tx_response @@ -500,7 +446,7 @@ async def send_tx_block_mode(self, tx_byte: bytes) -> abci_type.TxResponse: """ warn("This method is deprecated. BLOCK broadcast mode should not be used", DeprecationWarning, stacklevel=2) req = tx_service.BroadcastTxRequest(tx_bytes=tx_byte, mode=tx_service.BroadcastMode.BROADCAST_MODE_BLOCK) - metadata = await self.network.chain_metadata(metadata_query_provider=self._chain_cookie_metadata_requestor) + metadata = self.network.chain_cookie_assistant.metadata() result = await self.stubTx.BroadcastTx(request=req, metadata=metadata) return result.tx_response @@ -1838,9 +1784,7 @@ async def stream_spot_markets(self, **kwargs): warn("This method is deprecated. Use listen_spot_markets_updates instead", DeprecationWarning, stacklevel=2) req = spot_exchange_rpc_pb.StreamMarketsRequest(market_ids=kwargs.get("market_ids")) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubSpotExchange.StreamMarkets(request=req, metadata=metadata) async def listen_spot_markets_updates( @@ -2030,9 +1974,7 @@ async def stream_spot_orderbook_snapshot(self, market_ids: List[str]): """ warn("This method is deprecated. Use listen_spot_orderbook_snapshots instead", DeprecationWarning, stacklevel=2) req = spot_exchange_rpc_pb.StreamOrderbookV2Request(market_ids=market_ids) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubSpotExchange.StreamOrderbookV2(request=req, metadata=metadata) async def listen_spot_orderbook_snapshots( @@ -2055,9 +1997,7 @@ async def stream_spot_orderbook_update(self, market_ids: List[str]): """ warn("This method is deprecated. Use listen_spot_orderbook_updates instead", DeprecationWarning, stacklevel=2) req = spot_exchange_rpc_pb.StreamOrderbookUpdateRequest(market_ids=market_ids) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubSpotExchange.StreamOrderbookUpdate(request=req, metadata=metadata) async def listen_spot_orderbook_updates( @@ -2093,9 +2033,7 @@ async def stream_spot_orders(self, market_id: str, **kwargs): trade_id=kwargs.get("trade_id"), cid=kwargs.get("cid"), ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubSpotExchange.StreamOrders(request=req, metadata=metadata) async def listen_spot_orders_updates( @@ -2143,9 +2081,7 @@ async def stream_historical_spot_orders(self, market_id: str, **kwargs): state=kwargs.get("state"), execution_types=kwargs.get("execution_types"), ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubSpotExchange.StreamOrdersHistory(request=req, metadata=metadata) async def listen_spot_orders_history_updates( @@ -2190,9 +2126,7 @@ async def stream_historical_derivative_orders(self, market_id: str, **kwargs): state=kwargs.get("state"), execution_types=kwargs.get("execution_types"), ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubDerivativeExchange.StreamOrdersHistory(request=req, metadata=metadata) async def listen_derivative_orders_history_updates( @@ -2240,9 +2174,7 @@ async def stream_spot_trades(self, **kwargs): account_address=kwargs.get("account_address"), cid=kwargs.get("cid"), ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubSpotExchange.StreamTrades(request=req, metadata=metadata) async def listen_spot_trades_updates( @@ -2375,9 +2307,7 @@ async def stream_derivative_markets(self, **kwargs): "This method is deprecated. Use listen_derivative_market_updates instead", DeprecationWarning, stacklevel=2 ) req = derivative_exchange_rpc_pb.StreamMarketRequest(market_ids=kwargs.get("market_ids")) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubDerivativeExchange.StreamMarket(request=req, metadata=metadata) async def listen_derivative_market_updates( @@ -2580,9 +2510,7 @@ async def stream_derivative_orderbook_snapshot(self, market_ids: List[str]): stacklevel=2, ) req = derivative_exchange_rpc_pb.StreamOrderbookV2Request(market_ids=market_ids) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubDerivativeExchange.StreamOrderbookV2(request=req, metadata=metadata) async def listen_derivative_orderbook_snapshots( @@ -2609,9 +2537,7 @@ async def stream_derivative_orderbook_update(self, market_ids: List[str]): stacklevel=2, ) req = derivative_exchange_rpc_pb.StreamOrderbookUpdateRequest(market_ids=market_ids) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubDerivativeExchange.StreamOrderbookUpdate(request=req, metadata=metadata) async def listen_derivative_orderbook_updates( @@ -2651,9 +2577,7 @@ async def stream_derivative_orders(self, market_id: str, **kwargs): trade_id=kwargs.get("trade_id"), cid=kwargs.get("cid"), ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubDerivativeExchange.StreamOrders(request=req, metadata=metadata) async def listen_derivative_orders_updates( @@ -2711,9 +2635,7 @@ async def stream_derivative_trades(self, **kwargs): account_address=kwargs.get("account_address"), cid=kwargs.get("cid"), ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubDerivativeExchange.StreamTrades(request=req, metadata=metadata) async def listen_derivative_trades_updates( @@ -2793,9 +2715,7 @@ async def stream_derivative_positions(self, **kwargs): subaccount_id=kwargs.get("subaccount_id"), subaccount_ids=kwargs.get("subaccount_ids"), ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubDerivativeExchange.StreamPositions(request=req, metadata=metadata) async def listen_derivative_positions_updates( @@ -3008,9 +2928,7 @@ async def stream_account_portfolio(self, account_address: str, **kwargs): req = portfolio_rpc_pb.StreamAccountPortfolioRequest( account_address=account_address, subaccount_id=kwargs.get("subaccount_id"), type=kwargs.get("type") ) - metadata = await self.network.exchange_metadata( - metadata_query_provider=self._exchange_cookie_metadata_requestor - ) + metadata = self.network.exchange_cookie_assistant.metadata() return self.stubPortfolio.StreamAccountPortfolio(request=req, metadata=metadata) async def listen_account_portfolio_updates( @@ -3060,7 +2978,7 @@ async def chain_stream( positions_filter=positions_filter, oracle_price_filter=oracle_price_filter, ) - metadata = await self.network.chain_metadata(metadata_query_provider=self._chain_cookie_metadata_requestor) + metadata = self.network.chain_cookie_assistant.metadata() return self.chain_stream_stub.Stream(request=request, metadata=metadata) async def listen_chain_stream_updates( @@ -3289,18 +3207,6 @@ def _token_representation( return tokens_by_denom[denom] - def _chain_cookie_metadata_requestor(self) -> Coroutine: - request = tendermint_query.GetLatestBlockRequest() - return self.stubCosmosTendermint.GetLatestBlock(request).initial_metadata() - - def _exchange_cookie_metadata_requestor(self) -> Coroutine: - request = exchange_meta_rpc_pb.VersionRequest() - return self.stubMeta.Version(request).initial_metadata() - - def _explorer_cookie_metadata_requestor(self) -> Coroutine: - request = explorer_rpc_pb.GetBlocksRequest() - return self.stubExplorer.GetBlocks(request).initial_metadata() - def _initialize_timeout_height_sync_task(self): self._cancel_timeout_height_sync_task() self._timeout_height_sync_task = asyncio.get_event_loop().create_task(self._timeout_height_sync_process()) diff --git a/pyinjective/client/chain/grpc/chain_grpc_auction_api.py b/pyinjective/client/chain/grpc/chain_grpc_auction_api.py index 3f9d89fb..d2d2a211 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_auction_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_auction_api.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.injective.auction.v1beta1 import ( query_pb2 as auction_query_pb, query_pb2_grpc as auction_query_grpc, @@ -10,9 +11,9 @@ class ChainGrpcAuctionApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = auction_query_grpc.QueryStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_module_params(self) -> Dict[str, Any]: request = auction_query_pb.QueryAuctionParamsRequest() diff --git a/pyinjective/client/chain/grpc/chain_grpc_auth_api.py b/pyinjective/client/chain/grpc/chain_grpc_auth_api.py index 7b0c73dc..6980369a 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_auth_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_auth_api.py @@ -3,14 +3,15 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.cosmos.auth.v1beta1 import query_pb2 as auth_query_pb, query_pb2_grpc as auth_query_grpc from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant class ChainGrpcAuthApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = auth_query_grpc.QueryStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_module_params(self) -> Dict[str, Any]: request = auth_query_pb.QueryParamsRequest() diff --git a/pyinjective/client/chain/grpc/chain_grpc_authz_api.py b/pyinjective/client/chain/grpc/chain_grpc_authz_api.py index dae2e3c5..d06b4e8c 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_authz_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_authz_api.py @@ -3,14 +3,15 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.cosmos.authz.v1beta1 import query_pb2 as authz_query, query_pb2_grpc as authz_query_grpc from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant class ChainGrpcAuthZApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = authz_query_grpc.QueryStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_grants( self, diff --git a/pyinjective/client/chain/grpc/chain_grpc_bank_api.py b/pyinjective/client/chain/grpc/chain_grpc_bank_api.py index 69d0cd0e..cdbd3f1b 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_bank_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_bank_api.py @@ -3,14 +3,15 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.cosmos.bank.v1beta1 import query_pb2 as bank_query_pb, query_pb2_grpc as bank_query_grpc from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant class ChainGrpcBankApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = bank_query_grpc.QueryStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_module_params(self) -> Dict[str, Any]: request = bank_query_pb.QueryParamsRequest() diff --git a/pyinjective/client/chain/grpc/chain_grpc_distribution_api.py b/pyinjective/client/chain/grpc/chain_grpc_distribution_api.py index e7da0966..7e201a42 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_distribution_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_distribution_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.cosmos.distribution.v1beta1 import ( query_pb2 as distribution_query_pb, query_pb2_grpc as distribution_query_grpc, @@ -11,9 +12,9 @@ class ChainGrpcDistributionApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = distribution_query_grpc.QueryStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_module_params(self) -> Dict[str, Any]: request = distribution_query_pb.QueryParamsRequest() diff --git a/pyinjective/client/chain/grpc/chain_grpc_exchange_api.py b/pyinjective/client/chain/grpc/chain_grpc_exchange_api.py index b79e8569..6ac66a67 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_exchange_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_exchange_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.injective.exchange.v1beta1 import ( query_pb2 as exchange_query_pb, query_pb2_grpc as exchange_query_grpc, @@ -11,9 +12,9 @@ class ChainGrpcExchangeApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = exchange_query_grpc.QueryStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_exchange_params(self) -> Dict[str, Any]: request = exchange_query_pb.QueryExchangeParamsRequest() diff --git a/pyinjective/client/chain/grpc/chain_grpc_token_factory_api.py b/pyinjective/client/chain/grpc/chain_grpc_token_factory_api.py index 48e1df1c..457f6f1b 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_token_factory_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_token_factory_api.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.injective.tokenfactory.v1beta1 import ( query_pb2 as token_factory_query_pb, query_pb2_grpc as token_factory_query_grpc, @@ -11,10 +12,10 @@ class ChainGrpcTokenFactoryApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._query_stub = token_factory_query_grpc.QueryStub(channel) self._tx_stub = token_factory_tx_grpc.MsgStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_module_params(self) -> Dict[str, Any]: request = token_factory_query_pb.QueryParamsRequest() diff --git a/pyinjective/client/chain/grpc/chain_grpc_wasm_api.py b/pyinjective/client/chain/grpc/chain_grpc_wasm_api.py index 1d08e1c3..adc65e88 100644 --- a/pyinjective/client/chain/grpc/chain_grpc_wasm_api.py +++ b/pyinjective/client/chain/grpc/chain_grpc_wasm_api.py @@ -3,14 +3,15 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.cosmwasm.wasm.v1 import query_pb2 as wasm_query_pb, query_pb2_grpc as wasm_query_grpc from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant class ChainGrpcWasmApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = wasm_query_grpc.QueryStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_module_params(self) -> Dict[str, Any]: request = wasm_query_pb.QueryParamsRequest() diff --git a/pyinjective/client/chain/grpc_stream/chain_grpc_chain_stream.py b/pyinjective/client/chain/grpc_stream/chain_grpc_chain_stream.py index 46b99780..019ecc31 100644 --- a/pyinjective/client/chain/grpc_stream/chain_grpc_chain_stream.py +++ b/pyinjective/client/chain/grpc_stream/chain_grpc_chain_stream.py @@ -2,14 +2,15 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.injective.stream.v1beta1 import query_pb2 as chain_stream_pb, query_pb2_grpc as chain_stream_grpc from pyinjective.utils.grpc_api_stream_assistant import GrpcApiStreamAssistant class ChainGrpcChainStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = chain_stream_grpc.StreamStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream( self, diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py index 8fc387c1..3d985595 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_account_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_accounts_rpc_pb2 as exchange_accounts_pb, injective_accounts_rpc_pb2_grpc as exchange_accounts_grpc, @@ -11,9 +12,9 @@ class IndexerGrpcAccountApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_accounts_grpc.InjectiveAccountsRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_portfolio(self, account_address: str) -> Dict[str, Any]: request = exchange_accounts_pb.PortfolioRequest(account_address=account_address) diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_auction_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_auction_api.py index c9b9d853..e543d16e 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_auction_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_auction_api.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_auction_rpc_pb2 as exchange_auction_pb, injective_auction_rpc_pb2_grpc as exchange_auction_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcAuctionApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_auction_grpc.InjectiveAuctionRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_auction(self, round: int) -> Dict[str, Any]: request = exchange_auction_pb.AuctionEndpointRequest(round=round) diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_derivative_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_derivative_api.py index 7f28c7ac..1d0220ee 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_derivative_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_derivative_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_derivative_exchange_rpc_pb2 as exchange_derivative_pb, injective_derivative_exchange_rpc_pb2_grpc as exchange_derivative_grpc, @@ -11,9 +12,9 @@ class IndexerGrpcDerivativeApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_derivative_grpc.InjectiveDerivativeExchangeRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_markets( self, diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_explorer_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_explorer_api.py index 89bfc3c7..b08f5390 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_explorer_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_explorer_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_explorer_rpc_pb2 as exchange_explorer_pb, injective_explorer_rpc_pb2_grpc as exchange_explorer_grpc, @@ -11,9 +12,9 @@ class IndexerGrpcExplorerApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_explorer_grpc.InjectiveExplorerRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_account_txs( self, diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_insurance_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_insurance_api.py index 95476677..ea658bda 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_insurance_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_insurance_api.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_insurance_rpc_pb2 as exchange_insurance_pb, injective_insurance_rpc_pb2_grpc as exchange_insurance_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcInsuranceApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_insurance_grpc.InjectiveInsuranceRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_insurance_funds(self) -> Dict[str, Any]: request = exchange_insurance_pb.FundsRequest() diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_meta_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_meta_api.py index 27e108e1..0d06f884 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_meta_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_meta_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_meta_rpc_pb2 as exchange_meta_pb, injective_meta_rpc_pb2_grpc as exchange_meta_grpc, @@ -11,9 +12,9 @@ class IndexerGrpcMetaApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_meta_grpc.InjectiveMetaRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_ping(self) -> Dict[str, Any]: request = exchange_meta_pb.PingRequest() diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_oracle_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_oracle_api.py index 72416be7..ccf16ee9 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_oracle_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_oracle_api.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_oracle_rpc_pb2 as exchange_oracle_pb, injective_oracle_rpc_pb2_grpc as exchange_oracle_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcOracleApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_oracle_grpc.InjectiveOracleRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_oracle_list(self) -> Dict[str, Any]: request = exchange_oracle_pb.OracleListRequest() diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_portfolio_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_portfolio_api.py index 510f7054..d9d7460c 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_portfolio_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_portfolio_api.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_portfolio_rpc_pb2 as exchange_portfolio_pb, injective_portfolio_rpc_pb2_grpc as exchange_portfolio_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcPortfolioApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_portfolio_grpc.InjectivePortfolioRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_account_portfolio(self, account_address: str) -> Dict[str, Any]: request = exchange_portfolio_pb.AccountPortfolioRequest(account_address=account_address) diff --git a/pyinjective/client/indexer/grpc/indexer_grpc_spot_api.py b/pyinjective/client/indexer/grpc/indexer_grpc_spot_api.py index 994b2685..f91ecaf8 100644 --- a/pyinjective/client/indexer/grpc/indexer_grpc_spot_api.py +++ b/pyinjective/client/indexer/grpc/indexer_grpc_spot_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_spot_exchange_rpc_pb2 as exchange_spot_pb, injective_spot_exchange_rpc_pb2_grpc as exchange_spot_grpc, @@ -11,9 +12,9 @@ class IndexerGrpcSpotApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_spot_grpc.InjectiveSpotExchangeRPCStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_markets( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_account_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_account_stream.py index 04ba1af3..6fcaf1c8 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_account_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_account_stream.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_accounts_rpc_pb2 as exchange_accounts_pb, injective_accounts_rpc_pb2_grpc as exchange_accounts_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcAccountStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_accounts_grpc.InjectiveAccountsRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_subaccount_balance( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_auction_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_auction_stream.py index 43009ee9..f2477c82 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_auction_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_auction_stream.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_auction_rpc_pb2 as exchange_auction_pb, injective_auction_rpc_pb2_grpc as exchange_auction_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcAuctionStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_auction_grpc.InjectiveAuctionRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_bids( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_derivative_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_derivative_stream.py index b5c790db..2759e6a5 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_derivative_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_derivative_stream.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_derivative_exchange_rpc_pb2 as exchange_derivative_pb, injective_derivative_exchange_rpc_pb2_grpc as exchange_derivative_grpc, @@ -11,9 +12,9 @@ class IndexerGrpcDerivativeStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_derivative_grpc.InjectiveDerivativeExchangeRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_market( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_explorer_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_explorer_stream.py index aa4a69ae..faf96647 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_explorer_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_explorer_stream.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_explorer_rpc_pb2 as exchange_explorer_pb, injective_explorer_rpc_pb2_grpc as exchange_explorer_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcExplorerStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_explorer_grpc.InjectiveExplorerRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_txs( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_meta_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_meta_stream.py index aeff1132..bc2a9a7c 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_meta_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_meta_stream.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_meta_rpc_pb2 as exchange_meta_pb, injective_meta_rpc_pb2_grpc as exchange_meta_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcMetaStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_meta_grpc.InjectiveMetaRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_keepalive( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_oracle_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_oracle_stream.py index 0bad6e35..5ff2e4d5 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_oracle_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_oracle_stream.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_oracle_rpc_pb2 as exchange_oracle_pb, injective_oracle_rpc_pb2_grpc as exchange_oracle_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcOracleStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_oracle_grpc.InjectiveOracleRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_oracle_prices( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_portfolio_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_portfolio_stream.py index 59b0acfa..e1c202d2 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_portfolio_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_portfolio_stream.py @@ -2,6 +2,7 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_portfolio_rpc_pb2 as exchange_portfolio_pb, injective_portfolio_rpc_pb2_grpc as exchange_portfolio_grpc, @@ -10,9 +11,9 @@ class IndexerGrpcPortfolioStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_portfolio_grpc.InjectivePortfolioRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_account_portfolio( self, diff --git a/pyinjective/client/indexer/grpc_stream/indexer_grpc_spot_stream.py b/pyinjective/client/indexer/grpc_stream/indexer_grpc_spot_stream.py index 79b185af..0d7f32c9 100644 --- a/pyinjective/client/indexer/grpc_stream/indexer_grpc_spot_stream.py +++ b/pyinjective/client/indexer/grpc_stream/indexer_grpc_spot_stream.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.exchange import ( injective_spot_exchange_rpc_pb2 as exchange_spot_pb, injective_spot_exchange_rpc_pb2_grpc as exchange_spot_grpc, @@ -11,9 +12,9 @@ class IndexerGrpcSpotStream: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = self._stub = exchange_spot_grpc.InjectiveSpotExchangeRPCStub(channel) - self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant) async def stream_markets( self, diff --git a/pyinjective/core/network.py b/pyinjective/core/network.py index 93d006eb..e11528ec 100644 --- a/pyinjective/core/network.py +++ b/pyinjective/core/network.py @@ -1,171 +1,103 @@ -import asyncio import datetime -import time from abc import ABC, abstractmethod from http.cookies import SimpleCookie -from typing import Callable, Optional, Tuple +from typing import List, Optional +from grpc.aio import Call, Metadata -class CookieAssistant(ABC): - SESSION_RENEWAL_OFFSET = 120 +class CookieAssistant(ABC): @abstractmethod - async def chain_cookie(self, metadata_query_provider: Callable) -> str: + def cookie(self) -> Optional[str]: ... @abstractmethod - async def exchange_cookie(self, metadata_query_provider: Callable) -> str: + async def process_response_metadata(self, grpc_call: Call): ... - async def chain_metadata(self, metadata_query_provider: Callable) -> Tuple[Tuple[str, str]]: - cookie = await self.chain_cookie(metadata_query_provider=metadata_query_provider) - return (("cookie", cookie),) - - async def exchange_metadata(self, metadata_query_provider: Callable) -> Tuple[Tuple[str, str]]: - cookie = await self.exchange_cookie(metadata_query_provider=metadata_query_provider) - metadata = None + def metadata(self) -> Metadata: + cookie = self.cookie() + metadata = Metadata() if cookie is not None and cookie != "": - metadata = (("cookie", cookie),) + metadata.add("cookie", cookie) return metadata -class KubernetesLoadBalancedCookieAssistant(CookieAssistant): +class BareMetalLoadBalancedCookieAssistant(CookieAssistant): def __init__(self): - self._chain_cookie: Optional[str] = None - self._exchange_cookie: Optional[str] = None - self._chain_cookie_initialization_lock = asyncio.Lock() - self._exchange_cookie_initialization_lock = asyncio.Lock() - - async def chain_cookie(self, metadata_query_provider: Callable) -> str: - if self._chain_cookie is None: - async with self._chain_cookie_initialization_lock: - if self._chain_cookie is None: - await self._fetch_chain_cookie(metadata_query_provider=metadata_query_provider) - cookie = self._chain_cookie - self._check_chain_cookie_expiration() - - return cookie - - async def exchange_cookie(self, metadata_query_provider: Callable) -> str: - if self._exchange_cookie is None: - async with self._exchange_cookie_initialization_lock: - if self._exchange_cookie is None: - await self._fetch_exchange_cookie(metadata_query_provider=metadata_query_provider) - cookie = self._exchange_cookie - self._check_exchange_cookie_expiration() - - return cookie - - async def _fetch_chain_cookie(self, metadata_query_provider: Callable): - metadata = await metadata_query_provider() - cookie_info = next((value for key, value in metadata if key == "set-cookie"), None) + self._cookie: Optional[str] = None - if cookie_info is None: - raise RuntimeError(f"Error fetching chain cookie ({metadata})") + def cookie(self) -> Optional[str]: + self._check_cookie_expiration() - self._chain_cookie = cookie_info + return self._cookie - async def _fetch_exchange_cookie(self, metadata_query_provider: Callable): - metadata = await metadata_query_provider() - cookie_info = next((value for key, value in metadata if key == "set-cookie"), None) + async def process_response_metadata(self, grpc_call: Call): + metadata = await grpc_call.initial_metadata() + if "set-cookie" in metadata: + self._cookie = metadata["set-cookie"] - if cookie_info is None: - cookie_info = "" - - self._exchange_cookie = cookie_info - - def _check_chain_cookie_expiration(self): - if self._is_cookie_expired(cookie_data=self._chain_cookie): - self._chain_cookie = None - - def _check_exchange_cookie_expiration(self): - if self._is_cookie_expired(cookie_data=self._exchange_cookie): - self._exchange_cookie = None + def _check_cookie_expiration(self): + if self._is_cookie_expired(cookie_data=self._cookie): + self._cookie = None def _is_cookie_expired(self, cookie_data: str) -> bool: - cookie = SimpleCookie() - cookie.load(cookie_data) - - expiration_data: Optional[str] = cookie.get("GCLB", {}).get("expires", None) - if expiration_data is None: - expiration_time = 0 - else: - expiration_time = datetime.datetime.strptime(expiration_data, "%a, %d-%b-%Y %H:%M:%S %Z").timestamp() - - timestamp_diff = expiration_time - time.time() - return timestamp_diff < self.SESSION_RENEWAL_OFFSET - - -class BareMetalLoadBalancedCookieAssistant(CookieAssistant): - def __init__(self): - self._chain_cookie: Optional[str] = None - self._exchange_cookie: Optional[str] = None - self._chain_cookie_initialization_lock = asyncio.Lock() - self._exchange_cookie_initialization_lock = asyncio.Lock() - - async def chain_cookie(self, metadata_query_provider: Callable) -> str: - if self._chain_cookie is None: - async with self._chain_cookie_initialization_lock: - if self._chain_cookie is None: - await self._fetch_chain_cookie(metadata_query_provider=metadata_query_provider) - cookie = self._chain_cookie - self._check_chain_cookie_expiration() + # The cookies for these nodes do not expire + return False - return cookie - async def exchange_cookie(self, metadata_query_provider: Callable) -> str: - if self._exchange_cookie is None: - async with self._exchange_cookie_initialization_lock: - if self._exchange_cookie is None: - await self._fetch_exchange_cookie(metadata_query_provider=metadata_query_provider) - cookie = self._exchange_cookie - self._check_exchange_cookie_expiration() +class ExpiringCookieAssistant(CookieAssistant): + def __init__(self, expiration_time_keys_sequence: List[str], time_format: str): + self._cookie: Optional[str] = None + self._expiration_time_keys_sequence = expiration_time_keys_sequence + self._time_format = time_format - return cookie + @classmethod + def for_kubernetes_public_server(cls): + return cls( + expiration_time_keys_sequence=["grpc-cookie", "expires"], + time_format="%a, %d-%b-%Y %H:%M:%S %Z", + ) - async def _fetch_chain_cookie(self, metadata_query_provider: Callable): - metadata = await metadata_query_provider() - cookie_info = next((value for key, value in metadata if key == "set-cookie"), None) + def cookie(self) -> Optional[str]: + self._check_cookie_expiration() - if cookie_info is None: - raise RuntimeError(f"Error fetching chain cookie ({metadata})") + return self._cookie - self._chain_cookie = cookie_info + async def process_response_metadata(self, grpc_call: Call): + metadata = await grpc_call.initial_metadata() + if "set-cookie" in metadata: + self._cookie = metadata["set-cookie"] - async def _fetch_exchange_cookie(self, metadata_query_provider: Callable): - metadata = await metadata_query_provider() - cookie_info = next((value for key, value in metadata if key == "set-cookie"), None) + def _check_cookie_expiration(self): + if self._is_cookie_expired(): + self._cookie = None - if cookie_info is None: - cookie_info = "" + def _is_cookie_expired(self) -> bool: + is_expired = False - self._exchange_cookie = cookie_info + if self._cookie is not None: + cookie = SimpleCookie() + cookie.load(self._cookie) + cookie_map = cookie - def _check_chain_cookie_expiration(self): - if self._is_cookie_expired(cookie_data=self._chain_cookie): - self._chain_cookie = None + for key in self._expiration_time_keys_sequence[:-1]: + cookie_map = cookie.get(key, {}) - def _check_exchange_cookie_expiration(self): - if self._is_cookie_expired(cookie_data=self._exchange_cookie): - self._exchange_cookie = None + expiration_data: Optional[str] = cookie_map.get(self._expiration_time_keys_sequence[-1], None) + if expiration_data is not None: + expiration_time = datetime.datetime.strptime(expiration_data, self._time_format) + is_expired = datetime.datetime.utcnow() >= expiration_time - def _is_cookie_expired(self, cookie_data: str) -> bool: - # The cookies for these nodes do not expire - return False + return is_expired class DisabledCookieAssistant(CookieAssistant): - async def chain_cookie(self, metadata_query_provider: Callable) -> str: - pass - - async def exchange_cookie(self, metadata_query_provider: Callable) -> str: - pass - - async def chain_metadata(self, metadata_query_provider: Callable) -> Tuple[Tuple[str, str]]: + def cookie(self) -> Optional[str]: return None - async def exchange_metadata(self, metadata_query_provider: Callable) -> Tuple[Tuple[str, str]]: - return None + async def process_response_metadata(self, grpc_call: Call): + pass class Network: @@ -180,7 +112,9 @@ def __init__( chain_id: str, fee_denom: str, env: str, - cookie_assistant: CookieAssistant, + chain_cookie_assistant: CookieAssistant, + exchange_cookie_assistant: CookieAssistant, + explorer_cookie_assistant: CookieAssistant, use_secure_connection: bool = False, ): self.lcd_endpoint = lcd_endpoint @@ -192,7 +126,9 @@ def __init__( self.chain_id = chain_id self.fee_denom = fee_denom self.env = env - self.cookie_assistant = cookie_assistant + self.chain_cookie_assistant = chain_cookie_assistant + self.exchange_cookie_assistant = exchange_cookie_assistant + self.explorer_cookie_assistant = explorer_cookie_assistant self.use_secure_connection = use_secure_connection @classmethod @@ -207,7 +143,9 @@ def devnet(cls): chain_id="injective-777", fee_denom="inj", env="devnet", - cookie_assistant=DisabledCookieAssistant(), + chain_cookie_assistant=DisabledCookieAssistant(), + exchange_cookie_assistant=DisabledCookieAssistant(), + explorer_cookie_assistant=DisabledCookieAssistant(), ) @classmethod @@ -226,7 +164,9 @@ def testnet(cls, node="lb"): grpc_exchange_endpoint = "testnet.sentry.exchange.grpc.injective.network:443" grpc_explorer_endpoint = "testnet.sentry.explorer.grpc.injective.network:443" chain_stream_endpoint = "testnet.sentry.chain.stream.injective.network:443" - cookie_assistant = BareMetalLoadBalancedCookieAssistant() + chain_cookie_assistant = BareMetalLoadBalancedCookieAssistant() + exchange_cookie_assistant = BareMetalLoadBalancedCookieAssistant() + explorer_cookie_assistant = BareMetalLoadBalancedCookieAssistant() use_secure_connection = True else: lcd_endpoint = "https://testnet.lcd.injective.network:443" @@ -235,7 +175,9 @@ def testnet(cls, node="lb"): grpc_exchange_endpoint = "testnet.exchange.grpc.injective.network:443" grpc_explorer_endpoint = "testnet.explorer.grpc.injective.network:443" chain_stream_endpoint = "testnet.chain.stream.injective.network:443" - cookie_assistant = DisabledCookieAssistant() + chain_cookie_assistant = DisabledCookieAssistant() + exchange_cookie_assistant = DisabledCookieAssistant() + explorer_cookie_assistant = DisabledCookieAssistant() use_secure_connection = True return cls( @@ -248,7 +190,9 @@ def testnet(cls, node="lb"): chain_id="injective-888", fee_denom="inj", env="testnet", - cookie_assistant=cookie_assistant, + chain_cookie_assistant=chain_cookie_assistant, + exchange_cookie_assistant=exchange_cookie_assistant, + explorer_cookie_assistant=explorer_cookie_assistant, use_secure_connection=use_secure_connection, ) @@ -266,7 +210,9 @@ def mainnet(cls, node="lb"): grpc_exchange_endpoint = "sentry.exchange.grpc.injective.network:443" grpc_explorer_endpoint = "sentry.explorer.grpc.injective.network:443" chain_stream_endpoint = "sentry.chain.stream.injective.network:443" - cookie_assistant = BareMetalLoadBalancedCookieAssistant() + chain_cookie_assistant = BareMetalLoadBalancedCookieAssistant() + exchange_cookie_assistant = BareMetalLoadBalancedCookieAssistant() + explorer_cookie_assistant = BareMetalLoadBalancedCookieAssistant() use_secure_connection = True return cls( @@ -279,7 +225,9 @@ def mainnet(cls, node="lb"): chain_id="injective-1", fee_denom="inj", env="mainnet", - cookie_assistant=cookie_assistant, + chain_cookie_assistant=chain_cookie_assistant, + exchange_cookie_assistant=exchange_cookie_assistant, + explorer_cookie_assistant=explorer_cookie_assistant, use_secure_connection=use_secure_connection, ) @@ -295,7 +243,9 @@ def local(cls): chain_id="injective-1", fee_denom="inj", env="local", - cookie_assistant=DisabledCookieAssistant(), + chain_cookie_assistant=DisabledCookieAssistant(), + exchange_cookie_assistant=DisabledCookieAssistant(), + explorer_cookie_assistant=DisabledCookieAssistant(), use_secure_connection=False, ) @@ -310,10 +260,14 @@ def custom( chain_stream_endpoint, chain_id, env, - cookie_assistant: Optional[CookieAssistant] = None, + chain_cookie_assistant: Optional[CookieAssistant] = None, + exchange_cookie_assistant: Optional[CookieAssistant] = None, + explorer_cookie_assistant: Optional[CookieAssistant] = None, use_secure_connection: bool = False, ): - assistant = cookie_assistant or DisabledCookieAssistant() + chain_assistant = chain_cookie_assistant or DisabledCookieAssistant() + exchange_assistant = exchange_cookie_assistant or DisabledCookieAssistant() + explorer_assistant = explorer_cookie_assistant or DisabledCookieAssistant() return cls( lcd_endpoint=lcd_endpoint, tm_websocket_endpoint=tm_websocket_endpoint, @@ -324,15 +278,11 @@ def custom( chain_id=chain_id, fee_denom="inj", env=env, - cookie_assistant=assistant, + chain_cookie_assistant=chain_assistant, + exchange_cookie_assistant=exchange_assistant, + explorer_cookie_assistant=explorer_assistant, use_secure_connection=use_secure_connection, ) def string(self): return self.env - - async def chain_metadata(self, metadata_query_provider: Callable) -> Tuple[Tuple[str, str]]: - return await self.cookie_assistant.chain_metadata(metadata_query_provider=metadata_query_provider) - - async def exchange_metadata(self, metadata_query_provider: Callable) -> Tuple[Tuple[str, str]]: - return await self.cookie_assistant.exchange_metadata(metadata_query_provider=metadata_query_provider) diff --git a/pyinjective/core/tx/grpc/tendermint_grpc_api.py b/pyinjective/core/tx/grpc/tendermint_grpc_api.py index c6e091c6..352f98c4 100644 --- a/pyinjective/core/tx/grpc/tendermint_grpc_api.py +++ b/pyinjective/core/tx/grpc/tendermint_grpc_api.py @@ -3,6 +3,7 @@ from grpc.aio import Channel from pyinjective.client.model.pagination import PaginationOption +from pyinjective.core.network import CookieAssistant from pyinjective.proto.cosmos.base.tendermint.v1beta1 import ( query_pb2 as tendermint_query, query_pb2_grpc as tendermint_query_grpc, @@ -11,9 +12,9 @@ class TendermintGrpcApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = tendermint_query_grpc.ServiceStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def fetch_node_info(self) -> Dict[str, Any]: request = tendermint_query.GetNodeInfoRequest() diff --git a/pyinjective/core/tx/grpc/tx_grpc_api.py b/pyinjective/core/tx/grpc/tx_grpc_api.py index d984dbf6..28cd7feb 100644 --- a/pyinjective/core/tx/grpc/tx_grpc_api.py +++ b/pyinjective/core/tx/grpc/tx_grpc_api.py @@ -2,14 +2,15 @@ from grpc.aio import Channel +from pyinjective.core.network import CookieAssistant from pyinjective.proto.cosmos.tx.v1beta1 import service_pb2 as tx_service, service_pb2_grpc as tx_service_grpc from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant class TxGrpcApi: - def __init__(self, channel: Channel, metadata_provider: Callable): + def __init__(self, channel: Channel, cookie_assistant: CookieAssistant): self._stub = tx_service_grpc.ServiceStub(channel) - self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider) + self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant) async def simulate(self, tx_bytes: bytes) -> Dict[str, Any]: request = tx_service.SimulateRequest(tx_bytes=tx_bytes) diff --git a/pyinjective/utils/grpc_api_request_assistant.py b/pyinjective/utils/grpc_api_request_assistant.py index 5ed3c5fa..1b278bb9 100644 --- a/pyinjective/utils/grpc_api_request_assistant.py +++ b/pyinjective/utils/grpc_api_request_assistant.py @@ -2,15 +2,20 @@ from google.protobuf import json_format +from pyinjective.core.network import CookieAssistant + class GrpcApiRequestAssistant: - def __init__(self, metadata_provider: Callable): + def __init__(self, cookie_assistant: CookieAssistant): super().__init__() - self._metadata_provider = metadata_provider + self._cookie_assistant = cookie_assistant async def execute_call(self, call: Callable, request) -> Dict[str, Any]: - metadata = await self._metadata_provider() - response = await call(request, metadata=metadata) + metadata = self._cookie_assistant.metadata() + grpc_call = call(request, metadata=metadata) + response = await grpc_call + + await self._cookie_assistant.process_response_metadata(grpc_call=grpc_call) result = json_format.MessageToDict( message=response, diff --git a/pyinjective/utils/grpc_api_stream_assistant.py b/pyinjective/utils/grpc_api_stream_assistant.py index 50092def..e55b52c4 100644 --- a/pyinjective/utils/grpc_api_stream_assistant.py +++ b/pyinjective/utils/grpc_api_stream_assistant.py @@ -4,11 +4,13 @@ from google.protobuf import json_format from grpc import RpcError +from pyinjective.core.network import CookieAssistant + class GrpcApiStreamAssistant: - def __init__(self, metadata_provider: Callable): + def __init__(self, cookie_assistant: CookieAssistant): super().__init__() - self._metadata_provider = metadata_provider + self._cookie_assistant = cookie_assistant async def listen_stream( self, @@ -18,7 +20,7 @@ async def listen_stream( on_end_callback: Optional[Callable] = None, on_status_callback: Optional[Callable] = None, ): - metadata = await self._metadata_provider() + metadata = self._cookie_assistant.metadata() stream = call(request, metadata=metadata) try: diff --git a/tests/client/chain/grpc/test_chain_grpc_auction_api.py b/tests/client/chain/grpc/test_chain_grpc_auction_api.py index 968ee238..9de9c63a 100644 --- a/tests/client/chain/grpc/test_chain_grpc_auction_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_auction_api.py @@ -2,7 +2,7 @@ import pytest from pyinjective.client.chain.grpc.chain_grpc_auction_api import ChainGrpcAuctionApi -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.base.v1beta1 import coin_pb2 as coin_pb from pyinjective.proto.injective.auction.v1beta1 import ( auction_pb2 as auction_pb, @@ -26,11 +26,7 @@ async def test_fetch_module_params( params = auction_pb.Params(auction_period=604800, min_next_bid_increment_rate="2500000000000000") auction_servicer.auction_params.append(auction_query_pb.QueryAuctionParamsResponse(params=params)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuctionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auction_servicer + api = self._api_instance(servicer=auction_servicer) module_params = await api.fetch_module_params() expected_params = {"params": {"auctionPeriod": "604800", "minNextBidIncrementRate": "2500000000000000"}} @@ -55,11 +51,7 @@ async def test_fetch_module_state( ) auction_servicer.module_states.append(auction_query_pb.QueryModuleStateResponse(state=state)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuctionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auction_servicer + api = self._api_instance(servicer=auction_servicer) module_state = await api.fetch_module_state() expected_state = { @@ -92,11 +84,7 @@ async def test_fetch_module_state_when_no_highest_bid_present( ) auction_servicer.module_states.append(auction_query_pb.QueryModuleStateResponse(state=state)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuctionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auction_servicer + api = self._api_instance(servicer=auction_servicer) module_state = await api.fetch_module_state() expected_state = { @@ -136,11 +124,7 @@ async def test_fetch_current_basket( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuctionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auction_servicer + api = self._api_instance(servicer=auction_servicer) current_basket = await api.fetch_current_basket() expected_basket = { @@ -162,5 +146,12 @@ async def test_fetch_current_basket( assert expected_basket == current_basket - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcAuctionApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/chain/grpc/test_chain_grpc_auth_api.py b/tests/client/chain/grpc/test_chain_grpc_auth_api.py index 03032cb1..25507eb2 100644 --- a/tests/client/chain/grpc/test_chain_grpc_auth_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_auth_api.py @@ -6,7 +6,7 @@ from pyinjective.client.chain.grpc.chain_grpc_auth_api import ChainGrpcAuthApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.auth.v1beta1 import auth_pb2 as auth_pb, query_pb2 as auth_query_pb from pyinjective.proto.cosmos.base.query.v1beta1 import pagination_pb2 as pagination_pb from pyinjective.proto.injective.crypto.v1beta1.ethsecp256k1 import keys_pb2 as keys_pb @@ -34,11 +34,7 @@ async def test_fetch_module_params( ) auth_servicer.auth_params.append(auth_query_pb.QueryParamsResponse(params=params)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuthApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auth_servicer + api = self._api_instance(servicer=auth_servicer) module_params = await api.fetch_module_params() expected_params = { @@ -78,11 +74,7 @@ async def test_fetch_account( any_account.Pack(account, type_url_prefix="") auth_servicer.account_responses.append(auth_query_pb.QueryAccountResponse(account=any_account)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuthApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auth_servicer + api = self._api_instance(servicer=auth_servicer) response_account = await api.fetch_account(address="inj1knhahceyp57j5x7xh69p7utegnnnfgxavmahjr") expected_account = { @@ -138,11 +130,7 @@ async def test_fetch_accounts( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuthApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auth_servicer + api = self._api_instance(servicer=auth_servicer) pagination_option = PaginationOption( key="011ab4075a94245dff7338e3042db5b7cc3f42e1", @@ -170,5 +158,12 @@ async def test_fetch_accounts( assert result_pagination.next_key == base64.b64decode(response_pagination["nextKey"]) assert result_pagination.total == int(response_pagination["total"]) - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcAuthApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/chain/grpc/test_chain_grpc_authz_api.py b/tests/client/chain/grpc/test_chain_grpc_authz_api.py index 9d1d5586..315f051f 100644 --- a/tests/client/chain/grpc/test_chain_grpc_authz_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_authz_api.py @@ -4,7 +4,7 @@ from pyinjective.client.chain.grpc.chain_grpc_authz_api import ChainGrpcAuthZApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.authz.v1beta1 import authz_pb2, query_pb2 as authz_query from pyinjective.proto.cosmos.base.query.v1beta1 import pagination_pb2 as pagination_pb from tests.client.chain.grpc.configurable_authz_query_servicer import ConfigurableAuthZQueryServicer @@ -47,11 +47,7 @@ async def test_fetch_grants( count_total=True, ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuthZApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = authz_servicer + api = self._api_instance(servicer=authz_servicer) result_grants = await api.fetch_grants( granter="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku", @@ -109,11 +105,7 @@ async def test_fetch_granter_grants( count_total=True, ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuthZApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = authz_servicer + api = self._api_instance(servicer=authz_servicer) result_grants = await api.fetch_granter_grants( granter="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku", @@ -171,11 +163,7 @@ async def test_fetch_grantee_grants( count_total=True, ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcAuthZApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = authz_servicer + api = self._api_instance(servicer=authz_servicer) result_grants = await api.fetch_grantee_grants( grantee="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r", @@ -198,5 +186,12 @@ async def test_fetch_grantee_grants( assert result_grants == expected_grants - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcAuthZApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/chain/grpc/test_chain_grpc_bank_api.py b/tests/client/chain/grpc/test_chain_grpc_bank_api.py index f2c6cbdd..64b14f95 100644 --- a/tests/client/chain/grpc/test_chain_grpc_bank_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_bank_api.py @@ -5,7 +5,7 @@ from pyinjective.client.chain.grpc.chain_grpc_bank_api import ChainGrpcBankApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.bank.v1beta1 import bank_pb2 as bank_pb, query_pb2 as bank_query_pb from pyinjective.proto.cosmos.base.query.v1beta1 import pagination_pb2 as pagination_pb from pyinjective.proto.cosmos.base.v1beta1 import coin_pb2 as coin_pb @@ -26,11 +26,7 @@ async def test_fetch_module_params( params = bank_pb.Params(default_send_enabled=True) bank_servicer.bank_params.append(bank_query_pb.QueryParamsResponse(params=params)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) module_params = await api.fetch_module_params() expected_params = { @@ -50,11 +46,7 @@ async def test_fetch_balance( balance = coin_pb.Coin(denom="inj", amount="988987297011197594664") bank_servicer.balance_responses.append(bank_query_pb.QueryBalanceResponse(balance=balance)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) bank_balance = await api.fetch_balance( account_address="inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r", denom="inj" @@ -71,11 +63,7 @@ async def test_fetch_balance( balance = coin_pb.Coin(denom="inj", amount="988987297011197594664") bank_servicer.balance_responses.append(bank_query_pb.QueryBalanceResponse(balance=balance)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) bank_balance = await api.fetch_balance( account_address="inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r", denom="inj" @@ -105,11 +93,7 @@ async def test_fetch_balances( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) bank_balances = await api.fetch_balances( account_address="inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r", @@ -137,11 +121,7 @@ async def test_fetch_spendable_balances( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) balances = await api.fetch_spendable_balances( account_address="inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r", @@ -168,11 +148,7 @@ async def test_fetch_spendable_balances_by_denom( bank_query_pb.QuerySpendableBalanceByDenomResponse(balance=first_balance) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) balances = await api.fetch_spendable_balances_by_denom( account_address="inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r", @@ -210,11 +186,7 @@ async def test_fetch_total_supply( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) total_supply = await api.fetch_total_supply() next_key = "factory/inj1vkrp72xd67plcggcfjtjelqa4t5a093xljf2vj/inj1spw6nd0pj3kd3fgjljhuqpc8tv72a9v89myuja" @@ -243,11 +215,7 @@ async def test_fetch_supply_of( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) total_supply = await api.fetch_supply_of(denom=first_supply.denom) expected_supply = {"amount": {"denom": first_supply.denom, "amount": first_supply.amount}} @@ -284,11 +252,7 @@ async def test_fetch_denom_metadata( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) denom_metadata = await api.fetch_denom_metadata(denom=metadata.base) @@ -347,11 +311,7 @@ async def test_fetch_denoms_metadata( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) denoms_metadata = await api.fetch_denoms_metadata( pagination=PaginationOption( @@ -405,11 +365,7 @@ async def test_fetch_denom_owners( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) denoms_metadata = await api.fetch_denom_owners( denom=balance.denom, @@ -460,11 +416,7 @@ async def test_fetch_send_enabled( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcBankApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = bank_servicer + api = self._api_instance(servicer=bank_servicer) denoms_metadata = await api.fetch_send_enabled( denoms=[send_enabled.denom], @@ -489,5 +441,12 @@ async def test_fetch_send_enabled( assert expected_denoms_metadata == denoms_metadata - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcBankApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/chain/grpc/test_chain_grpc_distribution_api.py b/tests/client/chain/grpc/test_chain_grpc_distribution_api.py index 9f8ee9a6..4f54b539 100644 --- a/tests/client/chain/grpc/test_chain_grpc_distribution_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_distribution_api.py @@ -5,7 +5,7 @@ from pyinjective.client.chain.grpc.chain_grpc_distribution_api import ChainGrpcDistributionApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.base.query.v1beta1 import pagination_pb2 as pagination_pb from pyinjective.proto.cosmos.base.v1beta1 import coin_pb2 as coin_pb from pyinjective.proto.cosmos.distribution.v1beta1 import ( @@ -35,11 +35,7 @@ async def test_fetch_module_params( distribution_servicer.distribution_params.append(distribution_query_pb.QueryParamsResponse(params=params)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) module_params = await api.fetch_module_params() expected_params = { @@ -68,11 +64,7 @@ async def test_fetch_validator_distribution_info( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) validator_info = await api.fetch_validator_distribution_info(validator_address=operator) expected_info = { @@ -98,11 +90,7 @@ async def test_fetch_validator_outstanding_rewards( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) validator_rewards = await api.fetch_validator_outstanding_rewards(validator_address=operator) expected_rewards = {"rewards": {"rewards": [{"denom": reward.denom, "amount": reward.amount}]}} @@ -124,11 +112,7 @@ async def test_fetch_validator_commission( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) commission = await api.fetch_validator_commission(validator_address=operator) expected_commission = { @@ -156,11 +140,7 @@ async def test_fetch_validator_slashes( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) slashes = await api.fetch_validator_slashes( validator_address=operator, @@ -198,11 +178,7 @@ async def test_fetch_delegation_rewards( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) rewards = await api.fetch_delegation_rewards( delegator_address=delegator, @@ -233,11 +209,7 @@ async def test_fetch_delegation_total_rewards( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) rewards = await api.fetch_delegation_total_rewards( delegator_address=delegator, @@ -268,11 +240,7 @@ async def test_fetch_delegator_validators( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) validators = await api.fetch_delegator_validators( delegator_address=delegator, @@ -296,11 +264,7 @@ async def test_fetch_delegator_withdraw_address( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) withdraw_address = await api.fetch_delegator_withdraw_address( delegator_address=delegator, @@ -323,16 +287,19 @@ async def test_fetch_community_pool( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcDistributionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = distribution_servicer + api = self._api_instance(servicer=distribution_servicer) community_pool = await api.fetch_community_pool() expected_community_pool = {"pool": [{"denom": coin.denom, "amount": coin.amount}]} assert community_pool == expected_community_pool - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcDistributionApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/chain/grpc/test_chain_grpc_exchange_api.py b/tests/client/chain/grpc/test_chain_grpc_exchange_api.py index 7ff77bbc..66dde459 100644 --- a/tests/client/chain/grpc/test_chain_grpc_exchange_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_exchange_api.py @@ -5,7 +5,7 @@ from pyinjective.client.chain.grpc.chain_grpc_exchange_api import ChainGrpcExchangeApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.base.v1beta1 import coin_pb2 as coin_pb from pyinjective.proto.injective.exchange.v1beta1 import ( exchange_pb2 as exchange_pb, @@ -59,11 +59,7 @@ async def test_fetch_exchange_params( ) exchange_servicer.exchange_params.append(exchange_query_pb.QueryExchangeParamsResponse(params=params)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) module_params = await api.fetch_exchange_params() expected_params = { @@ -123,11 +119,7 @@ async def test_fetch_subaccount_deposits( exchange_query_pb.QuerySubaccountDepositsResponse(deposits={deposit_denom: deposit}) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) deposits = await api.fetch_subaccount_deposits( subaccount_id="0x5303d92e49a619bb29de8fb6f59c0e7589213cc8000000000000000000000001", @@ -158,11 +150,7 @@ async def test_fetch_subaccount_deposit( exchange_query_pb.QuerySubaccountDepositResponse(deposits=deposit) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) deposit_response = await api.fetch_subaccount_deposit( subaccount_id="0x5303d92e49a619bb29de8fb6f59c0e7589213cc8000000000000000000000001", @@ -195,11 +183,7 @@ async def test_fetch_exchange_balances( exchange_query_pb.QueryExchangeBalancesResponse(balances=[balance]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) balances_response = await api.fetch_exchange_balances() expected_balances = { @@ -236,11 +220,7 @@ async def test_fetch_aggregate_volume( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) volume_response = await api.fetch_aggregate_volume(account="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r") expected_volume = { @@ -289,11 +269,7 @@ async def test_fetch_aggregate_volumes( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) volume_response = await api.fetch_aggregate_volumes( accounts=[account_volume.account], @@ -342,11 +318,7 @@ async def test_fetch_aggregate_market_volume( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) volume_response = await api.fetch_aggregate_market_volume( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" @@ -379,11 +351,7 @@ async def test_fetch_aggregate_market_volumes( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) volume_response = await api.fetch_aggregate_market_volumes( market_ids=[market_volume.market_id], @@ -414,11 +382,7 @@ async def test_fetch_denom_decimal( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) denom_decimal = await api.fetch_denom_decimal(denom="inj") expected_decimal = {"decimal": str(decimal)} @@ -440,11 +404,7 @@ async def test_fetch_denom_decimals( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) denom_decimals = await api.fetch_denom_decimals(denoms=[denom_decimal.denom]) expected_decimals = { @@ -481,11 +441,7 @@ async def test_fetch_spot_markets( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) status_string = exchange_pb.MarketStatus.Name(market.status) markets = await api.fetch_spot_markets( @@ -534,11 +490,7 @@ async def test_fetch_spot_market( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) response_market = await api.fetch_spot_market( market_id=market.market_id, @@ -592,11 +544,7 @@ async def test_fetch_full_spot_markets( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) status_string = exchange_pb.MarketStatus.Name(market.status) markets = await api.fetch_full_spot_markets( @@ -662,11 +610,7 @@ async def test_fetch_full_spot_market( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) status_string = exchange_pb.MarketStatus.Name(market.status) market_response = await api.fetch_full_spot_market( @@ -717,11 +661,7 @@ async def test_fetch_spot_orderbook( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orderbook = await api.fetch_spot_orderbook( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe", @@ -765,11 +705,7 @@ async def test_fetch_trader_spot_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_trader_spot_orders( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe", @@ -807,11 +743,7 @@ async def test_fetch_account_address_spot_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_account_address_spot_orders( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe", @@ -849,11 +781,7 @@ async def test_fetch_spot_orders_by_hashes( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_spot_orders_by_hashes( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe", @@ -904,11 +832,7 @@ async def test_fetch_subaccount_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_subaccount_orders( subaccount_id="0x5303d92e49a619bb29de8fb6f59c0e7589213cc8000000000000000000000001", @@ -957,11 +881,7 @@ async def test_fetch_trader_spot_transient_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_trader_spot_transient_orders( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe", @@ -993,11 +913,7 @@ async def test_fetch_spot_mid_price_and_tob( ) exchange_servicer.spot_mid_price_and_tob_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) prices = await api.fetch_spot_mid_price_and_tob( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe", @@ -1022,11 +938,7 @@ async def test_fetch_derivative_mid_price_and_tob( ) exchange_servicer.derivative_mid_price_and_tob_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) prices = await api.fetch_derivative_mid_price_and_tob( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe", @@ -1059,11 +971,7 @@ async def test_fetch_derivative_orderbook( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orderbook = await api.fetch_derivative_orderbook( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -1106,11 +1014,7 @@ async def test_fetch_trader_derivative_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_trader_derivative_orders( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -1150,11 +1054,7 @@ async def test_fetch_account_address_derivative_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_account_address_derivative_orders( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -1194,11 +1094,7 @@ async def test_fetch_derivative_orders_by_hashes( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_derivative_orders_by_hashes( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -1239,11 +1135,7 @@ async def test_fetch_trader_derivative_transient_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_trader_derivative_transient_orders( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -1320,11 +1212,7 @@ async def test_fetch_derivative_markets( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) status_string = exchange_pb.MarketStatus.Name(market.status) markets = await api.fetch_derivative_markets( @@ -1434,11 +1322,7 @@ async def test_fetch_derivative_market( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) status_string = exchange_pb.MarketStatus.Name(market.status) market_response = await api.fetch_derivative_market( @@ -1500,11 +1384,7 @@ async def test_fetch_derivative_market_address( ) exchange_servicer.derivative_market_address_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) address = await api.fetch_derivative_market_address( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -1524,11 +1404,7 @@ async def test_fetch_subaccount_trade_nonce( response = exchange_query_pb.QuerySubaccountTradeNonceResponse(nonce=1234567879) exchange_servicer.subaccount_trade_nonce_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) nonce = await api.fetch_subaccount_trade_nonce( subaccount_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20000000000000000000000000", @@ -1560,11 +1436,7 @@ async def test_fetch_positions( exchange_query_pb.QueryPositionsResponse(state=[derivative_position]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) positions = await api.fetch_positions() expected_positions = { @@ -1606,11 +1478,7 @@ async def test_fetch_subaccount_positions( exchange_query_pb.QuerySubaccountPositionsResponse(state=[derivative_position]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) positions = await api.fetch_subaccount_positions(subaccount_id=derivative_position.subaccount_id) expected_positions = { @@ -1649,11 +1517,7 @@ async def test_fetch_subaccount_position_in_market( exchange_query_pb.QuerySubaccountPositionInMarketResponse(state=position) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) position_response = await api.fetch_subaccount_position_in_market( subaccount_id=subaccount_id, @@ -1689,11 +1553,7 @@ async def test_fetch_subaccount_effective_position_in_market( exchange_query_pb.QuerySubaccountEffectivePositionInMarketResponse(state=effective_position) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) position_response = await api.fetch_subaccount_effective_position_in_market( subaccount_id=subaccount_id, @@ -1726,11 +1586,7 @@ async def test_fetch_perpetual_market_info( exchange_query_pb.QueryPerpetualMarketInfoResponse(info=perpetual_market_info) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) market_info = await api.fetch_perpetual_market_info(market_id=perpetual_market_info.market_id) expected_market_info = { @@ -1761,11 +1617,7 @@ async def test_fetch_expiry_futures_market_info( exchange_query_pb.QueryExpiryFuturesMarketInfoResponse(info=expiry_futures_market_info) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) market_info = await api.fetch_expiry_futures_market_info(market_id=expiry_futures_market_info.market_id) expected_market_info = { @@ -1794,11 +1646,7 @@ async def test_fetch_perpetual_market_funding( exchange_query_pb.QueryPerpetualMarketFundingResponse(state=perpetual_market_funding) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) funding = await api.fetch_perpetual_market_funding( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" @@ -1835,11 +1683,7 @@ async def test_fetch_subaccount_order_metadata( exchange_query_pb.QuerySubaccountOrderMetadataResponse(metadata=[subaccount_order_metadata]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) metadata_response = await api.fetch_subaccount_order_metadata( subaccount_id="0x5303d92e49a619bb29de8fb6f59c0e7589213cc8000000000000000000000001" @@ -1872,11 +1716,7 @@ async def test_fetch_trade_reward_points( response = exchange_query_pb.QueryTradeRewardPointsResponse(account_trade_reward_points=[points]) exchange_servicer.trade_reward_points_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) trade_reward_points = await api.fetch_trade_reward_points( accounts=["inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"], @@ -1895,11 +1735,7 @@ async def test_fetch_pending_trade_reward_points( response = exchange_query_pb.QueryTradeRewardPointsResponse(account_trade_reward_points=[points]) exchange_servicer.pending_trade_reward_points_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) trade_reward_points = await api.fetch_pending_trade_reward_points( accounts=["inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"], @@ -1961,11 +1797,7 @@ async def test_fetch_trade_reward_campaign( ) exchange_servicer.trade_reward_campaign_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) trade_reward_campaign = await api.fetch_trade_reward_campaign() expected_campaign = { @@ -2044,11 +1876,7 @@ async def test_fetch_fee_discount_account_info( ) exchange_servicer.fee_discount_account_info_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) fee_discount = await api.fetch_fee_discount_account_info(account="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r") expected_fee_discount = { @@ -2091,11 +1919,7 @@ async def test_fetch_fee_discount_schedule( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) schedule = await api.fetch_fee_discount_schedule() expected_schedule = { @@ -2137,11 +1961,7 @@ async def test_fetch_balance_mismatches( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) mismatches = await api.fetch_balance_mismatches(dust_factor=20) expected_mismatches = { @@ -2178,11 +1998,7 @@ async def test_fetch_balance_with_balance_holds( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) balance = await api.fetch_balance_with_balance_holds() expected_balance = { @@ -2214,11 +2030,7 @@ async def test_fetch_fee_discount_tier_statistics( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) statistics = await api.fetch_fee_discount_tier_statistics() expected_statistics = { @@ -2249,11 +2061,7 @@ async def test_fetch_mito_vault_infos( ) exchange_servicer.mito_vault_infos_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) mito_vaults = await api.fetch_mito_vault_infos() expected_mito_vaults = { @@ -2277,11 +2085,7 @@ async def test_fetch_market_id_from_vault( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) market_id_response = await api.fetch_market_id_from_vault( vault_address="inj1zlh5sqevkfphtwnu9cul8p89vseme2eqt0snn9" @@ -2312,11 +2116,7 @@ async def test_fetch_historical_trade_records( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) records = await api.fetch_historical_trade_records(market_id=trade_record.market_id) expected_records = { @@ -2346,11 +2146,7 @@ async def test_fetch_is_opted_out_of_rewards( ) exchange_servicer.is_opted_out_of_rewards_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) is_opted_out = await api.fetch_is_opted_out_of_rewards(account="inj1zlh5sqevkfphtwnu9cul8p89vseme2eqt0snn9") expected_is_opted_out = { @@ -2369,11 +2165,7 @@ async def test_fetch_opted_out_of_rewards_accounts( ) exchange_servicer.opted_out_of_rewards_accounts_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) opted_out = await api.fetch_opted_out_of_rewards_accounts() expected_opted_out = { @@ -2408,11 +2200,7 @@ async def test_fetch_market_volatility( ) exchange_servicer.market_volatility_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) volatility = await api.fetch_market_volatility( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -2474,11 +2262,7 @@ async def test_fetch_binary_options_markets( ) exchange_servicer.binary_options_markets_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) markets = await api.fetch_binary_options_markets(status="Active") expected_markets = { @@ -2524,11 +2308,7 @@ async def test_fetch_trader_derivative_conditional_orders( response = exchange_query_pb.QueryTraderDerivativeConditionalOrdersResponse(orders=[order]) exchange_servicer.trader_derivative_conditional_orders_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) orders = await api.fetch_trader_derivative_conditional_orders( subaccount_id="0x5303d92e49a619bb29de8fb6f59c0e7589213cc8000000000000000000000001", @@ -2560,11 +2340,7 @@ async def test_fetch_market_atomic_execution_fee_multiplier( ) exchange_servicer.market_atomic_execution_fee_multiplier_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcExchangeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = exchange_servicer + api = self._api_instance(servicer=exchange_servicer) multiplier = await api.fetch_market_atomic_execution_fee_multiplier( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", @@ -2575,5 +2351,12 @@ async def test_fetch_market_atomic_execution_fee_multiplier( assert multiplier == expected_multiplier - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcExchangeApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/chain/grpc/test_chain_grpc_token_factory_api.py b/tests/client/chain/grpc/test_chain_grpc_token_factory_api.py index 418dfb35..18cad1f2 100644 --- a/tests/client/chain/grpc/test_chain_grpc_token_factory_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_token_factory_api.py @@ -2,7 +2,7 @@ import pytest from pyinjective.client.chain.grpc.chain_grpc_token_factory_api import ChainGrpcTokenFactoryApi -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.base.v1beta1 import coin_pb2 as coin_pb from pyinjective.proto.injective.tokenfactory.v1beta1 import ( authorityMetadata_pb2 as token_factory_authority_metadata_pb, @@ -30,11 +30,7 @@ async def test_fetch_module_params( ) token_factory_query_servicer.params_responses.append(token_factory_query_pb.QueryParamsResponse(params=params)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcTokenFactoryApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._query_stub = token_factory_query_servicer + api = self._api_instance(servicer=token_factory_query_servicer) module_params = await api.fetch_module_params() expected_params = { @@ -61,11 +57,7 @@ async def test_fetch_denom_authority_metadata( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcTokenFactoryApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._query_stub = token_factory_query_servicer + api = self._api_instance(servicer=token_factory_query_servicer) metadata = await api.fetch_denom_authority_metadata( creator=authority_metadata.admin, @@ -89,11 +81,7 @@ async def test_fetch_denoms_from_creator( token_factory_query_pb.QueryDenomsFromCreatorResponse(denoms=[denom]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcTokenFactoryApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._query_stub = token_factory_query_servicer + api = self._api_instance(servicer=token_factory_query_servicer) denoms = await api.fetch_denoms_from_creator(creator="inj1ady3s7whq30l4fx8sj3x6muv5mx4dfdlcpv8n7") expected_denoms = {"denoms": [denom]} @@ -126,11 +114,7 @@ async def test_fetch_tokenfactory_module_state( token_factory_query_pb.QueryModuleStateResponse(state=state) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcTokenFactoryApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._query_stub = token_factory_query_servicer + api = self._api_instance(servicer=token_factory_query_servicer) state = await api.fetch_tokenfactory_module_state() expected_state = { @@ -155,5 +139,12 @@ async def test_fetch_tokenfactory_module_state( assert state == expected_state - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcTokenFactoryApi(channel=channel, cookie_assistant=cookie_assistant) + api._query_stub = servicer + + return api diff --git a/tests/client/chain/grpc/test_chain_grpc_wasm_api.py b/tests/client/chain/grpc/test_chain_grpc_wasm_api.py index 254f382f..a8ebf1af 100644 --- a/tests/client/chain/grpc/test_chain_grpc_wasm_api.py +++ b/tests/client/chain/grpc/test_chain_grpc_wasm_api.py @@ -6,7 +6,7 @@ from pyinjective.client.chain.grpc.chain_grpc_wasm_api import ChainGrpcWasmApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.base.query.v1beta1 import pagination_pb2 as pagination_pb from pyinjective.proto.cosmwasm.wasm.v1 import query_pb2 as wasm_query_pb, types_pb2 as wasm_types_pb from tests.client.chain.grpc.configurable_wasm_query_servicer import ConfigurableWasmQueryServicer @@ -33,11 +33,7 @@ async def test_fetch_module_params( ) wasm_servicer.params_responses.append(wasm_query_pb.QueryParamsResponse(params=params)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) module_params = await api.fetch_module_params() expected_params = { @@ -77,11 +73,7 @@ async def test_fetch_contract_info( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) info = await api.fetch_contract_info(address=address) expected_contract_info = { @@ -130,11 +122,7 @@ async def test_fetch_contract_history( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) info = await api.fetch_contract_history( address="inj18pp4vjwucpgg4nw3rr4wh4zyjg9ct5t8v9wqgj", @@ -183,11 +171,7 @@ async def test_fetch_contracts_by_code( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) info = await api.fetch_contracts_by_code( code_id=3770, @@ -231,11 +215,7 @@ async def test_fetch_all_contracts_state( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) info = await api.fetch_all_contracts_state( address="inj1z4l7jc8dj3y9484aqcrmf6y8mcctvkmm9zkf7n", @@ -266,11 +246,7 @@ async def test_fetch_raw_contract_state( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) info = await api.fetch_raw_contract_state( address="inj1z4l7jc8dj3y9484aqcrmf6y8mcctvkmm9zkf7n", @@ -294,11 +270,7 @@ async def test_fetch_smart_contract_state( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) info = await api.fetch_smart_contract_state( address="inj1z4l7jc8dj3y9484aqcrmf6y8mcctvkmm9zkf7n", @@ -333,11 +305,7 @@ async def test_fetch_code( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) info = await api.fetch_code(code_id=code_info_response.code_id) expected_contract_info = { @@ -384,11 +352,7 @@ async def test_fetch_codes( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) codes = await api.fetch_codes( pagination=PaginationOption( @@ -436,11 +400,7 @@ async def test_fetch_pinned_codes( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) codes = await api.fetch_pinned_codes( pagination=PaginationOption( @@ -478,11 +438,7 @@ async def test_contracts_by_creator( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = ChainGrpcWasmApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = wasm_servicer + api = self._api_instance(servicer=wasm_servicer) codes = await api.fetch_contracts_by_creator( creator_address="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku", @@ -501,5 +457,12 @@ async def test_contracts_by_creator( assert codes == expected_codes - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcWasmApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/chain/stream_grpc/test_chain_grpc_chain_stream.py b/tests/client/chain/stream_grpc/test_chain_grpc_chain_stream.py index 8b932770..39513fdc 100644 --- a/tests/client/chain/stream_grpc/test_chain_grpc_chain_stream.py +++ b/tests/client/chain/stream_grpc/test_chain_grpc_chain_stream.py @@ -6,7 +6,7 @@ from pyinjective.client.chain.grpc_stream.chain_grpc_chain_stream import ChainGrpcChainStream from pyinjective.composer import Composer -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.cosmos.base.v1beta1 import coin_pb2 as coin_pb from pyinjective.proto.injective.exchange.v1beta1 import exchange_pb2 as exchange_pb from pyinjective.proto.injective.stream.v1beta1 import query_pb2 as chain_stream_pb @@ -194,10 +194,7 @@ async def test_stream( network = Network.devnet() composer = Composer(network=network.string()) - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = ChainGrpcChainStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = chain_stream_servicer + api = self._api_instance(servicer=chain_stream_servicer) events = asyncio.Queue() end_event = asyncio.Event() @@ -408,5 +405,12 @@ async def test_stream( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = ChainGrpcChainStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_account_api.py b/tests/client/indexer/grpc/test_indexer_grpc_account_api.py index 895e35c0..85443837 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_account_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_account_api.py @@ -3,7 +3,7 @@ from pyinjective.client.indexer.grpc.indexer_grpc_account_api import IndexerGrpcAccountApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_accounts_rpc_pb2 as exchange_accounts_pb from tests.client.indexer.configurable_account_query_servicer import ConfigurableAccountQueryServicer @@ -34,11 +34,7 @@ async def test_fetch_portfolio( ) account_servicer.portfolio_responses.append(exchange_accounts_pb.PortfolioResponse(portfolio=portfolio)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) account_address = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku" result_portfolio = await api.fetch_portfolio(account_address=account_address) @@ -84,11 +80,7 @@ async def test_order_states( exchange_accounts_pb.OrderStatesResponse(spot_order_states=[order_state]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_order_states = await api.fetch_order_states(spot_order_hashes=[order_state.order_hash]) expected_order_states = { @@ -124,11 +116,7 @@ async def test_subaccounts_list( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_subaccounts_list = await api.fetch_subaccounts_list(address="testAddress") expected_subaccounts_list = { @@ -156,11 +144,7 @@ async def test_subaccount_balances_list( exchange_accounts_pb.SubaccountBalancesListResponse(balances=[balance]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_subaccount_balances_list = await api.fetch_subaccount_balances_list( subaccount_id=balance.subaccount_id, denoms=[balance.denom] @@ -200,11 +184,7 @@ async def test_subaccount_balance( exchange_accounts_pb.SubaccountBalanceEndpointResponse(balance=balance) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_subaccount_balance = await api.fetch_subaccount_balance( subaccount_id=balance.subaccount_id, @@ -249,11 +229,7 @@ async def test_subaccount_history( exchange_accounts_pb.SubaccountHistoryResponse(transfers=[transfer], paging=paging) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_subaccount_history = await api.fetch_subaccount_history( subaccount_id=transfer.dst_subaccount_id, @@ -297,11 +273,7 @@ async def test_subaccount_order_summary( exchange_accounts_pb.SubaccountOrderSummaryResponse(spot_orders_total=0, derivative_orders_total=20) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_subaccount_order_summary = await api.fetch_subaccount_order_summary( subaccount_id="0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000", @@ -330,11 +302,7 @@ async def test_fetch_rewards( account_servicer.rewards_responses.append(exchange_accounts_pb.RewardsResponse(rewards=[reward])) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_rewards = await api.fetch_rewards(account_address=reward.account_address, epoch=1) expected_rewards = { @@ -372,11 +340,7 @@ async def test_fetch_rewards( account_servicer.rewards_responses.append(exchange_accounts_pb.RewardsResponse(rewards=[reward])) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) result_rewards = await api.fetch_rewards(account_address=reward.account_address, epoch=1) expected_rewards = { @@ -396,5 +360,12 @@ async def test_fetch_rewards( assert result_rewards == expected_rewards - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcAccountApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_auction_api.py b/tests/client/indexer/grpc/test_indexer_grpc_auction_api.py index 8be68ddb..f9d372c7 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_auction_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_auction_api.py @@ -2,7 +2,7 @@ import pytest from pyinjective.client.indexer.grpc.indexer_grpc_auction_api import IndexerGrpcAuctionApi -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_auction_rpc_pb2 as exchange_auction_pb from tests.client.indexer.configurable_auction_query_servicer import ConfigurableAuctionQueryServicer @@ -44,11 +44,7 @@ async def test_fetch_auction( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAuctionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auction_servicer + api = self._api_instance(servicer=auction_servicer) result_auction = await api.fetch_auction(round=auction.round) expected_auction = { @@ -90,11 +86,7 @@ async def test_fetch_auctions( auction_servicer.auctions_responses.append(exchange_auction_pb.AuctionsResponse(auctions=[auction])) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAuctionApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auction_servicer + api = self._api_instance(servicer=auction_servicer) result_auctions = await api.fetch_auctions() expected_auctions = { @@ -117,5 +109,12 @@ async def test_fetch_auctions( assert result_auctions == expected_auctions - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcAuctionApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_derivative_api.py b/tests/client/indexer/grpc/test_indexer_grpc_derivative_api.py index 932596ca..c5ae19e0 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_derivative_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_derivative_api.py @@ -3,7 +3,7 @@ from pyinjective.client.indexer.grpc.indexer_grpc_derivative_api import IndexerGrpcDerivativeApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_derivative_exchange_rpc_pb2 as exchange_derivative_pb from tests.client.indexer.configurable_derivative_query_servicer import ConfigurableDerivativeQueryServicer @@ -67,11 +67,7 @@ async def test_fetch_markets( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_markets = await api.fetch_markets( market_statuses=[market.market_status], @@ -174,11 +170,7 @@ async def test_fetch_market( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_market = await api.fetch_market(market_id=market.market_id) expected_market = { @@ -263,11 +255,7 @@ async def test_fetch_binary_options_markets( exchange_derivative_pb.BinaryOptionsMarketsResponse(markets=[market], paging=paging) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_markets = await api.fetch_binary_options_markets( market_status=market.market_status, @@ -355,11 +343,7 @@ async def test_fetch_binary_options_market( exchange_derivative_pb.BinaryOptionsMarketResponse(market=market) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_markets = await api.fetch_binary_options_market(market_id=market.market_id) expected_markets = { @@ -422,11 +406,7 @@ async def test_fetch_orderbook_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orderbook = await api.fetch_orderbook_v2( market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" @@ -488,11 +468,7 @@ async def test_fetch_orderbooks_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orderbook = await api.fetch_orderbooks_v2(market_ids=[single_orderbook.market_id]) expected_orderbook = { @@ -563,11 +539,7 @@ async def test_fetch_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_orders( market_ids=[order.market_id], @@ -654,11 +626,7 @@ async def test_fetch_positions( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_positions( market_ids=[position.market_id], @@ -729,11 +697,7 @@ async def test_fetch_positions_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_positions_v2( market_ids=[position.market_id], @@ -798,11 +762,7 @@ async def test_fetch_liquidable_positions( exchange_derivative_pb.LiquidablePositionsResponse(positions=[position]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_liquidable_positions( market_id=position.market_id, @@ -854,11 +814,7 @@ async def test_fetch_funding_payments( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_funding_payments( market_ids=[payment.market_id], @@ -910,11 +866,7 @@ async def test_fetch_funding_rates( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_funding_rates( market_id=funding_rate.market_id, @@ -981,11 +933,7 @@ async def test_fetch_trades( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_trades = await api.fetch_trades( market_ids=[trade.market_id], @@ -1077,11 +1025,7 @@ async def test_fetch_subaccount_orders_list( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_subaccount_orders_list( subaccount_id=order.subaccount_id, @@ -1163,11 +1107,7 @@ async def test_fetch_subaccount_trades_list( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_trades = await api.fetch_subaccount_trades_list( subaccount_id=trade.subaccount_id, @@ -1245,11 +1185,7 @@ async def test_fetch_orders_history( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_orders = await api.fetch_orders_history( subaccount_id=order.subaccount_id, @@ -1344,11 +1280,7 @@ async def test_fetch_trades_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) result_trades = await api.fetch_trades_v2( market_ids=[trade.market_id], @@ -1400,5 +1332,12 @@ async def test_fetch_trades_v2( assert result_trades == expected_trades - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcDerivativeApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_explorer_api.py b/tests/client/indexer/grpc/test_indexer_grpc_explorer_api.py index 3572174d..faf4364a 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_explorer_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_explorer_api.py @@ -5,7 +5,7 @@ from pyinjective.client.indexer.grpc.indexer_grpc_explorer_api import IndexerGrpcExplorerApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_explorer_rpc_pb2 as exchange_explorer_pb from tests.client.indexer.configurable_explorer_query_servicer import ConfigurableExplorerQueryServicer @@ -90,11 +90,7 @@ async def test_fetch_account_txs( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_txs = await api.fetch_account_txs( address="inj1phd706jqzd9wznkk5hgsfkrc8jqxv0kmlj0kex", @@ -245,11 +241,7 @@ async def test_fetch_contract_txs( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_contract_txs = await api.fetch_contract_txs( address="inj1phd706jqzd9wznkk5hgsfkrc8jqxv0kmlj0kex", @@ -345,11 +337,7 @@ async def test_fetch_blocks( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_blocks = await api.fetch_blocks( before=221419, @@ -418,11 +406,7 @@ async def test_fetch_block( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_block = await api.fetch_block(block_id=str(block_info.height)) expected_block = { @@ -496,11 +480,7 @@ async def test_fetch_validators( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_validators = await api.fetch_validators() expected_validators = { @@ -581,11 +561,7 @@ async def test_fetch_validator( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_validator = await api.fetch_validator(address=validator.operator_address) expected_validator = { @@ -645,11 +621,7 @@ async def test_fetch_validator_uptime( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_validator = await api.fetch_validator_uptime(address="injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5") expected_validator = { @@ -716,11 +688,7 @@ async def test_fetch_txs( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_txs = await api.fetch_txs( before=221439, @@ -837,11 +805,7 @@ async def test_fetch_tx_by_hash( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_tx = await api.fetch_tx_by_tx_hash(tx_hash=tx_data.hash) expected_tx = { @@ -921,11 +885,7 @@ async def test_fetch_peggy_deposit_txs( exchange_explorer_pb.GetPeggyDepositTxsResponse(field=[tx_data]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_tx = await api.fetch_peggy_deposit_txs( sender=tx_data.sender, @@ -985,11 +945,7 @@ async def test_fetch_peggy_withdrawal_txs( exchange_explorer_pb.GetPeggyWithdrawalTxsResponse(field=[tx_data]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_tx = await api.fetch_peggy_withdrawal_txs( sender=tx_data.sender, @@ -1056,11 +1012,7 @@ async def test_fetch_ibc_transfer_txs( exchange_explorer_pb.GetIBCTransferTxsResponse(field=[tx_data]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_tx = await api.fetch_ibc_transfer_txs( sender=tx_data.sender, @@ -1135,11 +1087,7 @@ async def test_fetch_wasm_codes( exchange_explorer_pb.GetWasmCodesResponse(paging=paging, data=[wasm_code]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_wasm_codes = await api.fetch_wasm_codes( from_number=1, @@ -1214,11 +1162,7 @@ async def test_fetch_wasm_code_by_id( explorer_servicer.wasm_code_by_id_responses.append(wasm_code) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_wasm_code = await api.fetch_wasm_code_by_id(code_id=wasm_code.code_id) expected_wasm_code = { @@ -1285,11 +1229,7 @@ async def test_fetch_wasm_contracts( exchange_explorer_pb.GetWasmContractsResponse(paging=paging, data=[wasm_contract]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_wasm_contracts = await api.fetch_wasm_contracts( code_id=wasm_contract.code_id, @@ -1368,11 +1308,7 @@ async def test_fetch_wasm_contract_by_address( explorer_servicer.wasm_contract_by_address_responses.append(wasm_contract) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_wasm_contract = await api.fetch_wasm_contract_by_address(address=wasm_contract.address) expected_wasm_contract = { @@ -1429,11 +1365,7 @@ async def test_fetch_cw20_balance( exchange_explorer_pb.GetCw20BalanceResponse(field=[wasm_balance]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_wasm_contract = await api.fetch_cw20_balance( address=wasm_balance.account, @@ -1483,11 +1415,7 @@ async def test_fetch_relayers( explorer_servicer.relayers_responses.append(exchange_explorer_pb.RelayersResponse(field=[relayers])) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_wasm_contract = await api.fetch_relayers( market_ids=[relayers.market_id], @@ -1532,11 +1460,7 @@ async def test_fetch_bank_transfers( exchange_explorer_pb.GetBankTransfersResponse(paging=paging, data=[bank_transfer]) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) result_transfers = await api.fetch_bank_transfers( senders=[bank_transfer.sender], @@ -1578,5 +1502,12 @@ async def test_fetch_bank_transfers( assert result_transfers == expected_transfers - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcExplorerApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_insurance_api.py b/tests/client/indexer/grpc/test_indexer_grpc_insurance_api.py index 2499b7db..27e3ee9f 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_insurance_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_insurance_api.py @@ -2,7 +2,7 @@ import pytest from pyinjective.client.indexer.grpc.indexer_grpc_insurance_api import IndexerGrpcInsuranceApi -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_insurance_rpc_pb2 as exchange_insurance_pb from tests.client.indexer.configurable_insurance_query_servicer import ConfigurableInsuranceQueryServicer @@ -38,11 +38,7 @@ async def test_fetch_insurance_funds( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcInsuranceApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = insurance_servicer + api = self._api_instance(servicer=insurance_servicer) result_insurance_list = await api.fetch_insurance_funds() expected_insurance_list = { @@ -89,11 +85,7 @@ async def test_fetch_redemptions( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcInsuranceApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = insurance_servicer + api = self._api_instance(servicer=insurance_servicer) result_insurance_list = await api.fetch_redemptions( address=redemption_schedule.redeemer, @@ -119,5 +111,12 @@ async def test_fetch_redemptions( assert result_insurance_list == expected_insurance_list - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcInsuranceApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_meta_api.py b/tests/client/indexer/grpc/test_indexer_grpc_meta_api.py index e9fe8d94..b7ee7378 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_meta_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_meta_api.py @@ -2,7 +2,7 @@ import pytest from pyinjective.client.indexer.grpc.indexer_grpc_meta_api import IndexerGrpcMetaApi -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_meta_rpc_pb2 as exchange_meta_pb from tests.client.indexer.configurable_meta_query_servicer import ConfigurableMetaQueryServicer @@ -20,11 +20,7 @@ async def test_fetch_portfolio( ): meta_servicer.ping_responses.append(exchange_meta_pb.PingResponse()) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcMetaApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = meta_servicer + api = self._api_instance(servicer=meta_servicer) result_ping = await api.fetch_ping() expected_ping = {} @@ -48,11 +44,7 @@ async def test_fetch_version( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcMetaApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = meta_servicer + api = self._api_instance(servicer=meta_servicer) result_version = await api.fetch_version() expected_version = {"build": build, "version": version} @@ -78,11 +70,7 @@ async def test_fetch_info( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcMetaApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = meta_servicer + api = self._api_instance(servicer=meta_servicer) result_info = await api.fetch_info() expected_info = { @@ -95,5 +83,12 @@ async def test_fetch_info( assert result_info == expected_info - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcMetaApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_oracle_api.py b/tests/client/indexer/grpc/test_indexer_grpc_oracle_api.py index 25c39733..96ac10d7 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_oracle_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_oracle_api.py @@ -2,7 +2,7 @@ import pytest from pyinjective.client.indexer.grpc.indexer_grpc_oracle_api import IndexerGrpcOracleApi -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_oracle_rpc_pb2 as exchange_oracle_pb from tests.client.indexer.configurable_oracle_query_servicer import ConfigurableOracleQueryServicer @@ -32,11 +32,7 @@ async def test_fetch_oracle_list( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcOracleApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = oracle_servicer + api = self._api_instance(servicer=oracle_servicer) result_oracle_list = await api.fetch_oracle_list() expected_oracle_list = { @@ -66,11 +62,7 @@ async def test_fetch_oracle_price( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcOracleApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = oracle_servicer + api = self._api_instance(servicer=oracle_servicer) result_oracle_list = await api.fetch_oracle_price( base_symbol="Gold", @@ -82,5 +74,12 @@ async def test_fetch_oracle_price( assert result_oracle_list == expected_oracle_list - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcOracleApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_portfolio_api.py b/tests/client/indexer/grpc/test_indexer_grpc_portfolio_api.py index ad88d127..45d5ea62 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_portfolio_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_portfolio_api.py @@ -2,7 +2,7 @@ import pytest from pyinjective.client.indexer.grpc.indexer_grpc_portfolio_api import IndexerGrpcPortfolioApi -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_portfolio_rpc_pb2 as exchange_portfolio_pb from tests.client.indexer.configurable_portfolio_query_servicer import ConfigurablePortfolioQueryServicer @@ -63,11 +63,7 @@ async def test_fetch_account_portfolio( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcPortfolioApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = portfolio_servicer + api = self._api_instance(servicer=portfolio_servicer) result_auction = await api.fetch_account_portfolio(account_address=portfolio.account_address) expected_auction = { @@ -144,11 +140,7 @@ async def test_fetch_account_portfolio_balances( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcPortfolioApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = portfolio_servicer + api = self._api_instance(servicer=portfolio_servicer) result_auction = await api.fetch_account_portfolio_balances(account_address=portfolio.account_address) expected_auction = { @@ -175,5 +167,12 @@ async def test_fetch_account_portfolio_balances( assert result_auction == expected_auction - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcPortfolioApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/grpc/test_indexer_grpc_spot_api.py b/tests/client/indexer/grpc/test_indexer_grpc_spot_api.py index 01b8fda9..095ca9a1 100644 --- a/tests/client/indexer/grpc/test_indexer_grpc_spot_api.py +++ b/tests/client/indexer/grpc/test_indexer_grpc_spot_api.py @@ -3,7 +3,7 @@ from pyinjective.client.indexer.grpc.indexer_grpc_spot_api import IndexerGrpcSpotApi from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_spot_exchange_rpc_pb2 as exchange_spot_pb from tests.client.indexer.configurable_spot_query_servicer import ConfigurableSpotQueryServicer @@ -57,11 +57,7 @@ async def test_fetch_markets( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_markets = await api.fetch_markets( market_statuses=[market.market_status], @@ -146,11 +142,7 @@ async def test_fetch_market( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_market = await api.fetch_market(market_id=market.market_id) expected_market = { @@ -215,11 +207,7 @@ async def test_fetch_orderbook_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_orderbook = await api.fetch_orderbook_v2( market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" @@ -281,11 +269,7 @@ async def test_fetch_orderbooks_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_orderbook = await api.fetch_orderbooks_v2(market_ids=[single_orderbook.market_id]) expected_orderbook = { @@ -348,11 +332,7 @@ async def test_fetch_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_orders = await api.fetch_orders( market_ids=[order.market_id], @@ -435,11 +415,7 @@ async def test_fetch_trades( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_trades = await api.fetch_trades( market_ids=[trade.market_id], @@ -521,11 +497,7 @@ async def test_fetch_subaccount_orders_list( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_orders = await api.fetch_subaccount_orders_list( subaccount_id=order.subaccount_id, @@ -597,11 +569,7 @@ async def test_fetch_subaccount_trades_list( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_trades = await api.fetch_subaccount_trades_list( subaccount_id=trade.subaccount_id, @@ -672,11 +640,7 @@ async def test_fetch_orders_history( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_orders = await api.fetch_orders_history( subaccount_id=order.subaccount_id, @@ -759,11 +723,7 @@ async def test_fetch_atomic_swap_history( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_history = await api.fetch_atomic_swap_history( address=atomic_swap.sender, @@ -838,11 +798,7 @@ async def test_fetch_trades_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) result_trades = await api.fetch_trades_v2( market_ids=[trade.market_id], @@ -892,5 +848,12 @@ async def test_fetch_trades_v2( assert result_trades == expected_trades - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcSpotApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_account_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_account_stream.py index f5579bee..925e85c8 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_account_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_account_stream.py @@ -4,7 +4,7 @@ import pytest from pyinjective.client.indexer.grpc_stream.indexer_grpc_account_stream import IndexerGrpcAccountStream -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_accounts_rpc_pb2 as exchange_accounts_pb from tests.client.indexer.configurable_account_query_servicer import ConfigurableAccountQueryServicer @@ -34,11 +34,7 @@ async def test_fetch_portfolio( exchange_accounts_pb.StreamSubaccountBalanceResponse(balance=balance, timestamp=1672218001897) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAccountStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = account_servicer + api = self._api_instance(servicer=account_servicer) balance_updates = asyncio.Queue() end_event = asyncio.Event() @@ -74,5 +70,12 @@ async def test_fetch_portfolio( assert first_balance_update == expected_balance_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcAccountStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_auction_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_auction_stream.py index 8c88d717..ef76134e 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_auction_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_auction_stream.py @@ -4,7 +4,7 @@ import pytest from pyinjective.client.indexer.grpc_stream.indexer_grpc_auction_stream import IndexerGrpcAuctionStream -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_auction_rpc_pb2 as exchange_auction_pb from tests.client.indexer.configurable_auction_query_servicer import ConfigurableAuctionQueryServicer @@ -29,11 +29,7 @@ async def test_stream_oracle_prices_by_markets( exchange_auction_pb.StreamBidsResponse(bidder=bidder, bid_amount=amount, round=round, timestamp=timestamp) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcAuctionStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = auction_servicer + api = self._api_instance(servicer=auction_servicer) bid_updates = asyncio.Queue() end_event = asyncio.Event() @@ -61,5 +57,12 @@ async def test_stream_oracle_prices_by_markets( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcAuctionStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_derivative_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_derivative_stream.py index ffa83c9a..fb9e9827 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_derivative_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_derivative_stream.py @@ -5,7 +5,7 @@ from pyinjective.client.indexer.grpc_stream.indexer_grpc_derivative_stream import IndexerGrpcDerivativeStream from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_derivative_exchange_rpc_pb2 as exchange_derivative_pb from tests.client.indexer.configurable_derivative_query_servicer import ConfigurableDerivativeQueryServicer @@ -74,11 +74,7 @@ async def test_stream_market( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) market_updates = asyncio.Queue() end_event = asyncio.Event() @@ -178,11 +174,7 @@ async def test_stream_orderbook_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) orderbook_updates = asyncio.Queue() end_event = asyncio.Event() @@ -266,11 +258,7 @@ async def test_stream_orderbook_update( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) orderbook_updates = asyncio.Queue() end_event = asyncio.Event() @@ -348,11 +336,7 @@ async def test_stream_positions( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) positions = asyncio.Queue() end_event = asyncio.Event() @@ -434,11 +418,7 @@ async def test_stream_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) orders_updates = asyncio.Queue() end_event = asyncio.Event() @@ -542,11 +522,7 @@ async def test_stream_trades( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) trade_updates = asyncio.Queue() end_event = asyncio.Event() @@ -646,11 +622,7 @@ async def test_stream_orders_history( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) orders_history_updates = asyncio.Queue() end_event = asyncio.Event() @@ -744,11 +716,7 @@ async def test_stream_trades_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcDerivativeStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = derivative_servicer + api = self._api_instance(servicer=derivative_servicer) trade_updates = asyncio.Queue() end_event = asyncio.Event() @@ -808,5 +776,12 @@ async def test_stream_trades_v2( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcDerivativeStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_explorer_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_explorer_stream.py index 98eed906..b960076a 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_explorer_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_explorer_stream.py @@ -4,7 +4,7 @@ import pytest from pyinjective.client.indexer.grpc_stream.indexer_grpc_explorer_stream import IndexerGrpcExplorerStream -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_explorer_rpc_pb2 as exchange_explorer_pb from tests.client.indexer.configurable_explorer_query_servicer import ConfigurableExplorerQueryServicer @@ -41,11 +41,7 @@ async def test_stream_txs( explorer_servicer.stream_txs_responses.append(tx_data) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) txs_updates = asyncio.Queue() end_event = asyncio.Event() @@ -97,11 +93,7 @@ async def test_stream_blocks( explorer_servicer.stream_blocks_responses.append(block_info) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcExplorerStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = explorer_servicer + api = self._api_instance(servicer=explorer_servicer) blocks_updates = asyncio.Queue() end_event = asyncio.Event() @@ -134,5 +126,12 @@ async def test_stream_blocks( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcExplorerStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_meta_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_meta_stream.py index 2a003c62..0e476e76 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_meta_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_meta_stream.py @@ -4,7 +4,7 @@ import pytest from pyinjective.client.indexer.grpc_stream.indexer_grpc_meta_stream import IndexerGrpcMetaStream -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_meta_rpc_pb2 as exchange_meta_pb from tests.client.indexer.configurable_meta_query_servicer import ConfigurableMetaQueryServicer @@ -32,11 +32,7 @@ async def test_fetch_portfolio( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcMetaStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = meta_servicer + api = self._api_instance(servicer=meta_servicer) keepalive_updates = asyncio.Queue() end_event = asyncio.Event() @@ -59,5 +55,12 @@ async def test_fetch_portfolio( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcMetaStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_oracle_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_oracle_stream.py index 3389948a..2e60d84a 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_oracle_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_oracle_stream.py @@ -4,7 +4,7 @@ import pytest from pyinjective.client.indexer.grpc_stream.indexer_grpc_oracle_stream import IndexerGrpcOracleStream -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_oracle_rpc_pb2 as exchange_oracle_pb from tests.client.indexer.configurable_oracle_query_servicer import ConfigurableOracleQueryServicer @@ -30,11 +30,7 @@ async def test_stream_oracle_prices( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcOracleStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = oracle_servicer + api = self._api_instance(servicer=oracle_servicer) price_updates = asyncio.Queue() end_event = asyncio.Event() @@ -77,11 +73,7 @@ async def test_stream_oracle_prices_by_markets( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcOracleStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = oracle_servicer + api = self._api_instance(servicer=oracle_servicer) price_updates = asyncio.Queue() end_event = asyncio.Event() @@ -105,5 +97,12 @@ async def test_stream_oracle_prices_by_markets( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcOracleStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_portfolio_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_portfolio_stream.py index 2f09ed40..f992fb9b 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_portfolio_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_portfolio_stream.py @@ -4,7 +4,7 @@ import pytest from pyinjective.client.indexer.grpc_stream.indexer_grpc_portfolio_stream import IndexerGrpcPortfolioStream -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_portfolio_rpc_pb2 as exchange_portfolio_pb from tests.client.indexer.configurable_portfolio_query_servicer import ConfigurablePortfolioQueryServicer @@ -36,11 +36,7 @@ async def test_stream_account_portfolio( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcPortfolioStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = portfolio_servicer + api = self._api_instance(servicer=portfolio_servicer) portfolio_updates = asyncio.Queue() end_event = asyncio.Event() @@ -72,5 +68,12 @@ async def test_stream_account_portfolio( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcPortfolioStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/client/indexer/stream_grpc/test_indexer_grpc_spot_stream.py b/tests/client/indexer/stream_grpc/test_indexer_grpc_spot_stream.py index 6b55ce88..be13f590 100644 --- a/tests/client/indexer/stream_grpc/test_indexer_grpc_spot_stream.py +++ b/tests/client/indexer/stream_grpc/test_indexer_grpc_spot_stream.py @@ -5,7 +5,7 @@ from pyinjective.client.indexer.grpc_stream.indexer_grpc_spot_stream import IndexerGrpcSpotStream from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.proto.exchange import injective_spot_exchange_rpc_pb2 as exchange_spot_pb from tests.client.indexer.configurable_spot_query_servicer import ConfigurableSpotQueryServicer @@ -64,11 +64,7 @@ async def test_stream_markets( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) market_updates = asyncio.Queue() end_event = asyncio.Event() @@ -159,11 +155,7 @@ async def test_stream_orderbook_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) orderbook_updates = asyncio.Queue() end_event = asyncio.Event() @@ -247,11 +239,7 @@ async def test_stream_orderbook_update( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) orderbook_updates = asyncio.Queue() end_event = asyncio.Event() @@ -333,11 +321,7 @@ async def test_stream_orders( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) orders_updates = asyncio.Queue() end_event = asyncio.Event() @@ -429,11 +413,7 @@ async def test_stream_trades( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) trade_updates = asyncio.Queue() end_event = asyncio.Event() @@ -526,11 +506,7 @@ async def test_stream_orders_history( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) orders_history_updates = asyncio.Queue() end_event = asyncio.Event() @@ -617,11 +593,7 @@ async def test_stream_trades_v2( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_exchange_endpoint) - - api = IndexerGrpcSpotStream(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = spot_servicer + api = self._api_instance(servicer=spot_servicer) trade_updates = asyncio.Queue() end_event = asyncio.Event() @@ -679,5 +651,12 @@ async def test_stream_trades_v2( assert first_update == expected_update assert end_event.is_set() - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = IndexerGrpcSpotStream(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/core/test_network.py b/tests/core/test_network.py index 479f7027..d226645e 100644 --- a/tests/core/test_network.py +++ b/tests/core/test_network.py @@ -1,105 +1,94 @@ -import pytest +import datetime -from pyinjective.core.network import BareMetalLoadBalancedCookieAssistant, KubernetesLoadBalancedCookieAssistant +import pytest +from grpc.aio import Metadata +from pyinjective.core.network import ( + BareMetalLoadBalancedCookieAssistant, + DisabledCookieAssistant, + ExpiringCookieAssistant, +) -class TestBareMetalLoadBalancedCookieAssistant: - @pytest.mark.asyncio - async def test_chain_metadata(self): - assistant = BareMetalLoadBalancedCookieAssistant() - dummy_metadata = [("set-cookie", "expected_cookie")] - async def dummy_metadata_provider(): - return dummy_metadata +class DummyCall: + def __init__(self, metadata: Metadata): + self._metadata = metadata - metadata = await assistant.chain_metadata(metadata_query_provider=dummy_metadata_provider) - expected_metadata = (("cookie", "expected_cookie"),) + async def initial_metadata(self): + return self._metadata - assert expected_metadata == metadata +class TestBareMetalLoadBalancedCookieAssistant: @pytest.mark.asyncio - async def test_chain_metadata_fails_when_cookie_info_not_included_in_server_response(self): + async def test_metadata_access(self): assistant = BareMetalLoadBalancedCookieAssistant() - dummy_metadata = [("invalid_key", "invalid_value")] - - async def dummy_metadata_provider(): - return dummy_metadata - with pytest.raises(RuntimeError, match=f"Error fetching chain cookie ({dummy_metadata})"): - await assistant.chain_metadata(metadata_query_provider=dummy_metadata_provider) + assert assistant.metadata() == Metadata() - @pytest.mark.asyncio - async def test_exchange_metadata(self): - assistant = BareMetalLoadBalancedCookieAssistant() - dummy_metadata = [("set-cookie", "expected_cookie")] + response_cookie = "lb=205989dfdbf02c2b4b9ed656ff8a081cb146d66797f69eefb4aee61ad5f13d4e; Path=/" + metadata = Metadata( + ("alt-svc", 'h3=":443"; ma=2592000'), + ("server", "Caddy"), + ("set-cookie", response_cookie), + ("x-cosmos-block-height", "23624674"), + ("date", "Mon, 18 Mar 2024 18:09:42 GMT"), + ) - async def dummy_metadata_provider(): - return dummy_metadata + grpc_call = DummyCall(metadata=metadata) + await assistant.process_response_metadata(grpc_call=grpc_call) - metadata = await assistant.exchange_metadata(metadata_query_provider=dummy_metadata_provider) - expected_metadata = (("cookie", "expected_cookie"),) + assert assistant.metadata() == Metadata(("cookie", response_cookie)) - assert expected_metadata == metadata +class TestExpiringCookieAssistant: @pytest.mark.asyncio - async def test_exchange_metadata_is_none_when_cookie_info_not_included_in_server_response(self): - assistant = BareMetalLoadBalancedCookieAssistant() - dummy_metadata = [("invalid_key", "invalid_value")] + async def test_cookie_expiration(self): + time_format = "%a, %d-%b-%Y %H:%M:%S %Z" + gmt_timezone = datetime.timezone(offset=datetime.timedelta(seconds=0), name="GMT") - async def dummy_metadata_provider(): - return dummy_metadata + assistant = ExpiringCookieAssistant( + expiration_time_keys_sequence=["grpc-cookie", "expires"], + time_format=time_format, + ) - metadata = await assistant.exchange_metadata(metadata_query_provider=dummy_metadata_provider) + future_time = datetime.datetime.now(tz=gmt_timezone) + datetime.timedelta(hours=1) + formatted_time = future_time.strftime(time_format) + cookie_value = ( + f"grpc-cookie=bb3a543cef4d9182587375c26556c15f; Expires={formatted_time};" + f" Max-Age=172800; Path=/; Secure; HttpOnly" + ) - assert metadata is None + metadata = Metadata(("set-cookie", cookie_value)) + grpc_call = DummyCall(metadata=metadata) + await assistant.process_response_metadata(grpc_call=grpc_call) -class TestKubernetesLoadBalancedCookieAssistant: - @pytest.mark.asyncio - async def test_chain_metadata(self): - assistant = KubernetesLoadBalancedCookieAssistant() - dummy_metadata = [("set-cookie", "expected_cookie")] + assert assistant.cookie() == cookie_value - async def dummy_metadata_provider(): - return dummy_metadata + past_time = datetime.datetime.now(tz=gmt_timezone) + datetime.timedelta(hours=-1) + formatted_time = past_time.strftime(time_format) + cookie_value = ( + f"grpc-cookie=bb3a543cef4d9182587375c26556c15f; Expires={formatted_time};" + f" Max-Age=172800; Path=/; Secure; HttpOnly" + ) - metadata = await assistant.chain_metadata(metadata_query_provider=dummy_metadata_provider) - expected_metadata = (("cookie", "expected_cookie"),) + metadata = Metadata(("set-cookie", cookie_value)) + grpc_call = DummyCall(metadata=metadata) - assert expected_metadata == metadata + await assistant.process_response_metadata(grpc_call=grpc_call) - @pytest.mark.asyncio - async def test_chain_metadata_fails_when_cookie_info_not_included_in_server_response(self): - assistant = KubernetesLoadBalancedCookieAssistant() - dummy_metadata = [("invalid_key", "invalid_value")] + assert assistant.cookie() is None - async def dummy_metadata_provider(): - return dummy_metadata + def test_instance_creation_for_kubernetes_server(self): + assistant = ExpiringCookieAssistant.for_kubernetes_public_server() - with pytest.raises(RuntimeError, match=f"Error fetching chain cookie ({dummy_metadata})"): - await assistant.chain_metadata(metadata_query_provider=dummy_metadata_provider) - - @pytest.mark.asyncio - async def test_exchange_metadata(self): - assistant = KubernetesLoadBalancedCookieAssistant() - dummy_metadata = [("set-cookie", "expected_cookie")] + assert ["grpc-cookie", "expires"] == assistant._expiration_time_keys_sequence + assert "%a, %d-%b-%Y %H:%M:%S %Z" == assistant._time_format - async def dummy_metadata_provider(): - return dummy_metadata - - metadata = await assistant.exchange_metadata(metadata_query_provider=dummy_metadata_provider) - expected_metadata = (("cookie", "expected_cookie"),) - - assert expected_metadata == metadata +class TestDisabledCookieAssistant: @pytest.mark.asyncio - async def test_exchange_metadata_is_none_when_cookie_info_not_included_in_server_response(self): - assistant = KubernetesLoadBalancedCookieAssistant() - dummy_metadata = [("invalid_key", "invalid_value")] - - async def dummy_metadata_provider(): - return dummy_metadata - - metadata = await assistant.exchange_metadata(metadata_query_provider=dummy_metadata_provider) + async def test_metadata_access(self): + assistant = DisabledCookieAssistant() - assert metadata is None + assert assistant.metadata() == Metadata() diff --git a/tests/core/tx/grpc/test_tendermint_grpc_api.py b/tests/core/tx/grpc/test_tendermint_grpc_api.py index ed9333f6..26496823 100644 --- a/tests/core/tx/grpc/test_tendermint_grpc_api.py +++ b/tests/core/tx/grpc/test_tendermint_grpc_api.py @@ -4,7 +4,7 @@ import pytest from pyinjective.client.model.pagination import PaginationOption -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.core.tx.grpc.tendermint_grpc_api import TendermintGrpcApi from pyinjective.proto.cosmos.base.query.v1beta1 import pagination_pb2 as pagination_pb from pyinjective.proto.cosmos.base.tendermint.v1beta1 import query_pb2 as tendermint_query @@ -66,11 +66,7 @@ async def test_fetch_node_info( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TendermintGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tendermint_servicer + api = self._api_instance(servicer=tendermint_servicer) result_info = await api.fetch_node_info() expected_info = { @@ -122,11 +118,7 @@ async def test_fetch_syncing( tendermint_servicer.get_syncing_responses.append(response) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TendermintGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tendermint_servicer + api = self._api_instance(servicer=tendermint_servicer) result_syncing = await api.fetch_syncing() expected_syncing = { @@ -154,11 +146,7 @@ async def test_fetch_latest_block( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TendermintGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tendermint_servicer + api = self._api_instance(servicer=tendermint_servicer) result_block = await api.fetch_latest_block() expected_block = { @@ -192,11 +180,7 @@ async def test_fetch_block_by_height( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TendermintGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tendermint_servicer + api = self._api_instance(servicer=tendermint_servicer) result_block = await api.fetch_block_by_height(height=1) expected_block = { @@ -234,11 +218,7 @@ async def test_fetch_latest_validator_set( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TendermintGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tendermint_servicer + api = self._api_instance(servicer=tendermint_servicer) result_validator_set = await api.fetch_latest_validator_set() expected_validator_set = { @@ -281,11 +261,7 @@ async def test_fetch_validator_set_by_height( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TendermintGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tendermint_servicer + api = self._api_instance(servicer=tendermint_servicer) pagination_option = PaginationOption( skip=10, @@ -349,11 +325,7 @@ async def test_abci_query( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TendermintGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tendermint_servicer + api = self._api_instance(servicer=tendermint_servicer) result_validator_set = await api.abci_query( data="query data".encode(), @@ -383,5 +355,12 @@ async def test_abci_query( assert result_validator_set == expected_validator_set - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = TendermintGrpcApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api diff --git a/tests/core/tx/grpc/test_tx_grpc_api.py b/tests/core/tx/grpc/test_tx_grpc_api.py index 84b62817..b98dfbdb 100644 --- a/tests/core/tx/grpc/test_tx_grpc_api.py +++ b/tests/core/tx/grpc/test_tx_grpc_api.py @@ -4,7 +4,7 @@ import pytest from google.protobuf import any_pb2 -from pyinjective.core.network import Network +from pyinjective.core.network import DisabledCookieAssistant, Network from pyinjective.core.tx.grpc.tx_grpc_api import TxGrpcApi from pyinjective.proto.cosmos.base.abci.v1beta1 import abci_pb2 as abci_type from pyinjective.proto.cosmos.base.v1beta1 import coin_pb2 as coin_pb @@ -37,11 +37,7 @@ async def test_simulate( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TxGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tx_servicer + api = self._api_instance(servicer=tx_servicer) result_simulate = await api.simulate(tx_bytes="Transaction content".encode()) expected_simulate = { @@ -100,11 +96,7 @@ async def test_get_tx( tx_servicer.get_tx_responses.append(tx_service.GetTxResponse(tx=transaction, tx_response=transaction_response)) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TxGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tx_servicer + api = self._api_instance(servicer=tx_servicer) result_tx = await api.fetch_tx(hash=transaction_response.txhash) expected_tx = { @@ -174,11 +166,7 @@ async def test_broadcast( ) ) - network = Network.devnet() - channel = grpc.aio.insecure_channel(network.grpc_endpoint) - - api = TxGrpcApi(channel=channel, metadata_provider=lambda: self._dummy_metadata_provider()) - api._stub = tx_servicer + api = self._api_instance(servicer=tx_servicer) result_broadcast = await api.broadcast( tx_bytes="Transaction content".encode(), @@ -203,5 +191,12 @@ async def test_broadcast( assert result_broadcast == expected_broadcast - async def _dummy_metadata_provider(self): - return None + def _api_instance(self, servicer): + network = Network.devnet() + channel = grpc.aio.insecure_channel(network.grpc_endpoint) + cookie_assistant = DisabledCookieAssistant() + + api = TxGrpcApi(channel=channel, cookie_assistant=cookie_assistant) + api._stub = servicer + + return api