-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from BoltzExchange/feat/e2e-tests
feat: e2e tests
- Loading branch information
Showing
15 changed files
with
406 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from warnings import filterwarnings | ||
from telegram.warnings import PTBUserWarning | ||
|
||
# this has to run before we import the command handlers | ||
filterwarnings( | ||
action="ignore", message=r".*CallbackQueryHandler", category=PTBUserWarning | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import asyncpg | ||
import pytest_asyncio | ||
from sqlalchemy import make_url | ||
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker | ||
|
||
from db import Base | ||
from settings import Settings | ||
|
||
|
||
@pytest_asyncio.fixture(scope="session") | ||
async def test_db_url(): | ||
settings = Settings() | ||
url = make_url(settings.database_url) | ||
conn = await asyncpg.connect( | ||
url.set(drivername="postgresql").render_as_string(False) | ||
) | ||
test_db = "fees_test" | ||
await conn.execute(f"DROP DATABASE IF EXISTS {test_db}") | ||
await conn.execute(f"CREATE DATABASE {test_db}") | ||
await conn.close() | ||
return url.set(database=test_db).render_as_string(hide_password=False) | ||
|
||
|
||
@pytest_asyncio.fixture(scope="session") | ||
async def db_session(test_db_url): | ||
engine = create_async_engine(test_db_url) | ||
async with engine.begin() as conn: | ||
await conn.run_sync(Base.metadata.create_all) | ||
async_session = async_sessionmaker(engine, expire_on_commit=False) | ||
async with async_session() as session: | ||
yield session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
from pydantic import Field | ||
from pydantic import Field, ConfigDict | ||
from pydantic_settings import BaseSettings | ||
|
||
|
||
class Settings(BaseSettings): | ||
telegram_bot_token: str = Field( | ||
..., env="TELEGRAM_BOT_TOKEN", description="Telegram bot token" | ||
) | ||
check_interval: int = Field( | ||
60, env="CHECK_INTERVAL", description="Interval to check API (seconds)" | ||
) | ||
telegram_bot_token: str = Field(..., description="Telegram bot token") | ||
check_interval: int = Field(60, description="Interval to check API (seconds)") | ||
api_url: str = Field( | ||
"https://api.boltz.exchange", | ||
env="API_URL", | ||
description="Boltz API URL for submarine swaps", | ||
) | ||
database_url: str = Field( | ||
env="DATABASE_URL", | ||
description="Database URL for PostgreSQL", | ||
) | ||
|
||
class Config: | ||
env_file = ".env" | ||
env_file_encoding = "utf-8" | ||
model_config = ConfigDict( | ||
env_file=".env", | ||
extra="allow", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import subprocess | ||
from typing import Optional | ||
|
||
import pytest | ||
import pytest_asyncio | ||
from telethon.tl.custom import Conversation | ||
|
||
from telethon import TelegramClient | ||
from telethon.sessions import StringSession | ||
|
||
from settings import Settings | ||
|
||
|
||
@pytest_asyncio.fixture(autouse=True, scope="session") | ||
def bot(test_db_url): | ||
"""Start bot to be tested.""" | ||
os.environ["DATABASE_URL"] = test_db_url | ||
process = subprocess.Popen( | ||
["uv", "run", "bot.py"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
env=os.environ, | ||
) | ||
yield | ||
process.terminate() | ||
process.wait() | ||
|
||
|
||
class TestSettings(Settings): | ||
test_api_id: int | ||
test_api_hash: str | ||
test_api_session: Optional[str] | ||
test_bot_name: str | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def test_settings(): | ||
return TestSettings() | ||
|
||
|
||
@pytest_asyncio.fixture(scope="session") | ||
async def telegram_client(test_settings): | ||
"""Connect to Telegram user for testing.""" | ||
|
||
client = TelegramClient( | ||
StringSession(test_settings.test_api_session), | ||
test_settings.test_api_id, | ||
test_settings.test_api_hash, | ||
sequential_updates=True, | ||
) | ||
await client.connect() | ||
await client.get_me() | ||
await client.get_dialogs() | ||
|
||
yield client | ||
|
||
await client.disconnect() | ||
|
||
|
||
@pytest_asyncio.fixture(scope="session") | ||
async def conv(telegram_client: TelegramClient, test_settings) -> Conversation: | ||
"""Open conversation with the bot.""" | ||
async with telegram_client.conversation( | ||
f"@{test_settings.test_bot_name}", timeout=3, max_messages=10000 | ||
) as conv: | ||
yield conv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from telethon import TelegramClient | ||
from telethon.sessions import StringSession | ||
|
||
from tests.e2e.conftest import TestSettings | ||
|
||
settings = TestSettings() | ||
|
||
|
||
with TelegramClient( | ||
StringSession(), settings.test_api_id, settings.test_api_hash | ||
) as client: | ||
print("Session string:", client.session.save()) |
Oops, something went wrong.