Skip to content

Commit

Permalink
fix: add PoA middleware where needed (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 24, 2022
1 parent 28b328b commit ceb358d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.10.0
hooks:
- id: black
name: black

- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v0.982
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests]
Expand Down
4 changes: 3 additions & 1 deletion ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def connection_str(self) -> str:
def connect(self):
self._web3 = Web3(HTTPProvider(self.uri))
try:
if self._web3.eth.chain_id in (4, 5, 42):
# optimism:mainnet, optimism:goerli, polygon:mainnet, or polygon:mumbai
if self._web3.eth.chain_id in (10, 420, 137, 80001):
self._web3.middleware_onion.inject(geth_poa_middleware, layer=0)

self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy)
except Exception as err:
raise ProviderError(f"Failed to connect to Alchemy.\n{repr(err)}") from err
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
],
"lint": [
"black>=22.6.0", # auto-formatter and linter
"mypy>=0.971", # Static type analyzer
"black>=22.10.0", # auto-formatter and linter
"mypy>=0.982", # Static type analyzer
"types-requests", # NOTE: Needed due to mypy typeshed
"flake8>=4.0.1", # Style linter
"flake8>=5.0.4", # Style linter
"flake8-breakpoint>=1.1.0", # detect breakpoints left in code
"flake8-print>=4.0.0", # detect print statements left in code
"isort>=5.10.1", # Import sorting linter
Expand Down
1 change: 1 addition & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ def test_alchemy(ecosystem, network):
with network_cls.use_provider("alchemy") as provider:
assert isinstance(provider, Alchemy)
assert provider.get_balance(ZERO_ADDRESS) > 0
assert provider.get_block("latest")

0 comments on commit ceb358d

Please sign in to comment.