From 291e0f4da4b0a3b7f97aff0bfbfffa2b65d4da24 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Thu, 3 Apr 2025 12:45:46 +0100 Subject: [PATCH] refactor: class based slot module --- crypto/utils/slot.py | 29 +++++++++++++++-------------- tests/utils/test_slot.py | 8 +++----- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/crypto/utils/slot.py b/crypto/utils/slot.py index 23b3d080..465f0f73 100644 --- a/crypto/utils/slot.py +++ b/crypto/utils/slot.py @@ -2,19 +2,20 @@ from crypto.configuration.network import get_network +class Slot: + @staticmethod + def time(): + """Get the time difference between now and network start. -def get_time(): - """Get the time difference between now and network start. + Returns: + int: difference in seconds + """ + now = datetime.utcnow() + network = get_network() + seconds = int((now - network['epoch']).total_seconds()) + return seconds - Returns: - int: difference in seconds - """ - now = datetime.utcnow() - network = get_network() - seconds = int((now - network['epoch']).total_seconds()) - return seconds - - -def get_epoch(): - network = get_network() - return network['epoch'] + @staticmethod + def epoch(): + network = get_network() + return network['epoch'] diff --git a/tests/utils/test_slot.py b/tests/utils/test_slot.py index fa17037a..7068fa23 100644 --- a/tests/utils/test_slot.py +++ b/tests/utils/test_slot.py @@ -1,13 +1,11 @@ from datetime import datetime -from crypto.utils.slot import get_epoch, get_time - +from crypto.utils.slot import Slot def test_get_epoch(): - result = get_epoch() + result = Slot.epoch() assert isinstance(result, datetime) - def test_get_time(): - result = get_time() + result = Slot.time() assert isinstance(result, int)