From f096b51f70d7807aabad109a4395ae9431d912b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 7 Aug 2023 21:49:37 +0200 Subject: [PATCH] [TEST] proper credit_wallet function from services (#1862) --- tests/conftest.py | 12 ++++-------- tests/helpers.py | 19 ------------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6793edeb..d7056ce3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,15 +8,11 @@ from httpx import AsyncClient from lnbits.app import create_app from lnbits.commands import migrate_databases from lnbits.core.crud import create_account, create_wallet +from lnbits.core.services import update_wallet_balance from lnbits.core.views.api import CreateInvoiceData, api_payments_create_invoice from lnbits.db import Database from lnbits.settings import settings -from tests.helpers import ( - credit_wallet, - get_hold_invoice, - get_random_invoice_data, - get_real_invoice, -) +from tests.helpers import get_hold_invoice, get_random_invoice_data, get_real_invoice @pytest_asyncio.fixture(scope="session") @@ -68,7 +64,7 @@ async def from_user(): async def from_wallet(from_user): user = from_user wallet = await create_wallet(user_id=user.id, wallet_name="test_wallet_from") - await credit_wallet( + await update_wallet_balance( wallet_id=wallet.id, amount=999999999, ) @@ -91,7 +87,7 @@ async def to_user(): async def to_wallet(to_user): user = to_user wallet = await create_wallet(user_id=user.id, wallet_name="test_wallet_to") - await credit_wallet( + await update_wallet_balance( wallet_id=wallet.id, amount=999999999, ) diff --git a/tests/helpers.py b/tests/helpers.py index 767a03bd..15754189 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -2,32 +2,13 @@ import hashlib import json import os import random -import secrets import string from subprocess import PIPE, Popen, run from typing import Tuple -from lnbits.core.crud import create_payment from lnbits.wallets import get_wallet_class, set_wallet_class -async def credit_wallet(wallet_id: str, amount: int): - preimage = secrets.token_hex(32) - m = hashlib.sha256() - m.update(f"{preimage}".encode()) - payment_hash = m.hexdigest() - await create_payment( - wallet_id=wallet_id, - payment_request="", - payment_hash=payment_hash, - checking_id=payment_hash, - preimage=preimage, - memo=f"funding_test_{get_random_string(5)}", - amount=amount, # msat - pending=False, # not pending, so it will increase the wallet's balance - ) - - def get_random_string(N: int = 10): return "".join( random.SystemRandom().choice(string.ascii_uppercase + string.digits)