diff --git a/safe_transaction_service/account_abstraction/constants.py b/safe_transaction_service/account_abstraction/constants.py index 375ef827c..0a39d203c 100644 --- a/safe_transaction_service/account_abstraction/constants.py +++ b/safe_transaction_service/account_abstraction/constants.py @@ -17,6 +17,7 @@ from hexbytes import HexBytes +USER_OPERATION_NUMBER_TOPICS = 4 USER_OPERATION_EVENT_TOPICS = { HexBytes("0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f") } diff --git a/safe_transaction_service/account_abstraction/exceptions.py b/safe_transaction_service/account_abstraction/exceptions.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/safe_transaction_service/account_abstraction/services/aa_processor_service.py b/safe_transaction_service/account_abstraction/services/aa_processor_service.py index 8f73255c2..c1c92967e 100644 --- a/safe_transaction_service/account_abstraction/services/aa_processor_service.py +++ b/safe_transaction_service/account_abstraction/services/aa_processor_service.py @@ -22,7 +22,7 @@ from safe_transaction_service.history import models as history_models -from ..constants import USER_OPERATION_EVENT_TOPICS +from ..constants import USER_OPERATION_EVENT_TOPICS, USER_OPERATION_NUMBER_TOPICS from ..models import SafeOperation as SafeOperationModel from ..models import SafeOperationConfirmation as SafeOperationConfirmationModel from ..models import UserOperation as UserOperationModel @@ -86,7 +86,7 @@ def get_user_operation_logs( log for log in logs if ( - len(log["topics"]) == 4 + len(log["topics"]) == USER_OPERATION_NUMBER_TOPICS and HexBytes(log["topics"][0]) in USER_OPERATION_EVENT_TOPICS and fast_to_checksum_address(log["address"]) in self.supported_entry_points # Only index supported entryPoints diff --git a/safe_transaction_service/account_abstraction/tests/test_views.py b/safe_transaction_service/account_abstraction/tests/test_views.py index 2b15e23a1..840c07235 100644 --- a/safe_transaction_service/account_abstraction/tests/test_views.py +++ b/safe_transaction_service/account_abstraction/tests/test_views.py @@ -1,4 +1,3 @@ -import datetime import logging from unittest import mock from unittest.mock import MagicMock @@ -25,20 +24,14 @@ from gnosis.safe.safe_signature import SafeSignatureEOA from gnosis.safe.tests.safe_test_case import SafeTestCaseMixin +from safe_transaction_service.utils.utils import datetime_to_str + from .. import models from . import factories logger = logging.getLogger(__name__) -# FIXME Refactor datetime_to_str -def datetime_to_str(value: datetime.datetime) -> str: - value = value.isoformat() - if value.endswith("+00:00"): - value = value[:-6] + "Z" - return value - - class TestAccountAbstractionViews(SafeTestCaseMixin, APITestCase): def test_safe_operation_view(self): random_safe_operation_hash = ( diff --git a/safe_transaction_service/safe_messages/tests/test_views.py b/safe_transaction_service/safe_messages/tests/test_views.py index 9ecb5e904..466b2eb5c 100644 --- a/safe_transaction_service/safe_messages/tests/test_views.py +++ b/safe_transaction_service/safe_messages/tests/test_views.py @@ -1,4 +1,3 @@ -import datetime import logging from unittest import mock from unittest.mock import MagicMock @@ -26,19 +25,13 @@ SafeMessageConfirmationFactory, SafeMessageFactory, ) +from safe_transaction_service.utils.utils import datetime_to_str from .mocks import get_eip712_payload_mock logger = logging.getLogger(__name__) -def datetime_to_str(value: datetime.datetime) -> str: - value = value.isoformat() - if value.endswith("+00:00"): - value = value[:-6] + "Z" - return value - - class TestMessageViews(SafeTestCaseMixin, APITestCase): def test_safe_message_view(self): random_safe_message_hash = ( diff --git a/safe_transaction_service/utils/utils.py b/safe_transaction_service/utils/utils.py index abe971d6f..746556287 100644 --- a/safe_transaction_service/utils/utils.py +++ b/safe_transaction_service/utils/utils.py @@ -1,3 +1,4 @@ +import datetime import socket from functools import wraps from itertools import islice @@ -80,3 +81,14 @@ def wrapper(*args, **kwargs): def parse_boolean_query_param(value: Union[bool, str, int]) -> bool: return value in (True, "True", "true", "1", 1) + + +def datetime_to_str(value: datetime.datetime) -> str: + """ + :param value: `datetime.datetime` value + :return: ``ISO 8601`` date with ``Z`` format + """ + value = value.isoformat() + if value.endswith("+00:00"): + value = value[:-6] + "Z" + return value