mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-10 12:32:34 +02:00
Automated tests (#566)
* return error for wrong key * payment check use key dependency * more expressive error * re-add optional key * more tests * more * more granular * more testing * custom event_loop * tests work * fix lots of mypy errors * test_public_api * both files * remove unused import * tests * tests working * rm empty file * minimal test * set FAKE_WALLET_SECRET="ToTheMoon1" * set FAKE_WALLET_SECRET="ToTheMoon1" * trial and error * trial and error * test postgres * test postgres * test postgres * test postgres * test postgres * test postgres * test build * skip mypy
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import time
|
||||
from mock import AsyncMock
|
||||
from lnbits import bolt11
|
||||
from lnbits.wallets.base import (
|
||||
@@ -9,20 +10,51 @@ from lnbits.wallets.base import (
|
||||
)
|
||||
from lnbits.settings import WALLET
|
||||
|
||||
from lnbits.wallets.fake import FakeWallet
|
||||
|
||||
from .helpers import get_random_string
|
||||
|
||||
# primitive event loop for generate_mock_invoice()
|
||||
def drive(c):
|
||||
while True:
|
||||
try:
|
||||
c.send(None)
|
||||
except StopIteration as e:
|
||||
return e.value
|
||||
|
||||
|
||||
# generates an invoice with FakeWallet
|
||||
async def generate_mock_invoice(**x):
|
||||
invoice = await FakeWallet.create_invoice(
|
||||
FakeWallet(), amount=10, memo=f"mock invoice {get_random_string()}"
|
||||
)
|
||||
return invoice
|
||||
|
||||
|
||||
WALLET.status = AsyncMock(
|
||||
return_value=StatusResponse(
|
||||
"", # no error
|
||||
1000000, # msats
|
||||
)
|
||||
)
|
||||
WALLET.create_invoice = AsyncMock(
|
||||
return_value=InvoiceResponse(
|
||||
True, # ok
|
||||
"6621aafbdd7709ca6eea6203f362d64bd7cb2911baa91311a176b3ecaf2274bd", # checking_id (i.e. payment_hash)
|
||||
"lntb1u1psezhgspp5vcs6477awuyu5mh2vgplxckkf0tuk2g3h253xydpw6e7etezwj7sdqqcqzpgxqyz5vqsp5dxpw8zs77hw5pla4wz4mfujllyxtlpu443auur2uxqdrs8q2h56q9qyyssq65zk30ylmygvv5y4tuwalnf3ttnqjn57ef6rmcqg0s53akem560jh8ptemjcmytn3lrlatw4hv9smg88exv3v4f4lqnp96s0psdrhxsp6pp75q", # payment_request
|
||||
"", # no error
|
||||
)
|
||||
)
|
||||
|
||||
WALLET.create_invoice = generate_mock_invoice
|
||||
|
||||
# NOTE: This mock fails since it yields the same invoice multiple
|
||||
# times which makes the db throw an error due to uniqueness contraints
|
||||
# on the checking ID
|
||||
|
||||
# # finally we await it
|
||||
# invoice = drive(generate_mock_invoice())
|
||||
|
||||
# WALLET.create_invoice = AsyncMock(
|
||||
# return_value=InvoiceResponse(
|
||||
# True, # ok
|
||||
# invoice.checking_id, # checking_id (i.e. payment_hash)
|
||||
# invoice.payment_request, # payment_request
|
||||
# "", # no error
|
||||
# )
|
||||
# )
|
||||
|
||||
|
||||
def pay_invoice_side_effect(
|
||||
|
Reference in New Issue
Block a user