Skip to content

Commit

Permalink
Add uninstall_filter, deprecate uninstallFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Mar 19, 2021
1 parent 12eba97 commit 3b77c86
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ API
- :meth:`web3.eth.filter() <web3.eth.Eth.filter>`
- :meth:`web3.eth.getFilterChanges() <web3.eth.Eth.getFilterChanges>`
- :meth:`web3.eth.getFilterLogs() <web3.eth.Eth.getFilterLogs>`
- :meth:`web3.eth.uninstallFilter() <web3.eth.Eth.uninstallFilter>`
- :meth:`web3.eth.uninstall_filter() <web3.eth.Eth.uninstall_filter>`
- :meth:`web3.eth.getLogs() <web3.eth.Eth.getLogs>`
- :meth:`Contract.events.your_event_name.createFilter() <web3.contract.Contract.events.your_event_name.createFilter>`
- :meth:`Contract.events.your_event_name.build_filter() <web3.contract.Contract.events.your_event_name.build_filter>`
Expand Down
12 changes: 9 additions & 3 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ with the filtering API.
]
.. py:method:: Eth.uninstallFilter(self, filter_id)
.. py:method:: Eth.uninstall_filter(self, filter_id)
* Delegates to ``eth_uninstallFilter`` RPC Method.

Expand All @@ -1107,12 +1107,18 @@ with the filtering API.
.. code-block:: python
>>> filt = web3.eth.filter()
>>> web3.eth.uninstallFilter(filt.filter_id)
>>> web3.eth.uninstall_filter(filt.filter_id)
True
>>> web3.eth.uninstallFilter(filt.filter_id)
>>> web3.eth.uninstall_filter(filt.filter_id)
False # already uninstalled.
.. py:method:: Eth.uninstallFilter(self, filter_id)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.uninstall_filter`


.. py:method:: Eth.getLogs(filter_params)
This is the equivalent of: creating a new
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1920.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``eth.uninstall_filter``, deprecate ``eth.uninstallFilter``
8 changes: 6 additions & 2 deletions tests/integration/parity/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ def test_eth_estimateGas_revert_without_msg(
def test_eth_getBlockByNumber_pending(self, web3):
super().test_eth_getBlockByNumber_pending(web3)

def test_eth_uninstallFilter(self, web3):
def test_eth_uninstall_filter(self, web3):
pytest.xfail('eth_uninstallFilter calls to parity always return true')
super().test_eth_uninstallFilter(web3)
super().test_eth_uninstall_filter(web3)

def test_eth_uninstallFilter_deprecated(self, web3):
pytest.xfail('eth_uninstallFilter calls to parity always return true')
super().test_eth_uninstallFilter_deprecated(web3)

@pytest.mark.xfail(reason='Parity is not setup to auto mine')
def test_eth_replace_transaction_already_mined(self, web3, unlocked_account):
Expand Down
26 changes: 20 additions & 6 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def test_eth_newFilter(self, web3: "Web3") -> None:
assert is_list_like(logs)
assert not logs

result = web3.eth.uninstallFilter(filter.filter_id)
result = web3.eth.uninstall_filter(filter.filter_id)
assert result is True

def test_eth_newBlockFilter(self, web3: "Web3") -> None:
Expand All @@ -1261,7 +1261,7 @@ def test_eth_newBlockFilter(self, web3: "Web3") -> None:
# assert is_list_like(logs)
# assert not logs

result = web3.eth.uninstallFilter(filter.filter_id)
result = web3.eth.uninstall_filter(filter.filter_id)
assert result is True

def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None:
Expand All @@ -1277,7 +1277,7 @@ def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None:
# assert is_list_like(logs)
# assert not logs

result = web3.eth.uninstallFilter(filter.filter_id)
result = web3.eth.uninstall_filter(filter.filter_id)
assert result is True

def test_eth_getLogs_without_logs(
Expand Down Expand Up @@ -1440,14 +1440,28 @@ def test_eth_call_old_contract_state(
if pending_call_result != 1:
raise AssertionError("pending call result was %d instead of 1" % pending_call_result)

def test_eth_uninstallFilter(self, web3: "Web3") -> None:
def test_eth_uninstallFilter_deprecated(self, web3: "Web3") -> None:
filter = web3.eth.filter({})
assert is_string(filter.filter_id)

success = web3.eth.uninstallFilter(filter.filter_id)
with pytest.warns(DeprecationWarning,
match="uninstallFilter is deprecated in favor of uninstall_filter"):
success = web3.eth.uninstallFilter(filter.filter_id)
assert success is True

with pytest.warns(DeprecationWarning,
match="uninstallFilter is deprecated in favor of uninstall_filter"):
failure = web3.eth.uninstallFilter(filter.filter_id)
assert failure is False

def test_eth_uninstall_filter(self, web3: "Web3") -> None:
filter = web3.eth.filter({})
assert is_string(filter.filter_id)

success = web3.eth.uninstall_filter(filter.filter_id)
assert success is True

failure = web3.eth.uninstallFilter(filter.filter_id)
failure = web3.eth.uninstall_filter(filter.filter_id)
assert failure is False

def test_eth_getTransactionFromBlock_deprecation(
Expand Down
3 changes: 2 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def filter_munger(
mungers=[default_root_munger],
)

uninstallFilter: Method[Callable[[HexStr], bool]] = Method(
uninstall_filter: Method[Callable[[HexStr], bool]] = Method(
RPC.eth_uninstallFilter,
mungers=[default_root_munger],
)
Expand Down Expand Up @@ -691,3 +691,4 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
getTransactionReceipt = DeprecatedMethod(get_transaction_receipt,
'getTransactionReceipt',
'get_transaction_receipt')
uninstallFilter = DeprecatedMethod(uninstall_filter, 'uninstallFilter', 'uninstall_filter')

0 comments on commit 3b77c86

Please sign in to comment.