mirror of https://github.com/nucypher/nucypher.git
Stop using deprecated datetime methods.
parent
cfef6c1a8f
commit
007fdeb9fc
|
@ -2,7 +2,7 @@
|
|||
|
||||
import functools
|
||||
import inspect
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Callable, Optional, TypeVar, Union
|
||||
|
||||
import eth_utils
|
||||
|
@ -111,7 +111,7 @@ def save_receipt(actor_method) -> Callable: # TODO: rename to "save_result"?
|
|||
@functools.wraps(actor_method)
|
||||
def wrapped(self, *args, **kwargs) -> dict:
|
||||
receipt_or_txhash = actor_method(self, *args, **kwargs)
|
||||
self._saved_receipts.append((datetime.utcnow(), receipt_or_txhash))
|
||||
self._saved_receipts.append((datetime.now(timezone.utc), receipt_or_txhash))
|
||||
return receipt_or_txhash
|
||||
return wrapped
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ def generate_self_signed_certificate(
|
|||
private_key = ec.generate_private_key(curve(), default_backend())
|
||||
public_key = private_key.public_key()
|
||||
|
||||
now = datetime.datetime.utcnow()
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
fields = [x509.NameAttribute(NameOID.COMMON_NAME, host)]
|
||||
|
||||
subject = issuer = x509.Name(fields)
|
||||
|
|
|
@ -188,7 +188,7 @@ class EventScanner:
|
|||
# minor chain reorganisation?
|
||||
return None
|
||||
last_time = block_info["timestamp"]
|
||||
return datetime.datetime.utcfromtimestamp(last_time)
|
||||
return datetime.datetime.fromtimestamp(last_time, tz=datetime.timezone.utc)
|
||||
|
||||
def get_suggested_scan_start_block(self):
|
||||
"""Get where we should start to scan for new token events.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import math
|
||||
import time
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Tuple
|
||||
from unittest.mock import MagicMock, Mock
|
||||
|
||||
|
@ -112,12 +112,14 @@ def test_get_block_timestamp():
|
|||
|
||||
now = time.time()
|
||||
web3.eth.get_block.return_value = {"timestamp": now}
|
||||
assert scanner.get_block_timestamp(block_num=0) == datetime.utcfromtimestamp(now)
|
||||
assert scanner.get_block_timestamp(block_num=0) == datetime.fromtimestamp(
|
||||
now, tz=timezone.utc
|
||||
)
|
||||
|
||||
other_time = time.time() - 1231231
|
||||
web3.eth.get_block.return_value = {"timestamp": other_time}
|
||||
assert scanner.get_block_timestamp(block_num=21) == datetime.utcfromtimestamp(
|
||||
other_time
|
||||
assert scanner.get_block_timestamp(block_num=21) == datetime.fromtimestamp(
|
||||
other_time, tz=timezone.utc
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue