Skip to content

Commit

Permalink
fix: handle not-implemented method from tenderly in ape-node (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Sep 3, 2024
1 parent 21ff959 commit 9c63602
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
31 changes: 30 additions & 1 deletion tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__"
Expand Down

0 comments on commit 9c63602

Please sign in to comment.