diff --git a/src/ape_ethereum/provider.py b/src/ape_ethereum/provider.py index e488db70bb..a9f2807a81 100644 --- a/src/ape_ethereum/provider.py +++ b/src/ape_ethereum/provider.py @@ -1120,7 +1120,7 @@ def make_request(self, rpc: str, parameters: Optional[Iterable] = None) -> Any: if ( "does not exist/is not available" in str(message) - or re.match(r"Method .*?not found", message) + or re.match(r"[m|M]ethod .*?not found", message) or message.startswith("Unknown RPC Endpoint") or "RPC Endpoint has not been implemented" in message ): diff --git a/tests/functional/geth/test_provider.py b/tests/functional/geth/test_provider.py index fb16a03b94..43b68b6e93 100644 --- a/tests/functional/geth/test_provider.py +++ b/tests/functional/geth/test_provider.py @@ -7,7 +7,7 @@ from eth_utils import keccak, to_hex from evmchains import PUBLIC_CHAIN_META from hexbytes import HexBytes -from web3 import AutoProvider +from web3 import AutoProvider, Web3 from web3.exceptions import ContractLogicError as Web3ContractLogicError from web3.exceptions import ExtraDataLengthError from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware @@ -605,6 +605,35 @@ def test_make_request_not_exists(geth_provider): geth_provider.make_request("ape_thisDoesNotExist") +@geth_process_test +@pytest.mark.parametrize( + "message", + ( + "ape_thisDoesNotExist does not exist/is not available", + "method not found", + "Method ape_thisDoesNotExist not found", + "Unknown RPC Endpoint ape_thisDoesNotExist", + ), +) +def test_make_request_not_exists_different_messages(message, mock_web3, geth_provider): + def mock_make_request(*args, **kwargs): + return {"error": message} + + mock_web3.provider.make_request.side_effect = mock_make_request + + class MyProvider(EthereumNodeProvider): + @property + def web3(self) -> Web3: + return mock_web3 + + provider = MyProvider(network=geth_provider.network) + with pytest.raises( + APINotImplementedError, + match="RPC method 'ape_thisDoesNotExist' is not implemented by this node instance.", + ): + provider.make_request("ape_thisDoesNotExist") + + @geth_process_test def test_geth_bin_not_found(): bin_name = "__NOT_A_REAL_EXECUTABLE_HOPEFULLY__"