Remove is_connected in favour of is_initialized for clarity.

v7.4.1-hotfix^2
derekpierre 2024-09-04 07:55:35 -04:00
parent 3b0710d611
commit 646e2f5b11
No known key found for this signature in database
2 changed files with 9 additions and 9 deletions

View File

@ -253,7 +253,7 @@ class BlockchainInterface:
self.gas_strategy = gas_strategy or self.DEFAULT_GAS_STRATEGY self.gas_strategy = gas_strategy or self.DEFAULT_GAS_STRATEGY
self.max_gas_price = max_gas_price self.max_gas_price = max_gas_price
self.__is_connected = False self.__is_initialized = False
def __repr__(self): def __repr__(self):
r = "{name}({uri})".format(name=self.__class__.__name__, uri=self.endpoint) r = "{name}({uri})".format(name=self.__class__.__name__, uri=self.endpoint)
@ -263,8 +263,8 @@ class BlockchainInterface:
return self.client.get_blocktime() return self.client.get_blocktime()
@property @property
def is_connected(self) -> bool: def is_initialized(self) -> bool:
return self.__is_connected return self.__is_initialized
@classmethod @classmethod
def get_gas_strategy(cls, gas_strategy: Union[str, Callable] = None) -> Callable: def get_gas_strategy(cls, gas_strategy: Union[str, Callable] = None) -> Callable:
@ -307,7 +307,7 @@ class BlockchainInterface:
# self.log.debug(f"Gas strategy currently reports a gas price of {gwei_gas_price} gwei.") # self.log.debug(f"Gas strategy currently reports a gas price of {gwei_gas_price} gwei.")
def connect(self): def connect(self):
if self.__is_connected: if self.__is_initialized:
# safety check - connect was already previously called # safety check - connect was already previously called
return return
@ -358,8 +358,8 @@ class BlockchainInterface:
f"Blockchain: {client.chain_name} (chain_id={chain_id}, block_num={latest_block_number})" f"Blockchain: {client.chain_name} (chain_id={chain_id}, block_num={latest_block_number})"
) )
self.__is_connected = True self.__is_initialized = True
return self.__is_connected return self.__is_initialized
@property @property
def provider(self) -> BaseProvider: def provider(self) -> BaseProvider:
@ -844,7 +844,7 @@ class BlockchainInterfaceFactory:
# Connect and Sync # Connect and Sync
interface, emitter = cached_interface interface, emitter = cached_interface
if not interface.is_connected: if not interface.is_initialized:
interface.connect() interface.connect()
return interface return interface

View File

@ -136,11 +136,11 @@ def test_connect_handle_connectivity_issues(mocker):
endpoint="https://public-node.io:8445" endpoint="https://public-node.io:8445"
) )
assert not blockchain_interface.is_connected assert not blockchain_interface.is_initialized
# connect() is called with no connectivity issues and executes successfully # connect() is called with no connectivity issues and executes successfully
blockchain_interface.connect() blockchain_interface.connect()
assert blockchain_interface.is_connected assert blockchain_interface.is_initialized
# poa, retry, simplecache # poa, retry, simplecache
current_middlewares = blockchain_interface.w3.middleware_onion.middlewares current_middlewares = blockchain_interface.w3.middleware_onion.middlewares