From 07ebe5b29e8455f7325b99680c5700994a4a27e1 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Tue, 16 Jul 2019 20:20:31 -0700 Subject: [PATCH] Apply @vepkenez suggestion, Building MockInfuraClient. --- nucypher/blockchain/eth/clients.py | 3 ++- .../blockchain/eth/clients/test_mocked_clients.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/nucypher/blockchain/eth/clients.py b/nucypher/blockchain/eth/clients.py index 3d354d0aad3..5132ce277c1 100644 --- a/nucypher/blockchain/eth/clients.py +++ b/nucypher/blockchain/eth/clients.py @@ -267,7 +267,7 @@ class GethClient(Web3Client): @classmethod def _get_variant(cls, w3): - if 'infura' in w3.provider.endpoint_uri: + if 'infura' in getattr(w3.provider, 'endpoint_uri', ''): return InfuraClient return cls @@ -331,6 +331,7 @@ def unlock_account(self, address, password): def sync(self, *args, **kwargs): return True + class EthereumTesterClient(Web3Client): is_local = True diff --git a/tests/blockchain/eth/clients/test_mocked_clients.py b/tests/blockchain/eth/clients/test_mocked_clients.py index 4fa1f0851e4..f013f08a769 100644 --- a/tests/blockchain/eth/clients/test_mocked_clients.py +++ b/tests/blockchain/eth/clients/test_mocked_clients.py @@ -72,14 +72,17 @@ def attach_middleware(self): pass +class InfuraTestClient(BlockchainInterfaceTestBase): + + def _attach_provider(self, *args, **kwargs) -> None: + super()._attach_provider(provider=MockInfuraProvider()) + + class GethClientTestBlockchain(BlockchainInterfaceTestBase): def _attach_provider(self, *args, **kwargs) -> None: super()._attach_provider(provider=MockGethProvider()) - def _get_infura_provider(self): - return MockInfuraProvider() - @property def is_local(self): return int(self.w3.net.version) not in PUBLIC_CHAINS @@ -112,9 +115,9 @@ def test_geth_web3_client(): def test_infura_web3_client(): - interface = GethClientTestBlockchain( - provider_uri='infura://1234567890987654321abcdef' - ) + interface = InfuraTestClient(provider_uri='infura://1234567890987654321abcdef') + interface.connect(fetch_registry=False, sync_now=False) + assert isinstance(interface.client, InfuraClient) assert interface.node_technology == 'Geth' assert interface.node_version == 'v1.8.23-omnibus-2ad89aaa'