remove bleskomat (#1521)
This commit is contained in:
parent
c49b68600e
commit
451c8f7a9e
19 changed files with 0 additions and 1677 deletions
|
|
@ -1,66 +0,0 @@
|
|||
import json
|
||||
import secrets
|
||||
|
||||
import pytest_asyncio
|
||||
|
||||
from lnbits.core.crud import create_account, create_wallet
|
||||
from lnbits.extensions.bleskomat.crud import create_bleskomat, create_bleskomat_lnurl
|
||||
from lnbits.extensions.bleskomat.exchange_rates import exchange_rate_providers
|
||||
from lnbits.extensions.bleskomat.helpers import (
|
||||
generate_bleskomat_lnurl_secret,
|
||||
generate_bleskomat_lnurl_signature,
|
||||
prepare_lnurl_params,
|
||||
query_to_signing_payload,
|
||||
)
|
||||
from lnbits.extensions.bleskomat.models import CreateBleskomat
|
||||
|
||||
exchange_rate_providers["dummy"] = {
|
||||
"name": "dummy",
|
||||
"domain": None,
|
||||
"api_url": None,
|
||||
"getter": lambda data, replacements: str(1e8), # 1 BTC = 100000000 sats
|
||||
}
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def bleskomat():
|
||||
user = await create_account()
|
||||
wallet = await create_wallet(user_id=user.id, wallet_name="bleskomat_test")
|
||||
data = CreateBleskomat(
|
||||
name="Test Bleskomat",
|
||||
fiat_currency="EUR",
|
||||
exchange_rate_provider="dummy",
|
||||
fee="0",
|
||||
)
|
||||
bleskomat = await create_bleskomat(data=data, wallet_id=wallet.id)
|
||||
return bleskomat
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def lnurl(bleskomat):
|
||||
query = {
|
||||
"tag": "withdrawRequest",
|
||||
"nonce": secrets.token_hex(10),
|
||||
"tag": "withdrawRequest",
|
||||
"minWithdrawable": "50000",
|
||||
"maxWithdrawable": "50000",
|
||||
"defaultDescription": "test valid sig",
|
||||
}
|
||||
tag = query["tag"]
|
||||
params = prepare_lnurl_params(tag, query)
|
||||
payload = query_to_signing_payload(query)
|
||||
signature = generate_bleskomat_lnurl_signature(
|
||||
payload=payload,
|
||||
api_key_secret=bleskomat.api_key_secret,
|
||||
api_key_encoding=bleskomat.api_key_encoding,
|
||||
)
|
||||
secret = generate_bleskomat_lnurl_secret(bleskomat.api_key_id, signature)
|
||||
params = json.JSONEncoder().encode(params)
|
||||
lnurl = await create_bleskomat_lnurl(
|
||||
bleskomat=bleskomat, secret=secret, tag=tag, params=params, uses=1
|
||||
)
|
||||
return {
|
||||
"bleskomat": bleskomat,
|
||||
"lnurl": lnurl,
|
||||
"secret": secret,
|
||||
}
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
import secrets
|
||||
|
||||
import pytest
|
||||
|
||||
from lnbits.core.crud import get_wallet
|
||||
from lnbits.extensions.bleskomat.crud import get_bleskomat_lnurl
|
||||
from lnbits.extensions.bleskomat.helpers import (
|
||||
generate_bleskomat_lnurl_signature,
|
||||
query_to_signing_payload,
|
||||
)
|
||||
from lnbits.settings import get_wallet_class, settings
|
||||
from tests.helpers import credit_wallet, is_regtest
|
||||
|
||||
WALLET = get_wallet_class()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bleskomat_lnurl_api_missing_secret(client):
|
||||
response = await client.get("/bleskomat/u")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ERROR", "reason": "Missing secret"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bleskomat_lnurl_api_invalid_secret(client):
|
||||
response = await client.get("/bleskomat/u?k1=invalid-secret")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ERROR", "reason": "Invalid secret"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bleskomat_lnurl_api_unknown_api_key(client):
|
||||
query = {
|
||||
"id": "does-not-exist",
|
||||
"nonce": secrets.token_hex(10),
|
||||
"tag": "withdrawRequest",
|
||||
"minWithdrawable": "1",
|
||||
"maxWithdrawable": "1",
|
||||
"defaultDescription": "",
|
||||
"f": "EUR",
|
||||
}
|
||||
payload = query_to_signing_payload(query)
|
||||
signature = "xxx" # not checked, so doesn't matter
|
||||
response = await client.get(f"/bleskomat/u?{payload}&signature={signature}")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ERROR", "reason": "Unknown API key"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bleskomat_lnurl_api_invalid_signature(client, bleskomat):
|
||||
query = {
|
||||
"id": bleskomat.api_key_id,
|
||||
"nonce": secrets.token_hex(10),
|
||||
"tag": "withdrawRequest",
|
||||
"minWithdrawable": "1",
|
||||
"maxWithdrawable": "1",
|
||||
"defaultDescription": "",
|
||||
"f": "EUR",
|
||||
}
|
||||
payload = query_to_signing_payload(query)
|
||||
signature = "invalid"
|
||||
response = await client.get(f"/bleskomat/u?{payload}&signature={signature}")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ERROR", "reason": "Invalid API key signature"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bleskomat_lnurl_api_valid_signature(client, bleskomat):
|
||||
query = {
|
||||
"id": bleskomat.api_key_id,
|
||||
"nonce": secrets.token_hex(10),
|
||||
"tag": "withdrawRequest",
|
||||
"minWithdrawable": "1",
|
||||
"maxWithdrawable": "1",
|
||||
"defaultDescription": "test valid sig",
|
||||
"f": "EUR", # tests use the dummy exchange rate provider
|
||||
}
|
||||
payload = query_to_signing_payload(query)
|
||||
signature = generate_bleskomat_lnurl_signature(
|
||||
payload=payload,
|
||||
api_key_secret=bleskomat.api_key_secret,
|
||||
api_key_encoding=bleskomat.api_key_encoding,
|
||||
)
|
||||
response = await client.get(f"/bleskomat/u?{payload}&signature={signature}")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["tag"] == "withdrawRequest"
|
||||
assert data["minWithdrawable"] == 1000
|
||||
assert data["maxWithdrawable"] == 1000
|
||||
assert data["defaultDescription"] == "test valid sig"
|
||||
assert data["callback"] == f"http://{settings.host}:{settings.port}/bleskomat/u"
|
||||
k1 = data["k1"]
|
||||
lnurl = await get_bleskomat_lnurl(secret=k1)
|
||||
assert lnurl
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.skipif(is_regtest, reason="this test is only passes in fakewallet")
|
||||
async def test_bleskomat_lnurl_api_action_insufficient_balance(client, lnurl):
|
||||
bleskomat = lnurl["bleskomat"]
|
||||
secret = lnurl["secret"]
|
||||
pr = "lntb500n1pseq44upp5xqd38rgad72lnlh4gl339njlrsl3ykep82j6gj4g02dkule7k54qdqqcqzpgxqyz5vqsp5h0zgewuxdxcl2rnlumh6g520t4fr05rgudakpxm789xgjekha75s9qyyssq5vhwsy9knhfeqg0wn6hcnppwmum8fs3g3jxkgw45havgfl6evchjsz3s8e8kr6eyacz02szdhs7v5lg0m7wehd5rpf6yg8480cddjlqpae52xu"
|
||||
WALLET.pay_invoice.reset_mock()
|
||||
response = await client.get(f"/bleskomat/u?k1={secret}&pr={pr}")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "ERROR"
|
||||
assert ("Insufficient balance" in response.json()["reason"]) or (
|
||||
"fee" in response.json()["reason"]
|
||||
)
|
||||
wallet = await get_wallet(bleskomat.wallet)
|
||||
assert wallet, not None
|
||||
assert wallet.balance_msat == 0
|
||||
bleskomat_lnurl = await get_bleskomat_lnurl(secret)
|
||||
assert bleskomat_lnurl, not None
|
||||
assert bleskomat_lnurl.has_uses_remaining() is True
|
||||
WALLET.pay_invoice.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.skipif(is_regtest, reason="this test is only passes in fakewallet")
|
||||
async def test_bleskomat_lnurl_api_action_success(client, lnurl):
|
||||
bleskomat = lnurl["bleskomat"]
|
||||
secret = lnurl["secret"]
|
||||
pr = "lntb500n1pseq44upp5xqd38rgad72lnlh4gl339njlrsl3ykep82j6gj4g02dkule7k54qdqqcqzpgxqyz5vqsp5h0zgewuxdxcl2rnlumh6g520t4fr05rgudakpxm789xgjekha75s9qyyssq5vhwsy9knhfeqg0wn6hcnppwmum8fs3g3jxkgw45havgfl6evchjsz3s8e8kr6eyacz02szdhs7v5lg0m7wehd5rpf6yg8480cddjlqpae52xu"
|
||||
await credit_wallet(
|
||||
wallet_id=bleskomat.wallet,
|
||||
amount=100000,
|
||||
)
|
||||
wallet = await get_wallet(bleskomat.wallet)
|
||||
assert wallet, not None
|
||||
assert wallet.balance_msat == 100000
|
||||
WALLET.pay_invoice.reset_mock()
|
||||
response = await client.get(f"/bleskomat/u?k1={secret}&pr={pr}")
|
||||
assert response.json() == {"status": "OK"}
|
||||
wallet = await get_wallet(bleskomat.wallet)
|
||||
assert wallet, not None
|
||||
assert wallet.balance_msat == 50000
|
||||
bleskomat_lnurl = await get_bleskomat_lnurl(secret)
|
||||
assert bleskomat_lnurl, not None
|
||||
assert bleskomat_lnurl.has_uses_remaining() is False
|
||||
WALLET.pay_invoice.assert_called_once_with(pr, 2000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue