From 3eeea22db019a7f79facf9fe861deddc6fb26cee Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 7 Aug 2024 19:25:53 -0500 Subject: [PATCH] fix: handle result from make_request --- ape_alchemy/provider.py | 7 ++++++- tests/test_integration.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ape_alchemy/provider.py b/ape_alchemy/provider.py index f92fd09..7b9cb7a 100644 --- a/ape_alchemy/provider.py +++ b/ape_alchemy/provider.py @@ -184,7 +184,7 @@ def create_access_list( def make_request(self, rpc: str, parameters: Optional[Iterable] = None) -> Any: parameters = parameters or [] try: - return self.web3.provider.make_request(RPCEndpoint(rpc), parameters) + result = self.web3.provider.make_request(RPCEndpoint(rpc), parameters) except HTTPError as err: response_data = err.response.json() if err.response else {} if "error" not in response_data: @@ -203,6 +203,11 @@ def make_request(self, rpc: str, parameters: Optional[Iterable] = None) -> Any: ) raise cls(message) from err + if isinstance(result, dict) and (res := result.get("result")): + return res + + return result + def send_private_transaction(self, txn: TransactionAPI, **kwargs) -> ReceiptAPI: """ See `Alchemy's guide `__ diff --git a/tests/test_integration.py b/tests/test_integration.py index c617809..b5a4797 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -49,3 +49,18 @@ def test_polygon_zkevm(): tx = provider.network.ecosystem.create_transaction(receiver=receiver) with pytest.raises(APINotImplementedError): _ = provider.create_access_list(tx) + + +def test_make_requeset_handles_result(): + """ + There was a bug where eth_call because ape-alchemy wasn't + handling the result from make_request properly. + """ + tx = { + "to": "0x5576815a38A3706f37bf815b261cCc7cCA77e975", + "value": "0x0", + "data": "0x70a082310000000000000000000000005576815a38a3706f37bf815b261ccc7cca77e975", + } + with networks.polygon_zkevm.cardona.use_provider("alchemy") as provider: + result = provider.make_request("eth_call", [tx, "latest"]) + assert not isinstance(result, dict)