Skip to content

Commit 646a211

Browse files
committed
refactor: use metho
1 parent 8bf1e9f commit 646a211

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

ape_infura/provider.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,21 @@ def ws_uri(self) -> Optional[str]:
114114
def connection_str(self) -> str:
115115
return self.uri
116116

117-
@property
118-
def _needs_poa_middleware(self) -> bool:
119-
if self._web3 is None:
120-
return False
121-
122117
def connect(self):
123118
session = _get_session()
124119
session.auth = ("", api_secret)
125-
126120
http_provider = HTTPProvider(self.uri, session=session)
127-
self._web3 = Web3(http_provider)
121+
self._web3 = _create_web3(http_provider)
122+
123+
if self._needs_poa_middleware:
124+
self._web3.middleware_onion.inject(geth_poa_middleware, layer=0)
125+
126+
self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy)
127+
128+
@property
129+
def _needs_poa_middleware(self) -> bool:
130+
if self._web3 is None:
131+
return False
128132

129133
# Any chain that *began* as PoA needs the middleware for pre-merge blocks
130134
optimism = (10, 420)

tests/test_provider.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import pytest
44
import websocket # type: ignore
5-
from ape import networks
65
from ape.utils import ZERO_ADDRESS
76
from web3.exceptions import ExtraDataLengthError
87
from web3.middleware import geth_poa_middleware
98

10-
from ape_infura.provider import _WEBSOCKET_CAPABLE_ECOSYSTEMS, Infura
9+
from ape_infura.provider import _WEBSOCKET_CAPABLE_ECOSYSTEMS, Infura, _get_session
1110

1211

1312
def test_infura_http(provider):
@@ -111,8 +110,6 @@ def test_dynamic_poa_check(mocker):
111110

112111
def test_api_secret():
113112
os.environ["WEB3_INFURA_PROJECT_SECRET"] = "123"
114-
mainnet = networks.ethereum.mainnet
115-
infura = Infura(name="infura", network=mainnet)
116113
session = _get_session()
117114
assert session.auth == ("", "123")
118115
del os.environ["WEB3_INFURA_PROJECT_SECRET"]

0 commit comments

Comments
 (0)