From 137836b8ecb5828b4683bb30088e965fe6591651 Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 19 Mar 2021 14:04:13 -0600 Subject: [PATCH] Add get_filter_logs, deprecate getFilterLogs --- docs/filters.rst | 2 +- docs/overview.rst | 2 +- docs/web3.eth.rst | 12 +++++++--- newsfragments/1919.feature.rst | 1 + .../core/middleware/test_filter_middleware.py | 2 +- web3/_utils/filters.py | 2 +- web3/_utils/module_testing/eth_module.py | 22 ++++++++++++++++--- web3/eth.py | 3 ++- 8 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 newsfragments/1919.feature.rst diff --git a/docs/filters.rst b/docs/filters.rst index efa363c2e7..d1c84f581c 100644 --- a/docs/filters.rst +++ b/docs/filters.rst @@ -73,7 +73,7 @@ Filter Class Retrieve all entries for this filter. Logs will be retrieved using the - :func:`web3.eth.Eth.getFilterLogs` which returns all entries that match the given + :func:`web3.eth.Eth.get_filter_logs` which returns all entries that match the given filter. diff --git a/docs/overview.rst b/docs/overview.rst index dbebef1287..ad13212e16 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -279,7 +279,7 @@ API - :meth:`web3.eth.filter() ` - :meth:`web3.eth.getFilterChanges() ` -- :meth:`web3.eth.getFilterLogs() ` +- :meth:`web3.eth.get_filter_logs() ` - :meth:`web3.eth.uninstallFilter() ` - :meth:`web3.eth.getLogs() ` - :meth:`Contract.events.your_event_name.createFilter() ` diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index 2f9d6e27f6..ba13e22aa7 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -1070,7 +1070,7 @@ with the filtering API. ] -.. py:method:: Eth.getFilterLogs(self, filter_id) +.. py:method:: Eth.get_filter_logs(self, filter_id) * Delegates to ``eth_getFilterLogs`` RPC Method. @@ -1079,7 +1079,7 @@ with the filtering API. .. code-block:: python >>> filt = web3.eth.filter() - >>> web3.eth.getFilterLogs(filt.filter_id) + >>> web3.eth.get_filter_logs(filt.filter_id) [ { 'address': '0xDc3A9Db694BCdd55EBaE4A89B22aC6D12b3F0c24', @@ -1097,6 +1097,12 @@ with the filtering API. ] +.. py:method:: Eth.getFilterLogs(self, filter_id) + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.eth.Eth.get_filter_logs` + + .. py:method:: Eth.uninstallFilter(self, filter_id) * Delegates to ``eth_uninstallFilter`` RPC Method. @@ -1116,7 +1122,7 @@ with the filtering API. .. py:method:: Eth.getLogs(filter_params) This is the equivalent of: creating a new - filter, running :meth:`~Eth.getFilterLogs`, and then uninstalling the filter. See + filter, running :meth:`~Eth.get_filter_logs`, and then uninstalling the filter. See :meth:`~Eth.filter` for details on allowed filter parameters. diff --git a/newsfragments/1919.feature.rst b/newsfragments/1919.feature.rst new file mode 100644 index 0000000000..93ba280894 --- /dev/null +++ b/newsfragments/1919.feature.rst @@ -0,0 +1 @@ +Add ``eth.get_filter_logs``, deprecate ``eth.getFilterLogs`` diff --git a/tests/core/middleware/test_filter_middleware.py b/tests/core/middleware/test_filter_middleware.py index a6e76a8497..96a20c4b8c 100644 --- a/tests/core/middleware/test_filter_middleware.py +++ b/tests/core/middleware/test_filter_middleware.py @@ -155,7 +155,7 @@ def test_local_filter_middleware(w3, iter_block_number): results = w3.eth.getFilterChanges(log_filter.filter_id) assert results == FILTER_LOG - assert w3.eth.getFilterLogs(log_filter.filter_id) == FILTER_LOG + assert w3.eth.get_filter_logs(log_filter.filter_id) == FILTER_LOG filter_ids = ( block_filter.filter_id, diff --git a/web3/_utils/filters.py b/web3/_utils/filters.py index fb93fac9d6..2f205bda67 100644 --- a/web3/_utils/filters.py +++ b/web3/_utils/filters.py @@ -165,7 +165,7 @@ def get_new_entries(self) -> List[LogReceipt]: return self._format_log_entries(log_entries) def get_all_entries(self) -> List[LogReceipt]: - log_entries = self._filter_valid_entries(self.eth_module.getFilterLogs(self.filter_id)) + log_entries = self._filter_valid_entries(self.eth_module.get_filter_logs(self.filter_id)) return self._format_log_entries(log_entries) def _format_log_entries(self, diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 925d92b4ef..74a13796be 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -1241,7 +1241,23 @@ def test_eth_newFilter(self, web3: "Web3") -> None: assert is_list_like(changes) assert not changes - logs = web3.eth.getFilterLogs(filter.filter_id) + logs = web3.eth.get_filter_logs(filter.filter_id) + assert is_list_like(logs) + assert not logs + + result = web3.eth.uninstallFilter(filter.filter_id) + assert result is True + + def test_eth_newFilter_deprecated(self, web3: "Web3") -> None: + filter = web3.eth.filter({}) + + changes = web3.eth.getFilterChanges(filter.filter_id) + assert is_list_like(changes) + assert not changes + + with pytest.warns(DeprecationWarning, + match="getFilterLogs is deprecated in favor of get_filter_logs"): + logs = web3.eth.getFilterLogs(filter.filter_id) assert is_list_like(logs) assert not logs @@ -1257,7 +1273,7 @@ def test_eth_newBlockFilter(self, web3: "Web3") -> None: assert not changes # TODO: figure out why this fails in go-ethereum - # logs = web3.eth.getFilterLogs(filter.filter_id) + # logs = web3.eth.get_filter_logs(filter.filter_id) # assert is_list_like(logs) # assert not logs @@ -1273,7 +1289,7 @@ def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None: assert not changes # TODO: figure out why this fails in go-ethereum - # logs = web3.eth.getFilterLogs(filter.filter_id) + # logs = web3.eth.get_filter_logs(filter.filter_id) # assert is_list_like(logs) # assert not logs diff --git a/web3/eth.py b/web3/eth.py index 6ee923de3c..ec445a988b 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -595,7 +595,7 @@ def filter_munger( mungers=[default_root_munger] ) - getFilterLogs: Method[Callable[[HexStr], List[LogReceipt]]] = Method( + get_filter_logs: Method[Callable[[HexStr], List[LogReceipt]]] = Method( RPC.eth_getFilterLogs, mungers=[default_root_munger] ) @@ -685,3 +685,4 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None: getTransactionReceipt = DeprecatedMethod(get_transaction_receipt, 'getTransactionReceipt', 'get_transaction_receipt') + getFilterLogs = DeprecatedMethod(get_filter_logs, 'getFilterLogs', 'get_filter_logs')