diff --git a/ape_infura/provider.py b/ape_infura/provider.py index f84c324..46103b4 100644 --- a/ape_infura/provider.py +++ b/ape_infura/provider.py @@ -114,18 +114,22 @@ def ws_uri(self) -> Optional[str]: def connection_str(self) -> str: return self.uri - @property - def _needs_poa_middleware(self) -> bool: - if self._web3 is None: - return False - def connect(self): session = _get_session() session.auth = ("", api_secret) - http_provider = HTTPProvider(self.uri, session=session) self._web3 = Web3(http_provider) + if self._needs_poa_middleware: + self._web3.middleware_onion.inject(geth_poa_middleware, layer=0) + + self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy) + + @property + def _needs_poa_middleware(self) -> bool: + if self._web3 is None: + return False + # Any chain that *began* as PoA needs the middleware for pre-merge blocks optimism = (10, 420) polygon = (137, 80001, 80002) diff --git a/tests/test_provider.py b/tests/test_provider.py index b0d9bc1..b2134e8 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -2,12 +2,11 @@ import pytest import websocket # type: ignore -from ape import networks from ape.utils import ZERO_ADDRESS from web3.exceptions import ExtraDataLengthError from web3.middleware import geth_poa_middleware -from ape_infura.provider import _WEBSOCKET_CAPABLE_ECOSYSTEMS, Infura +from ape_infura.provider import _WEBSOCKET_CAPABLE_ECOSYSTEMS, Infura, _get_session def test_infura_http(provider): @@ -111,8 +110,6 @@ def test_dynamic_poa_check(mocker): def test_api_secret(): os.environ["WEB3_INFURA_PROJECT_SECRET"] = "123" - mainnet = networks.ethereum.mainnet - infura = Infura(name="infura", network=mainnet) session = _get_session() assert session.auth == ("", "123") del os.environ["WEB3_INFURA_PROJECT_SECRET"]