@@ -83,6 +83,22 @@ def mine_pending_block(web3: "Web3") -> None:
83
83
web3 .geth .miner .stop () # type: ignore
84
84
85
85
86
+ def _assert_contains_log (
87
+ result : Sequence [LogReceipt ],
88
+ block_with_txn_with_log : BlockData ,
89
+ emitter_contract_address : ChecksumAddress ,
90
+ txn_hash_with_log : HexStr ,
91
+ ) -> None :
92
+ assert len (result ) == 1
93
+ log_entry = result [0 ]
94
+ assert log_entry ['blockNumber' ] == block_with_txn_with_log ['number' ]
95
+ assert log_entry ['blockHash' ] == block_with_txn_with_log ['hash' ]
96
+ assert log_entry ['logIndex' ] == 0
97
+ assert is_same_address (log_entry ['address' ], emitter_contract_address )
98
+ assert log_entry ['transactionIndex' ] == 0
99
+ assert log_entry ['transactionHash' ] == HexBytes (txn_hash_with_log )
100
+
101
+
86
102
class AsyncEthModuleTest :
87
103
@pytest .mark .asyncio
88
104
async def test_eth_gas_price (self , async_w3 : "Web3" ) -> None :
@@ -848,6 +864,143 @@ async def test_async_eth_accounts(self, async_w3: "Web3") -> None:
848
864
))
849
865
assert await async_w3 .eth .coinbase in accounts # type: ignore
850
866
867
+ @pytest .mark .asyncio
868
+ async def test_async_eth_get_logs_without_logs (
869
+ self , async_w3 : "Web3" , block_with_txn_with_log : BlockData
870
+ ) -> None :
871
+ # Test with block range
872
+
873
+ filter_params : FilterParams = {
874
+ "fromBlock" : BlockNumber (0 ),
875
+ "toBlock" : BlockNumber (block_with_txn_with_log ['number' ] - 1 ),
876
+ }
877
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
878
+ assert len (result ) == 0
879
+
880
+ # the range is wrong
881
+ filter_params = {
882
+ "fromBlock" : block_with_txn_with_log ['number' ],
883
+ "toBlock" : BlockNumber (block_with_txn_with_log ['number' ] - 1 ),
884
+ }
885
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
886
+ assert len (result ) == 0
887
+
888
+ # Test with `address`
889
+
890
+ # filter with other address
891
+ filter_params = {
892
+ "fromBlock" : BlockNumber (0 ),
893
+ "address" : UNKNOWN_ADDRESS ,
894
+ }
895
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
896
+ assert len (result ) == 0
897
+
898
+ # Test with multiple `address`
899
+
900
+ # filter with other address
901
+ filter_params = {
902
+ "fromBlock" : BlockNumber (0 ),
903
+ "address" : [UNKNOWN_ADDRESS , UNKNOWN_ADDRESS ],
904
+ }
905
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
906
+ assert len (result ) == 0
907
+
908
+ @pytest .mark .asyncio
909
+ async def test_async_eth_get_logs_with_logs (
910
+ self ,
911
+ async_w3 : "Web3" ,
912
+ block_with_txn_with_log : BlockData ,
913
+ emitter_contract_address : ChecksumAddress ,
914
+ txn_hash_with_log : HexStr ,
915
+ ) -> None :
916
+
917
+ # Test with block range
918
+
919
+ # the range includes the block where the log resides in
920
+ filter_params : FilterParams = {
921
+ "fromBlock" : block_with_txn_with_log ['number' ],
922
+ "toBlock" : block_with_txn_with_log ['number' ],
923
+ }
924
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
925
+ _assert_contains_log (
926
+ result ,
927
+ block_with_txn_with_log ,
928
+ emitter_contract_address ,
929
+ txn_hash_with_log
930
+ )
931
+
932
+ # specify only `from_block`. by default `to_block` should be 'latest'
933
+ filter_params = {
934
+ "fromBlock" : BlockNumber (0 ),
935
+ }
936
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
937
+ _assert_contains_log (
938
+ result ,
939
+ block_with_txn_with_log ,
940
+ emitter_contract_address ,
941
+ txn_hash_with_log
942
+ )
943
+
944
+ # Test with `address`
945
+
946
+ # filter with emitter_contract.address
947
+ filter_params = {
948
+ "fromBlock" : BlockNumber (0 ),
949
+ "address" : emitter_contract_address ,
950
+ }
951
+
952
+ @pytest .mark .asyncio
953
+ async def test_async_eth_get_logs_with_logs_topic_args (
954
+ self ,
955
+ async_w3 : "Web3" ,
956
+ block_with_txn_with_log : BlockData ,
957
+ emitter_contract_address : ChecksumAddress ,
958
+ txn_hash_with_log : HexStr ,
959
+ ) -> None :
960
+
961
+ # Test with None event sig
962
+
963
+ filter_params : FilterParams = {
964
+ "fromBlock" : BlockNumber (0 ),
965
+ "topics" : [
966
+ None ,
967
+ HexStr ('0x000000000000000000000000000000000000000000000000000000000000d431' )],
968
+ }
969
+
970
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
971
+ _assert_contains_log (
972
+ result ,
973
+ block_with_txn_with_log ,
974
+ emitter_contract_address ,
975
+ txn_hash_with_log
976
+ )
977
+
978
+ # Test with None indexed arg
979
+ filter_params = {
980
+ "fromBlock" : BlockNumber (0 ),
981
+ "topics" : [
982
+ HexStr ('0x057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca' ),
983
+ None ],
984
+ }
985
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
986
+ _assert_contains_log (
987
+ result ,
988
+ block_with_txn_with_log ,
989
+ emitter_contract_address ,
990
+ txn_hash_with_log
991
+ )
992
+
993
+ @pytest .mark .asyncio
994
+ async def test_async_eth_get_logs_with_logs_none_topic_args (self , async_w3 : "Web3" ) -> None :
995
+ # Test with None overflowing
996
+ filter_params : FilterParams = {
997
+ "fromBlock" : BlockNumber (0 ),
998
+ "topics" : [None , None , None ],
999
+ }
1000
+
1001
+ result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
1002
+ assert len (result ) == 0
1003
+
851
1004
def test_async_provider_default_account (
852
1005
self ,
853
1006
async_w3 : "Web3" ,
@@ -2718,15 +2871,6 @@ def test_eth_get_logs_with_logs(
2718
2871
emitter_contract_address : ChecksumAddress ,
2719
2872
txn_hash_with_log : HexStr ,
2720
2873
) -> None :
2721
- def assert_contains_log (result : Sequence [LogReceipt ]) -> None :
2722
- assert len (result ) == 1
2723
- log_entry = result [0 ]
2724
- assert log_entry ['blockNumber' ] == block_with_txn_with_log ['number' ]
2725
- assert log_entry ['blockHash' ] == block_with_txn_with_log ['hash' ]
2726
- assert log_entry ['logIndex' ] == 0
2727
- assert is_same_address (log_entry ['address' ], emitter_contract_address )
2728
- assert log_entry ['transactionIndex' ] == 0
2729
- assert log_entry ['transactionHash' ] == HexBytes (txn_hash_with_log )
2730
2874
2731
2875
# Test with block range
2732
2876
@@ -2736,14 +2880,24 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
2736
2880
"toBlock" : block_with_txn_with_log ['number' ],
2737
2881
}
2738
2882
result = web3 .eth .get_logs (filter_params )
2739
- assert_contains_log (result )
2883
+ _assert_contains_log (
2884
+ result ,
2885
+ block_with_txn_with_log ,
2886
+ emitter_contract_address ,
2887
+ txn_hash_with_log
2888
+ )
2740
2889
2741
2890
# specify only `from_block`. by default `to_block` should be 'latest'
2742
2891
filter_params = {
2743
2892
"fromBlock" : BlockNumber (0 ),
2744
2893
}
2745
2894
result = web3 .eth .get_logs (filter_params )
2746
- assert_contains_log (result )
2895
+ _assert_contains_log (
2896
+ result ,
2897
+ block_with_txn_with_log ,
2898
+ emitter_contract_address ,
2899
+ txn_hash_with_log
2900
+ )
2747
2901
2748
2902
# Test with `address`
2749
2903
@@ -2760,15 +2914,6 @@ def test_eth_get_logs_with_logs_topic_args(
2760
2914
emitter_contract_address : ChecksumAddress ,
2761
2915
txn_hash_with_log : HexStr ,
2762
2916
) -> None :
2763
- def assert_contains_log (result : Sequence [LogReceipt ]) -> None :
2764
- assert len (result ) == 1
2765
- log_entry = result [0 ]
2766
- assert log_entry ['blockNumber' ] == block_with_txn_with_log ['number' ]
2767
- assert log_entry ['blockHash' ] == block_with_txn_with_log ['hash' ]
2768
- assert log_entry ['logIndex' ] == 0
2769
- assert is_same_address (log_entry ['address' ], emitter_contract_address )
2770
- assert log_entry ['transactionIndex' ] == 0
2771
- assert log_entry ['transactionHash' ] == HexBytes (txn_hash_with_log )
2772
2917
2773
2918
# Test with None event sig
2774
2919
@@ -2780,7 +2925,12 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
2780
2925
}
2781
2926
2782
2927
result = web3 .eth .get_logs (filter_params )
2783
- assert_contains_log (result )
2928
+ _assert_contains_log (
2929
+ result ,
2930
+ block_with_txn_with_log ,
2931
+ emitter_contract_address ,
2932
+ txn_hash_with_log
2933
+ )
2784
2934
2785
2935
# Test with None indexed arg
2786
2936
filter_params = {
@@ -2790,7 +2940,12 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
2790
2940
None ],
2791
2941
}
2792
2942
result = web3 .eth .get_logs (filter_params )
2793
- assert_contains_log (result )
2943
+ _assert_contains_log (
2944
+ result ,
2945
+ block_with_txn_with_log ,
2946
+ emitter_contract_address ,
2947
+ txn_hash_with_log
2948
+ )
2794
2949
2795
2950
def test_eth_get_logs_with_logs_none_topic_args (self , web3 : "Web3" ) -> None :
2796
2951
# Test with None overflowing
0 commit comments