From cce32dbf81999c3377af221e36a582de013594ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Tanr=C4=B1kulu?= Date: Tue, 15 Oct 2024 15:42:41 +0200 Subject: [PATCH] bugfix: CCIP-Read POST should send json data: - send ccip-read post request with json payload - update _mock_specific_request util for ccip-read post requests - lint, remove additional header since it's added when payload sent with json arg --- web3/_utils/module_testing/module_testing_utils.py | 2 +- web3/utils/exception_handling.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/web3/_utils/module_testing/module_testing_utils.py b/web3/_utils/module_testing/module_testing_utils.py index 35a5e33d11..84e0f7bbc0 100644 --- a/web3/_utils/module_testing/module_testing_utils.py +++ b/web3/_utils/module_testing/module_testing_utils.py @@ -147,7 +147,7 @@ def _mock_specific_request( if url_from_args == mocked_request_url: assert kwargs["timeout"] == DEFAULT_HTTP_TIMEOUT if http_method.upper() == "POST": - assert kwargs["data"] == {"data": calldata, "sender": sender} + assert kwargs["json"] == {"data": calldata, "sender": sender} return MockedResponse() # else, make a normal request (no mocking) diff --git a/web3/utils/exception_handling.py b/web3/utils/exception_handling.py index 7957360cb0..aee50926c1 100644 --- a/web3/utils/exception_handling.py +++ b/web3/utils/exception_handling.py @@ -52,12 +52,13 @@ 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, - data={ - "data": formatted_data, - "sender": formatted_sender, - }, + json=payload, timeout=DEFAULT_HTTP_TIMEOUT, ) except Exception: