Skip to content

Commit 131a9be

Browse files
authored
Filtering accounts purgatory (#1093)
* 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.
1 parent 84a560e commit 131a9be

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 5.1.7
2+
current_version = 5.1.8
33
commit = True
44
tag = True
55

aquarius/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
__author__ = """OceanProtocol"""
1010
# fmt: off
1111
# bumpversion needs single quotes
12-
__version__ = '5.1.7'
12+
__version__ = '5.1.8'
1313
# fmt: on

aquarius/events/purgatory.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, es_instance):
2222

2323
def retrieve_new_list(self, env_var):
2424
"""
25-
:param env_var: Url of the file containing purgatory list.
25+
:param env_var: Environment variable name of the file URL containing purgatory list.
2626
:return: Object as follows: {...('<did>', '<reason>'),...}
2727
"""
2828
response = requests.get(os.getenv(env_var), timeout=5)
@@ -31,9 +31,16 @@ def retrieve_new_list(self, env_var):
3131
logger.info(
3232
f"PURGATORY: Successfully retrieved new purgatory list from {env_var} env var."
3333
)
34-
return {
35-
(a["did"], a["reason"]) for a in response.json() if a and "did" in a
36-
}
34+
if env_var == "ASSET_PURGATORY_URL":
35+
return {
36+
(a["did"], a["reason"]) for a in response.json() if a and "did" in a
37+
}
38+
elif env_var == "ACCOUNT_PURGATORY_URL":
39+
return {
40+
(a["address"], a["reason"])
41+
for a in response.json()
42+
if a and "address" in a
43+
}
3744

3845
logger.info(
3946
f"PURGATORY: Failed to retrieve purgatory list from {env_var} env var."

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
url="https://github.com/oceanprotocol/aquarius",
9595
# fmt: off
9696
# bumpversion needs single quotes
97-
version='5.1.7',
97+
version='5.1.8',
9898
# fmt: on
9999
zip_safe=False,
100100
)

tests/test_purgatory.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2023 Ocean Protocol Foundation
33
# SPDX-License-Identifier: Apache-2.0
44
#
5+
import os
56
from unittest.mock import Mock, patch
67

78
from freezegun import freeze_time
@@ -123,7 +124,9 @@ def test_purgatory_retrieve_new_list(events_object):
123124
the_response.status_code = 200
124125
the_response.json.return_value = [{"did": "some_did", "reason": "some_reason"}]
125126
mock.return_value = the_response
126-
assert purgatory.retrieve_new_list("env") == {("some_did", "some_reason")}
127+
assert purgatory.retrieve_new_list("ASSET_PURGATORY_URL") == {
128+
("some_did", "some_reason")
129+
}
127130

128131
with patch("requests.get") as mock:
129132
the_response = Mock(spec=Response)
@@ -132,6 +135,24 @@ def test_purgatory_retrieve_new_list(events_object):
132135
assert purgatory.retrieve_new_list("env") == set()
133136

134137

138+
def test_purgatory_retrieve_account_list(events_object, monkeypatch):
139+
# set account purgatory filtering for accounts
140+
monkeypatch.setenv(
141+
"ACCOUNT_PURGATORY_URL",
142+
"https://raw.githubusercontent.com/oceanprotocol/list-purgatory/main/list-accounts.json",
143+
)
144+
purgatory = Purgatory(events_object._es_instance)
145+
146+
result = purgatory.retrieve_new_list("ACCOUNT_PURGATORY_URL")
147+
assert result
148+
149+
filter_by_address = {
150+
x[1] for x in result if x[0] == "0xAD23fC9D943018C34aC55E8DA29AF700A2Fd0FeB"
151+
}
152+
assert len(filter_by_address) == 1
153+
assert list(filter_by_address)[0] == "bad actor"
154+
155+
135156
def test_failures(events_object):
136157
purgatory = Purgatory(events_object._es_instance)
137158
with patch("aquarius.app.es_instance.ElasticsearchInstance.update") as mock:

0 commit comments

Comments
 (0)