Skip to content

Commit

Permalink
Filtering accounts purgatory (#1093)
Browse files Browse the repository at this point in the history
* Added functionality and test.

* Modify quotes type.

* Convert to monkeypatch.

* black.

* Updated test.

* Updated test.

* Updated tuple indices.

* Bump version v5.1.7 -> v5.1.8.
  • Loading branch information
mariacarmina authored Jan 17, 2024
1 parent 84a560e commit 131a9be
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 5.1.7
current_version = 5.1.8
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion aquarius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
__author__ = """OceanProtocol"""
# fmt: off
# bumpversion needs single quotes
__version__ = '5.1.7'
__version__ = '5.1.8'
# fmt: on
15 changes: 11 additions & 4 deletions aquarius/events/purgatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {...('<did>', '<reason>'),...}
"""
response = requests.get(os.getenv(env_var), timeout=5)
Expand All @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
23 changes: 22 additions & 1 deletion tests/test_purgatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 131a9be

Please sign in to comment.