Skip to content

Commit

Permalink
feat: upgrade web3
Browse files Browse the repository at this point in the history
  • Loading branch information
NotPeopling2day committed Dec 4, 2024
1 parent c27abb5 commit 9bfa182
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions ape_infura/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from web3.exceptions import ContractLogicError as Web3ContractLogicError
from web3.exceptions import ExtraDataLengthError
from web3.gas_strategies.rpc import rpc_gas_price_strategy
from web3.middleware import geth_poa_middleware
try:
from web3.middleware import ExtraDataToPOAMiddleware # type: ignore
except ImportError:
from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore
from web3.middleware.validation import MAX_EXTRADATA_LENGTH

_API_KEY_ENVIRONMENT_VARIABLE_NAMES = ("WEB3_INFURA_PROJECT_ID", "WEB3_INFURA_API_KEY")
Expand Down Expand Up @@ -135,7 +138,7 @@ def connect(self):
self._web3 = _create_web3(http_provider)

if self._needs_poa_middleware:
self._web3.middleware_onion.inject(geth_poa_middleware, layer=0)
self._web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)

self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy)

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
include_package_data=True,
install_requires=[
"eth-ape>=0.8.1,<0.9",
"web3>=7.6.0,<8",
"requests>=2.32.3,<3",
],
python_requires=">=3.9,<4",
extras_require=extras_require,
Expand Down
7 changes: 5 additions & 2 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import websocket # type: ignore
from ape import networks
from web3.exceptions import ExtraDataLengthError
from web3.middleware import geth_poa_middleware
try:
from web3.middleware import ExtraDataToPOAMiddleware # type: ignore
except ImportError:
from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore

from ape_infura.provider import _WEBSOCKET_CAPABLE_NETWORKS, Infura, _get_session

Expand Down Expand Up @@ -116,7 +119,7 @@ def test_dynamic_poa_check(mocker):
patch = mocker.patch("ape_infura.provider._create_web3")
patch.return_value = mock_web3
infura.connect()
mock_web3.middleware_onion.inject.assert_called_once_with(geth_poa_middleware, layer=0)
mock_web3.middleware_onion.inject.assert_called_once_with(ExtraDataToPOAMiddleware, layer=0)


def test_api_secret():
Expand Down

0 comments on commit 9bfa182

Please sign in to comment.