Skip to content

Commit 56a49eb

Browse files
committed
✅ test(add-wallet): cover password and pin branches
Add router tests for Password and PIN protection selections in add-wallet flow to reduce regressions in wallet setup paths beyond existing NoPassword coverage.
1 parent f431d2c commit 56a49eb

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

bot/tests/routers/test_add_wallet.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
router as add_wallet_router,
77
StateAddWallet,
88
)
9+
from routers.sign import PinState
910
from tests.conftest import (
1011
RouterTestMiddleware,
1112
create_callback_update,
@@ -306,3 +307,60 @@ async def test_add_wallet_no_password_persists_pin_type_zero(
306307
pin_type=0,
307308
)
308309
assert setup_add_wallet_mocks.change_password_uc.execute.await_count == 1
310+
311+
312+
@pytest.mark.asyncio
313+
async def test_add_wallet_password_sets_password_state(
314+
mock_telegram, router_app_context, setup_add_wallet_mocks
315+
):
316+
"""Selecting Password should move flow to password setup state."""
317+
dp = router_app_context.dispatcher
318+
dp.callback_query.middleware(RouterTestMiddleware(router_app_context))
319+
dp.include_router(add_wallet_router)
320+
321+
user_id = 123
322+
state_key = StorageKey(
323+
bot_id=router_app_context.bot.id, chat_id=user_id, user_id=user_id
324+
)
325+
326+
await dp.feed_update(
327+
router_app_context.bot, create_callback_update(user_id, "Password")
328+
)
329+
330+
assert await dp.storage.get_state(state_key) == PinState.ask_password_set
331+
data = await dp.storage.get_data(state_key)
332+
assert data.get("pin_type") == 2
333+
334+
req = get_latest_msg(mock_telegram)
335+
if req is None:
336+
raise AssertionError("Expected send message for password prompt")
337+
assert "send_password" in req["data"]["text"]
338+
339+
340+
@pytest.mark.asyncio
341+
async def test_add_wallet_pin_sets_pin_state(
342+
mock_telegram, router_app_context, setup_add_wallet_mocks
343+
):
344+
"""Selecting PIN should move flow to PIN setup state."""
345+
dp = router_app_context.dispatcher
346+
dp.callback_query.middleware(RouterTestMiddleware(router_app_context))
347+
dp.include_router(add_wallet_router)
348+
349+
user_id = 123
350+
state_key = StorageKey(
351+
bot_id=router_app_context.bot.id, chat_id=user_id, user_id=user_id
352+
)
353+
router_app_context.stellar_service.get_user_account = AsyncMock(
354+
return_value=MagicMock(
355+
account=MagicMock(
356+
account_id="GDLTH4KKMA4R2JGKA7XKI5DLHJBUT42D5RHVK6SS6YHZZLHVLCWJAYXI"
357+
)
358+
)
359+
)
360+
await dp.storage.set_data(state_key, {"user_lang": "en"})
361+
362+
await dp.feed_update(router_app_context.bot, create_callback_update(user_id, "PIN"))
363+
364+
assert await dp.storage.get_state(state_key) == PinState.set_pin
365+
data = await dp.storage.get_data(state_key)
366+
assert data.get("pin_type") == 1

0 commit comments

Comments
 (0)