@@ -760,91 +760,97 @@ async def test_eth_call_revert_without_msg(
760
760
async def test_eth_call_offchain_lookup (
761
761
self ,
762
762
async_w3 : "Web3" ,
763
- offchain_lookup_contract : "Contract" ,
763
+ async_offchain_lookup_contract : "Contract" ,
764
764
unlocked_account : ChecksumAddress ,
765
765
monkeypatch : "MonkeyPatch" ,
766
766
) -> None :
767
- normalized_contract_address = to_hex_if_bytes (offchain_lookup_contract .address ).lower ()
767
+ normalized_contract_address = to_hex_if_bytes (
768
+ async_offchain_lookup_contract .address
769
+ ).lower ()
770
+
768
771
async_mock_offchain_lookup_request_response (
769
772
monkeypatch ,
770
773
mocked_request_url = f'https://web3.py/gateway/{ normalized_contract_address } /{ OFFCHAIN_LOOKUP_TEST_DATA } .json' , # noqa: E501
771
774
mocked_json_data = WEB3PY_AS_HEXBYTES ,
772
775
)
773
- # TODO: change to contract call when async Contract is supported
774
- tx = {
775
- 'to' : offchain_lookup_contract .address ,
776
- 'data' : '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501
777
- }
778
- response = await async_w3 .eth .call (tx ) # type: ignore
779
- response_as_bytes = async_w3 .codec .decode_abi (['bytes' ], response )[0 ]
780
- decoded_as_string = async_w3 .codec .decode_abi (['string' ], response_as_bytes )[0 ]
781
- assert decoded_as_string == 'web3py'
776
+ response_caller = await async_offchain_lookup_contract .caller ().testOffchainLookup ( # noqa: E501 type: ignore
777
+ OFFCHAIN_LOOKUP_TEST_DATA
778
+ )
779
+ response_function_call = await async_offchain_lookup_contract .functions .testOffchainLookup ( # noqa: E501 type: ignore
780
+ OFFCHAIN_LOOKUP_TEST_DATA
781
+ ).call ()
782
+ assert async_w3 .codec .decode_abi (['string' ], response_caller )[0 ] == 'web3py'
783
+ assert async_w3 .codec .decode_abi (['string' ], response_function_call )[0 ] == 'web3py'
782
784
783
785
@pytest .mark .asyncio
784
- async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled (
785
- self , async_w3 : "Web3" , offchain_lookup_contract : "Contract" ,
786
+ async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled_yy (
787
+ self , async_w3 : "Web3" , async_offchain_lookup_contract : "Contract" ,
786
788
) -> None :
787
- # TODO: change to contract call when async Contract is supported
788
- tx = {
789
- 'to' : offchain_lookup_contract .address ,
790
- 'data' : '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501
791
- }
792
789
with pytest .raises (OffchainLookup ):
793
- await async_w3 .eth .call (tx , ccip_read_enabled = False ) # type: ignore
790
+ # test AsyncContractCaller
791
+ await async_offchain_lookup_contract .caller (ccip_read_enabled = False ).testOffchainLookup ( # noqa: E501 type: ignore
792
+ OFFCHAIN_LOOKUP_TEST_DATA
793
+ )
794
+ with pytest .raises (OffchainLookup ):
795
+ # test AsyncContractFunction call
796
+ await async_offchain_lookup_contract .functions .testOffchainLookup (
797
+ OFFCHAIN_LOOKUP_TEST_DATA
798
+ ).call (ccip_read_enabled = False )
794
799
795
800
@pytest .mark .asyncio
796
801
@pytest .mark .parametrize ("max_redirects" , range (- 4 , 4 ))
797
802
async def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4 (
798
803
self ,
799
804
async_w3 : "Web3" ,
800
- offchain_lookup_contract : "Contract" ,
805
+ async_offchain_lookup_contract : "Contract" ,
801
806
max_redirects : int ,
802
807
) -> None :
803
808
default_max_redirects = async_w3 .provider .ccip_read_max_redirects
804
- tx = {
805
- 'to' : offchain_lookup_contract .address ,
806
- 'data' : '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501
807
- }
809
+
808
810
async_w3 .provider .ccip_read_max_redirects = max_redirects
809
811
with pytest .raises (ValueError , match = "at least 4" ):
810
- await async_w3 .eth .call (tx ) # type: ignore
812
+ await async_offchain_lookup_contract .caller ().testOffchainLookup (
813
+ OFFCHAIN_LOOKUP_TEST_DATA
814
+ )
811
815
812
816
async_w3 .provider .ccip_read_max_redirects = default_max_redirects # cleanup
813
817
814
818
@pytest .mark .asyncio
815
819
async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_request_response (
816
820
self ,
817
821
async_w3 : "Web3" ,
818
- offchain_lookup_contract : "Contract" ,
822
+ async_offchain_lookup_contract : "Contract" ,
819
823
unlocked_account : ChecksumAddress ,
820
824
monkeypatch : "MonkeyPatch" ,
821
825
) -> None :
822
- normalized_contract_address = to_hex_if_bytes (offchain_lookup_contract .address ).lower ()
826
+ normalized_contract_address = to_hex_if_bytes (
827
+ async_offchain_lookup_contract .address
828
+ ).lower ()
829
+
823
830
async_mock_offchain_lookup_request_response (
824
831
monkeypatch ,
825
832
mocked_request_url = f'https://web3.py/gateway/{ normalized_contract_address } /{ OFFCHAIN_LOOKUP_TEST_DATA } .json' , # noqa: E501
826
833
mocked_json_data = WEB3PY_AS_HEXBYTES ,
827
834
json_data_field = 'not_data' ,
828
835
)
829
- # TODO: change to contract call when async Contract is supported
830
- tx = {
831
- 'to' : offchain_lookup_contract .address ,
832
- 'data' : '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501
833
- }
834
836
with pytest .raises (ValidationError , match = "missing 'data' field" ):
835
- await async_w3 .eth .call (tx ) # type: ignore
837
+ await async_offchain_lookup_contract .caller ().testOffchainLookup (
838
+ OFFCHAIN_LOOKUP_TEST_DATA
839
+ )
836
840
837
841
@pytest .mark .asyncio
838
842
@pytest .mark .parametrize ('status_code_non_4xx_error' , [100 , 300 , 500 , 600 ])
839
843
async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST (
840
844
self ,
841
845
async_w3 : "Web3" ,
842
- offchain_lookup_contract : "Contract" ,
846
+ async_offchain_lookup_contract : "Contract" ,
843
847
unlocked_account : ChecksumAddress ,
844
848
monkeypatch : "MonkeyPatch" ,
845
849
status_code_non_4xx_error : int ,
846
850
) -> None :
847
- normalized_contract_address = to_hex_if_bytes (offchain_lookup_contract .address ).lower ()
851
+ normalized_contract_address = to_hex_if_bytes (
852
+ async_offchain_lookup_contract .address
853
+ ).lower ()
848
854
849
855
# The next url in our test contract doesn't contain '{data}', triggering the POST request
850
856
# logic. The idea here is to return a bad status for the first url (GET) and a success
@@ -865,73 +871,66 @@ async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_
865
871
sender = normalized_contract_address ,
866
872
calldata = OFFCHAIN_LOOKUP_TEST_DATA ,
867
873
)
868
- # TODO: change to contract call when async Contract is supported
869
- tx = {
870
- 'to' : offchain_lookup_contract .address ,
871
- 'data' : '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501
872
- }
873
- response = await async_w3 .eth .call (tx ) # type: ignore
874
- response_as_bytes = async_w3 .codec .decode_abi (['bytes' ], response )[0 ]
875
- decoded_as_string = async_w3 .codec .decode_abi (['string' ], response_as_bytes )[0 ]
876
- assert decoded_as_string == 'web3py'
874
+ response = await async_offchain_lookup_contract .caller ().testOffchainLookup (
875
+ OFFCHAIN_LOOKUP_TEST_DATA
876
+ )
877
+ assert async_w3 .codec .decode_abi (['string' ], response )[0 ] == 'web3py'
877
878
878
879
@pytest .mark .asyncio
879
880
@pytest .mark .parametrize ('status_code_4xx_error' , [400 , 410 , 450 , 499 ])
880
881
async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code (
881
882
self ,
882
883
async_w3 : "Web3" ,
883
- offchain_lookup_contract : "Contract" ,
884
+ async_offchain_lookup_contract : "Contract" ,
884
885
unlocked_account : ChecksumAddress ,
885
886
monkeypatch : "MonkeyPatch" ,
886
887
status_code_4xx_error : int ,
887
888
) -> None :
888
- normalized_contract_address = to_hex_if_bytes (offchain_lookup_contract .address ).lower ()
889
+ normalized_contract_address = to_hex_if_bytes (
890
+ async_offchain_lookup_contract .address
891
+ ).lower ()
892
+
889
893
async_mock_offchain_lookup_request_response (
890
894
monkeypatch ,
891
895
mocked_request_url = f'https://web3.py/gateway/{ normalized_contract_address } /{ OFFCHAIN_LOOKUP_TEST_DATA } .json' , # noqa: E501
892
896
mocked_status_code = status_code_4xx_error ,
893
897
mocked_json_data = WEB3PY_AS_HEXBYTES ,
894
898
)
895
899
with pytest .raises (Exception , match = "called raise_for_status\\ (\\ )" ):
896
- # TODO: change to contract call when async Contract is supported
897
- tx = {
898
- 'to' : offchain_lookup_contract .address ,
899
- 'data' : '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501
900
- }
901
- await async_w3 .eth .call (tx ) # type: ignore
900
+ await async_offchain_lookup_contract .caller ().testOffchainLookup (
901
+ OFFCHAIN_LOOKUP_TEST_DATA
902
+ )
902
903
903
904
@pytest .mark .asyncio
904
905
async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail (
905
- self , async_w3 : "Web3" , offchain_lookup_contract : "Contract" ,
906
+ self , async_w3 : "Web3" , async_offchain_lookup_contract : "Contract" ,
906
907
) -> None :
907
908
# GET and POST requests should fail since responses are not mocked
908
909
with pytest .raises (
909
910
MultipleFailedRequests , match = "Offchain lookup failed for supplied urls"
910
911
):
911
- # TODO: change to contract call when async Contract is supported
912
- tx = {
913
- 'to' : offchain_lookup_contract .address ,
914
- 'data' : '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501
915
- }
916
- await async_w3 .eth .call (tx ) # type: ignore
912
+ await async_offchain_lookup_contract .caller ().testOffchainLookup (
913
+ OFFCHAIN_LOOKUP_TEST_DATA
914
+ )
917
915
918
916
@pytest .mark .asyncio
919
917
async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests (
920
918
self ,
921
919
async_w3 : "Web3" ,
922
- offchain_lookup_contract : "Contract" ,
920
+ async_offchain_lookup_contract : "Contract" ,
923
921
unlocked_account : ChecksumAddress ,
924
922
monkeypatch : "MonkeyPatch" ,
925
923
) -> None :
926
- normalized_contract_address = to_hex_if_bytes (offchain_lookup_contract .address ).lower ()
924
+ normalized_contract_address = to_hex_if_bytes (
925
+ async_offchain_lookup_contract .address
926
+ ).lower ()
927
+
927
928
async_mock_offchain_lookup_request_response (
928
929
monkeypatch ,
929
930
mocked_request_url = f'https://web3.py/gateway/{ normalized_contract_address } /0x.json' ,
930
931
)
931
932
with pytest .raises (TooManyRequests , match = "Too many CCIP read redirects" ):
932
- # TODO: change to contract call when async Contract is supported
933
- tx = {'to' : offchain_lookup_contract .address , 'data' : '0x09a3c01b' }
934
- await async_w3 .eth .call (tx ) # type: ignore
933
+ await async_offchain_lookup_contract .caller ().continuousOffchainLookup () # noqa: E501 type: ignore
935
934
936
935
@pytest .mark .asyncio
937
936
async def test_async_eth_hashrate (
0 commit comments