Skip to content

Commit

Permalink
fix: handle result from make_request
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Aug 8, 2024
1 parent 5c44fd8 commit 3eeea22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 <https://www.alchemy.com/overviews/ethereum-private-transactions>`__
Expand Down
15 changes: 15 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3eeea22

Please sign in to comment.