diff --git a/tests/chain_providers/__init__.py b/tests/chain_providers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_bitcoin_signing.py b/tests/chain_providers/test_bitcoin_signing.py similarity index 100% rename from tests/test_bitcoin_signing.py rename to tests/chain_providers/test_bitcoin_signing.py diff --git a/tests/core/__init__.py b/tests/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_chains.py b/tests/core/test_chains.py similarity index 100% rename from tests/test_chains.py rename to tests/core/test_chains.py diff --git a/tests/test_commitments.py b/tests/core/test_commitments.py similarity index 100% rename from tests/test_commitments.py rename to tests/core/test_commitments.py diff --git a/tests/test_rate.py b/tests/core/test_rate.py similarity index 100% rename from tests/test_rate.py rename to tests/core/test_rate.py diff --git a/tests/test_scale.py b/tests/core/test_scale.py similarity index 100% rename from tests/test_scale.py rename to tests/core/test_scale.py diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 0000000..6dd8a9b --- /dev/null +++ b/tests/helpers.py @@ -0,0 +1,34 @@ +"""Shared test factories and constants used across multiple test modules.""" + +from pathlib import Path + +from allways.classes import Swap, SwapStatus + +METADATA_PATH = Path(__file__).parent.parent / 'allways' / 'metadata' / 'allways_swap_manager.json' + + +def make_swap( + swap_id: int = 1, + miner_hotkey: str = 'miner', + timeout_block: int = 500, + rate: str = '345', + miner_from: str = 'bc1q-miner', +) -> Swap: + """Swap factory covering both validator and miner test contexts.""" + return Swap( + id=swap_id, + user_hotkey='user', + miner_hotkey=miner_hotkey, + from_chain='btc', + to_chain='tao', + from_amount=1_000_000, + to_amount=345_000_000, + tao_amount=345_000_000, + user_from_address='bc1q-user', + user_to_address='5user', + miner_from_address=miner_from, + rate=rate, + status=SwapStatus.ACTIVE, + initiated_block=100, + timeout_block=timeout_block, + ) diff --git a/tests/miner/__init__.py b/tests/miner/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_fulfillment.py b/tests/miner/test_fulfillment.py similarity index 90% rename from tests/test_fulfillment.py rename to tests/miner/test_fulfillment.py index ae3f0f1..d8e7e17 100644 --- a/tests/test_fulfillment.py +++ b/tests/miner/test_fulfillment.py @@ -11,10 +11,11 @@ import pytest -from allways.classes import Swap, SwapStatus from allways.constants import DEFAULT_MINER_TIMEOUT_CUSHION_BLOCKS from allways.miner.fulfillment import SwapFulfiller, load_timeout_cushion_blocks +from tests.helpers import make_swap + def make_fulfiller(cushion_env: str | None = None) -> SwapFulfiller: """Build a SwapFulfiller with mocked deps. Optionally seed the env var.""" @@ -32,25 +33,6 @@ def make_fulfiller(cushion_env: str | None = None) -> SwapFulfiller: ) -def make_swap(timeout_block: int = 500, rate: str = '345', miner_from: str = 'bc1q-miner') -> Swap: - return Swap( - id=1, - user_hotkey='user', - miner_hotkey='miner', - from_chain='btc', - to_chain='tao', - from_amount=1_000_000, - to_amount=345_000_000, - tao_amount=345_000_000, - user_from_address='bc1q-user', - user_to_address='5user', - miner_from_address=miner_from, - rate=rate, - status=SwapStatus.ACTIVE, - initiated_block=100, - timeout_block=timeout_block, - ) - class TestLoadTimeoutCushionBlocks: def test_unset_env_returns_default(self): diff --git a/tests/validator/__init__.py b/tests/validator/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_axon_handlers.py b/tests/validator/test_axon_handlers.py similarity index 100% rename from tests/test_axon_handlers.py rename to tests/validator/test_axon_handlers.py diff --git a/tests/test_event_watcher.py b/tests/validator/test_event_watcher.py similarity index 99% rename from tests/test_event_watcher.py rename to tests/validator/test_event_watcher.py index 17e59cf..3ed605b 100644 --- a/tests/test_event_watcher.py +++ b/tests/validator/test_event_watcher.py @@ -23,7 +23,7 @@ ) from allways.validator.state_store import ValidatorStateStore -METADATA_PATH = Path(__file__).parent.parent / 'allways' / 'metadata' / 'allways_swap_manager.json' +from tests.helpers import METADATA_PATH # Well-known test SS58 — Alice from the substrate dev keyring. Used as # contract_address in fixtures so the decoder's address comparison doesn't diff --git a/tests/test_pending_confirm_queue.py b/tests/validator/test_pending_confirm_queue.py similarity index 100% rename from tests/test_pending_confirm_queue.py rename to tests/validator/test_pending_confirm_queue.py diff --git a/tests/test_poll_commitments.py b/tests/validator/test_poll_commitments.py similarity index 100% rename from tests/test_poll_commitments.py rename to tests/validator/test_poll_commitments.py diff --git a/tests/test_rate_state.py b/tests/validator/test_rate_state.py similarity index 100% rename from tests/test_rate_state.py rename to tests/validator/test_rate_state.py diff --git a/tests/test_scoring_v1.py b/tests/validator/test_scoring_v1.py similarity index 99% rename from tests/test_scoring_v1.py rename to tests/validator/test_scoring_v1.py index 33f54fb..3406619 100644 --- a/tests/test_scoring_v1.py +++ b/tests/validator/test_scoring_v1.py @@ -17,12 +17,12 @@ ) from allways.validator.state_store import ValidatorStateStore +from tests.helpers import METADATA_PATH + POOL_TAO_BTC = 0.04 POOL_BTC_TAO = 0.04 MIN_COLLATERAL = 100_000_000 # 0.1 TAO -METADATA_PATH = Path(__file__).parent.parent / 'allways' / 'metadata' / 'allways_swap_manager.json' - def make_metagraph(hotkeys: list[str]) -> SimpleNamespace: n = SimpleNamespace(item=lambda: len(hotkeys)) diff --git a/tests/test_swap_tracker.py b/tests/validator/test_swap_tracker.py similarity index 95% rename from tests/test_swap_tracker.py rename to tests/validator/test_swap_tracker.py index 321dee3..3f6510e 100644 --- a/tests/test_swap_tracker.py +++ b/tests/validator/test_swap_tracker.py @@ -10,26 +10,10 @@ import asyncio from unittest.mock import MagicMock -from allways.classes import Swap, SwapStatus +from allways.classes import SwapStatus from allways.validator.swap_tracker import NULL_SWAP_RETRY_LIMIT, SwapTracker - -def make_swap(swap_id: int, miner_hotkey: str = 'hk_a', timeout_block: int = 500) -> Swap: - return Swap( - id=swap_id, - user_hotkey='user', - miner_hotkey=miner_hotkey, - from_chain='btc', - to_chain='tao', - from_amount=100_000, - to_amount=500_000_000, - tao_amount=500_000_000, - user_from_address='bc1q-user', - user_to_address='5user', - status=SwapStatus.ACTIVE, - initiated_block=100, - timeout_block=timeout_block, - ) +from tests.helpers import make_swap def make_tracker() -> SwapTracker: