@@ -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 :
@@ -897,15 +913,6 @@ async def test_async_eth_get_logs_with_logs(
897
913
emitter_contract_address : ChecksumAddress ,
898
914
txn_hash_with_log : HexStr ,
899
915
) -> None :
900
- def assert_contains_log (result : Sequence [LogReceipt ]) -> None :
901
- assert len (result ) == 1
902
- log_entry = result [0 ]
903
- assert log_entry ['blockNumber' ] == block_with_txn_with_log ['number' ]
904
- assert log_entry ['blockHash' ] == block_with_txn_with_log ['hash' ]
905
- assert log_entry ['logIndex' ] == 0
906
- assert is_same_address (log_entry ['address' ], emitter_contract_address )
907
- assert log_entry ['transactionIndex' ] == 0
908
- assert log_entry ['transactionHash' ] == HexBytes (txn_hash_with_log )
909
916
910
917
# Test with block range
911
918
@@ -915,14 +922,24 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
915
922
"toBlock" : block_with_txn_with_log ['number' ],
916
923
}
917
924
result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
918
- assert_contains_log (result )
925
+ _assert_contains_log (
926
+ result ,
927
+ block_with_txn_with_log ,
928
+ emitter_contract_address ,
929
+ txn_hash_with_log
930
+ )
919
931
920
932
# specify only `from_block`. by default `to_block` should be 'latest'
921
933
filter_params = {
922
934
"fromBlock" : BlockNumber (0 ),
923
935
}
924
936
result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
925
- assert_contains_log (result )
937
+ _assert_contains_log (
938
+ result ,
939
+ block_with_txn_with_log ,
940
+ emitter_contract_address ,
941
+ txn_hash_with_log
942
+ )
926
943
927
944
# Test with `address`
928
945
@@ -940,15 +957,6 @@ async def test_async_eth_get_logs_with_logs_topic_args(
940
957
emitter_contract_address : ChecksumAddress ,
941
958
txn_hash_with_log : HexStr ,
942
959
) -> None :
943
- def assert_contains_log (result : Sequence [LogReceipt ]) -> None :
944
- assert len (result ) == 1
945
- log_entry = result [0 ]
946
- assert log_entry ['blockNumber' ] == block_with_txn_with_log ['number' ]
947
- assert log_entry ['blockHash' ] == block_with_txn_with_log ['hash' ]
948
- assert log_entry ['logIndex' ] == 0
949
- assert is_same_address (log_entry ['address' ], emitter_contract_address )
950
- assert log_entry ['transactionIndex' ] == 0
951
- assert log_entry ['transactionHash' ] == HexBytes (txn_hash_with_log )
952
960
953
961
# Test with None event sig
954
962
@@ -960,7 +968,12 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
960
968
}
961
969
962
970
result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
963
- assert_contains_log (result )
971
+ _assert_contains_log (
972
+ result ,
973
+ block_with_txn_with_log ,
974
+ emitter_contract_address ,
975
+ txn_hash_with_log
976
+ )
964
977
965
978
# Test with None indexed arg
966
979
filter_params = {
@@ -970,7 +983,12 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
970
983
None ],
971
984
}
972
985
result = await async_w3 .eth .get_logs (filter_params ) # type: ignore
973
- assert_contains_log (result )
986
+ _assert_contains_log (
987
+ result ,
988
+ block_with_txn_with_log ,
989
+ emitter_contract_address ,
990
+ txn_hash_with_log
991
+ )
974
992
975
993
@pytest .mark .asyncio
976
994
async def test_async_eth_get_logs_with_logs_none_topic_args (self , async_w3 : "Web3" ) -> None :
@@ -2853,15 +2871,6 @@ def test_eth_get_logs_with_logs(
2853
2871
emitter_contract_address : ChecksumAddress ,
2854
2872
txn_hash_with_log : HexStr ,
2855
2873
) -> None :
2856
- def assert_contains_log (result : Sequence [LogReceipt ]) -> None :
2857
- assert len (result ) == 1
2858
- log_entry = result [0 ]
2859
- assert log_entry ['blockNumber' ] == block_with_txn_with_log ['number' ]
2860
- assert log_entry ['blockHash' ] == block_with_txn_with_log ['hash' ]
2861
- assert log_entry ['logIndex' ] == 0
2862
- assert is_same_address (log_entry ['address' ], emitter_contract_address )
2863
- assert log_entry ['transactionIndex' ] == 0
2864
- assert log_entry ['transactionHash' ] == HexBytes (txn_hash_with_log )
2865
2874
2866
2875
# Test with block range
2867
2876
@@ -2871,14 +2880,24 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
2871
2880
"toBlock" : block_with_txn_with_log ['number' ],
2872
2881
}
2873
2882
result = web3 .eth .get_logs (filter_params )
2874
- 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
+ )
2875
2889
2876
2890
# specify only `from_block`. by default `to_block` should be 'latest'
2877
2891
filter_params = {
2878
2892
"fromBlock" : BlockNumber (0 ),
2879
2893
}
2880
2894
result = web3 .eth .get_logs (filter_params )
2881
- 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
+ )
2882
2901
2883
2902
# Test with `address`
2884
2903
@@ -2895,15 +2914,6 @@ def test_eth_get_logs_with_logs_topic_args(
2895
2914
emitter_contract_address : ChecksumAddress ,
2896
2915
txn_hash_with_log : HexStr ,
2897
2916
) -> None :
2898
- def assert_contains_log (result : Sequence [LogReceipt ]) -> None :
2899
- assert len (result ) == 1
2900
- log_entry = result [0 ]
2901
- assert log_entry ['blockNumber' ] == block_with_txn_with_log ['number' ]
2902
- assert log_entry ['blockHash' ] == block_with_txn_with_log ['hash' ]
2903
- assert log_entry ['logIndex' ] == 0
2904
- assert is_same_address (log_entry ['address' ], emitter_contract_address )
2905
- assert log_entry ['transactionIndex' ] == 0
2906
- assert log_entry ['transactionHash' ] == HexBytes (txn_hash_with_log )
2907
2917
2908
2918
# Test with None event sig
2909
2919
@@ -2915,7 +2925,12 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
2915
2925
}
2916
2926
2917
2927
result = web3 .eth .get_logs (filter_params )
2918
- 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
+ )
2919
2934
2920
2935
# Test with None indexed arg
2921
2936
filter_params = {
@@ -2925,7 +2940,12 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None:
2925
2940
None ],
2926
2941
}
2927
2942
result = web3 .eth .get_logs (filter_params )
2928
- 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
+ )
2929
2949
2930
2950
def test_eth_get_logs_with_logs_none_topic_args (self , web3 : "Web3" ) -> None :
2931
2951
# Test with None overflowing
0 commit comments