diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f54b2090..507216c4 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 5.1.7 +current_version = 5.1.8 commit = True tag = True diff --git a/aquarius/__init__.py b/aquarius/__init__.py index 9ad23979..f3d8b8ea 100644 --- a/aquarius/__init__.py +++ b/aquarius/__init__.py @@ -9,5 +9,5 @@ __author__ = """OceanProtocol""" # fmt: off # bumpversion needs single quotes -__version__ = '5.1.7' +__version__ = '5.1.8' # fmt: on diff --git a/aquarius/events/purgatory.py b/aquarius/events/purgatory.py index 7ccf8183..bacea3f8 100644 --- a/aquarius/events/purgatory.py +++ b/aquarius/events/purgatory.py @@ -22,7 +22,7 @@ def __init__(self, es_instance): def retrieve_new_list(self, env_var): """ - :param env_var: Url of the file containing purgatory list. + :param env_var: Environment variable name of the file URL containing purgatory list. :return: Object as follows: {...('', ''),...} """ response = requests.get(os.getenv(env_var), timeout=5) @@ -31,9 +31,16 @@ def retrieve_new_list(self, env_var): logger.info( f"PURGATORY: Successfully retrieved new purgatory list from {env_var} env var." ) - return { - (a["did"], a["reason"]) for a in response.json() if a and "did" in a - } + if env_var == "ASSET_PURGATORY_URL": + return { + (a["did"], a["reason"]) for a in response.json() if a and "did" in a + } + elif env_var == "ACCOUNT_PURGATORY_URL": + return { + (a["address"], a["reason"]) + for a in response.json() + if a and "address" in a + } logger.info( f"PURGATORY: Failed to retrieve purgatory list from {env_var} env var." diff --git a/setup.py b/setup.py index efd0c3f7..9c5160eb 100644 --- a/setup.py +++ b/setup.py @@ -94,7 +94,7 @@ url="https://github.com/oceanprotocol/aquarius", # fmt: off # bumpversion needs single quotes - version='5.1.7', + version='5.1.8', # fmt: on zip_safe=False, ) diff --git a/tests/test_purgatory.py b/tests/test_purgatory.py index d5ded2de..0b02475d 100644 --- a/tests/test_purgatory.py +++ b/tests/test_purgatory.py @@ -2,6 +2,7 @@ # Copyright 2023 Ocean Protocol Foundation # SPDX-License-Identifier: Apache-2.0 # +import os from unittest.mock import Mock, patch from freezegun import freeze_time @@ -123,7 +124,9 @@ def test_purgatory_retrieve_new_list(events_object): the_response.status_code = 200 the_response.json.return_value = [{"did": "some_did", "reason": "some_reason"}] mock.return_value = the_response - assert purgatory.retrieve_new_list("env") == {("some_did", "some_reason")} + assert purgatory.retrieve_new_list("ASSET_PURGATORY_URL") == { + ("some_did", "some_reason") + } with patch("requests.get") as mock: the_response = Mock(spec=Response) @@ -132,6 +135,24 @@ def test_purgatory_retrieve_new_list(events_object): assert purgatory.retrieve_new_list("env") == set() +def test_purgatory_retrieve_account_list(events_object, monkeypatch): + # set account purgatory filtering for accounts + monkeypatch.setenv( + "ACCOUNT_PURGATORY_URL", + "https://raw.githubusercontent.com/oceanprotocol/list-purgatory/main/list-accounts.json", + ) + purgatory = Purgatory(events_object._es_instance) + + result = purgatory.retrieve_new_list("ACCOUNT_PURGATORY_URL") + assert result + + filter_by_address = { + x[1] for x in result if x[0] == "0xAD23fC9D943018C34aC55E8DA29AF700A2Fd0FeB" + } + assert len(filter_by_address) == 1 + assert list(filter_by_address)[0] == "bad actor" + + def test_failures(events_object): purgatory = Purgatory(events_object._es_instance) with patch("aquarius.app.es_instance.ElasticsearchInstance.update") as mock: