diff --git a/ape_infura/provider.py b/ape_infura/provider.py index b67250d..ad1cac0 100644 --- a/ape_infura/provider.py +++ b/ape_infura/provider.py @@ -122,18 +122,21 @@ def ws_uri(self) -> Optional[str]: def connection_str(self) -> str: return self.uri + def connect(self): + session = _get_session() + http_provider = HTTPProvider(self.uri, session=session) + self._web3 = _create_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 - def connect(self): - session = _get_session() - session.auth = ("", api_secret) - - http_provider = HTTPProvider(self.uri, session=session) - self._web3 = Web3(http_provider) - # 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 c27e5c2..4b51118 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -7,7 +7,7 @@ from web3.exceptions import ExtraDataLengthError from web3.middleware import geth_poa_middleware -from ape_infura.provider import _WEBSOCKET_CAPABLE_NETWORKS, Infura +from ape_infura.provider import _WEBSOCKET_CAPABLE_NETWORKS, Infura, _get_session def test_infura_http(provider): @@ -111,8 +111,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"]