Skip to content

Commit

Permalink
Apply @vepkenez suggestion, Building MockInfuraClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
KPrasch committed Jul 28, 2019
1 parent 8cb6ce5 commit 07ebe5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion nucypher/blockchain/eth/clients.py
Expand Up @@ -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

Expand Down Expand Up @@ -331,6 +331,7 @@ def unlock_account(self, address, password):
def sync(self, *args, **kwargs):
return True


class EthereumTesterClient(Web3Client):

is_local = True
Expand Down
15 changes: 9 additions & 6 deletions tests/blockchain/eth/clients/test_mocked_clients.py
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 07ebe5b

Please sign in to comment.