Skip to content

Commit

Permalink
fix: issue where empty results were not returned properly from `make_…
Browse files Browse the repository at this point in the history
…request()` (#96)

Co-authored-by: antazoey <[email protected]>
  • Loading branch information
antazoey and antazoey authored Jan 6, 2025
1 parent 548b653 commit 4c29eb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 1 addition & 4 deletions ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ 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
return result["result"] if isinstance(result, dict) and "result" in result else result

def send_private_transaction(self, txn: TransactionAPI, **kwargs) -> ReceiptAPI:
"""
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
max-line-length = 100
ignore = E704,W503,PYD002,TC003,TC006
exclude =
.venv*
venv*
docs
build
Expand Down
11 changes: 11 additions & 0 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,14 @@ def rate_limit_hook(self, rpc, params):
result = alchemy_provider.make_request("ape_testRateLimiting", parameters=[])
assert rate_limit_tester.tries_made == rate_limit_tester.tries + 1
assert result == {"success": True}


def test_make_request_empty_result(alchemy_provider, mock_web3):
"""
Testing the case when the result is empty that it still returns it
(and not the raw JSON response).
"""
alchemy_provider._web3 = mock_web3
mock_web3.provider.make_request.return_value = {"jsonrpc": "2.0", "id": 8, "result": []}
result = alchemy_provider.make_request("ape_madeUpRPC", [])
assert result == []

0 comments on commit 4c29eb8

Please sign in to comment.