From 8125b3bca038d06083ca5534b9d818f964a0c21f Mon Sep 17 00:00:00 2001 From: fselmo Date: Tue, 15 Oct 2024 09:23:39 -0600 Subject: [PATCH] Add async changes for previous commit: - Use json payload for CCIP-Read POST requests. - Tweak mocker to check for ``json`` key and data in kwargs. - Add newsfragment for PR #3512. --- newsfragments/3512.bugfix.rst | 1 + web3/_utils/module_testing/module_testing_utils.py | 4 ++-- web3/utils/async_exception_handling.py | 2 +- web3/utils/exception_handling.py | 6 +----- 4 files changed, 5 insertions(+), 8 deletions(-) create mode 100644 newsfragments/3512.bugfix.rst diff --git a/newsfragments/3512.bugfix.rst b/newsfragments/3512.bugfix.rst new file mode 100644 index 0000000000..fec9b62d5b --- /dev/null +++ b/newsfragments/3512.bugfix.rst @@ -0,0 +1 @@ +Send ``json``, not ``data`` with CCIP-Read POST requests. diff --git a/web3/_utils/module_testing/module_testing_utils.py b/web3/_utils/module_testing/module_testing_utils.py index 84e0f7bbc0..a15fea72d0 100644 --- a/web3/_utils/module_testing/module_testing_utils.py +++ b/web3/_utils/module_testing/module_testing_utils.py @@ -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) diff --git a/web3/utils/async_exception_handling.py b/web3/utils/async_exception_handling.py index b4e23e12d5..ea42d4d52c 100644 --- a/web3/utils/async_exception_handling.py +++ b/web3/utils/async_exception_handling.py @@ -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: diff --git a/web3/utils/exception_handling.py b/web3/utils/exception_handling.py index aee50926c1..7aa8991084 100644 --- a/web3/utils/exception_handling.py +++ b/web3/utils/exception_handling.py @@ -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: