Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file added tests/core/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -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,
)
Empty file added tests/miner/__init__.py
Empty file.
22 changes: 2 additions & 20 deletions tests/test_fulfillment.py → tests/miner/test_fulfillment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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):
Expand Down
Empty file added tests/validator/__init__.py
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down