Skip to content

Commit

Permalink
Refactor datetime_to_str to utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Mar 25, 2024
1 parent 4ce87c9 commit f8657d8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions safe_transaction_service/account_abstraction/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from hexbytes import HexBytes

USER_OPERATION_NUMBER_TOPICS = 4
USER_OPERATION_EVENT_TOPICS = {
HexBytes("0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f")
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions safe_transaction_service/account_abstraction/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import logging
from unittest import mock
from unittest.mock import MagicMock
Expand All @@ -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 = (
Expand Down
9 changes: 1 addition & 8 deletions safe_transaction_service/safe_messages/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import logging
from unittest import mock
from unittest.mock import MagicMock
Expand Down Expand Up @@ -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 = (
Expand Down
12 changes: 12 additions & 0 deletions safe_transaction_service/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import socket
from functools import wraps
from itertools import islice
Expand Down Expand Up @@ -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

0 comments on commit f8657d8

Please sign in to comment.