Skip to content

Commit

Permalink
Add async changes for previous commit:
Browse files Browse the repository at this point in the history
- Use json payload for CCIP-Read POST requests.
- Tweak mocker to check for ``json`` key and data in kwargs.
- Add newsfragment for PR #3512.
  • Loading branch information
fselmo committed Oct 15, 2024
1 parent cce32db commit 8125b3b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions newsfragments/3512.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Send ``json``, not ``data`` with CCIP-Read POST requests.
4 changes: 2 additions & 2 deletions web3/_utils/module_testing/module_testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ async def _mock_specific_request(
# mock response only to specified url while validating appropriate fields
if url_from_args == mocked_request_url:
assert kwargs["timeout"] == ClientTimeout(DEFAULT_HTTP_TIMEOUT)
if http_method.upper() == "post":
assert kwargs["data"] == {"data": calldata, "sender": sender}
if http_method.upper() == "POST":
assert kwargs["json"] == {"data": calldata, "sender": sender}
return AsyncMockedResponse()

# else, make a normal request (no mocking)
Expand Down
2 changes: 1 addition & 1 deletion web3/utils/async_exception_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def async_handle_offchain_lookup(
else:
response = await session.post(
formatted_url,
data={"data": formatted_data, "sender": formatted_sender},
json={"data": formatted_data, "sender": formatted_sender},
timeout=ClientTimeout(DEFAULT_HTTP_TIMEOUT),
)
except Exception:
Expand Down
6 changes: 1 addition & 5 deletions web3/utils/exception_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ def handle_offchain_lookup(
if "{data}" in url and "{sender}" in url:
response = session.get(formatted_url, timeout=DEFAULT_HTTP_TIMEOUT)
else:
payload = {
"data": formatted_data,
"sender": formatted_sender,
}
response = session.post(
formatted_url,
json=payload,
json={"data": formatted_data, "sender": formatted_sender},
timeout=DEFAULT_HTTP_TIMEOUT,
)
except Exception:
Expand Down

0 comments on commit 8125b3b

Please sign in to comment.