From 5a0b217d635937026fc5767241bc6466d27750ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Thu, 26 Jan 2023 10:43:12 +0100 Subject: [PATCH] TEST: LNbits as fundingsource in regtest (#1402) * lnbits funding source * add create_fake_user to workflow * change quotes in workflow ymal * not use interactive docker exec * update tools/create_fake_admin to not use lnbits imports * formatting Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> --- .dockerignore | 1 - .github/workflows/regtest.yml | 45 +++++++++++++++++++- Dockerfile | 2 +- tools/create_fake_admin.py | 80 +++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 tools/create_fake_admin.py diff --git a/.dockerignore b/.dockerignore index 005f64cc4..edbbf1892 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,7 +4,6 @@ docker docs tests venv -tools lnbits/static/css/* lnbits/static/bundle.js diff --git a/.github/workflows/regtest.yml b/.github/workflows/regtest.yml index 57b7e1f41..eb2630db6 100644 --- a/.github/workflows/regtest.yml +++ b/.github/workflows/regtest.yml @@ -134,6 +134,49 @@ jobs: uses: codecov/codecov-action@v3 with: file: ./coverage.xml + LNbitsWallet: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + poetry-version: ["1.3.1"] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Set up Poetry ${{ matrix.poetry-version }} + uses: abatilo/actions-poetry@v2 + with: + poetry-version: ${{ matrix.poetry-version }} + - name: Setup Regtest + run: | + docker build -t lnbitsdocker/lnbits-legend . + git clone https://github.com/lnbits/legend-regtest-enviroment.git docker + cd docker + chmod +x ./tests + ./tests + sudo chmod -R a+rwx . + docker exec lnbits-legend-lnbits-1 /bin/bash -c "poetry run python tools/create_fake_admin.py" + - name: Install dependencies + run: | + poetry install + - name: Run tests + env: + PYTHONUNBUFFERED: 1 + PORT: 5123 + LNBITS_DATA_FOLDER: ./data + LNBITS_BACKEND_WALLET_CLASS: LNbitsWallet + LNBITS_ENDPOINT: http://localhost:5001 + LNBITS_KEY: "d08a3313322a4514af75d488bcc27eee" + run: | + sudo chmod -R a+rwx . && rm -rf ./data && mkdir -p ./data + make test-real-wallet + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: ./coverage.xml EclairWallet: runs-on: ubuntu-latest strategy: @@ -176,4 +219,4 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: - file: ./coverage.xml + file: ./coverage.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index cc3a14bd7..a7a3be9fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN mkdir -p lnbits/data COPY . . RUN poetry config virtualenvs.create false -RUN poetry install --only main --no-root +RUN poetry install --only main RUN poetry run python build.py ENV LNBITS_PORT="5000" diff --git a/tools/create_fake_admin.py b/tools/create_fake_admin.py new file mode 100644 index 000000000..9edb0529e --- /dev/null +++ b/tools/create_fake_admin.py @@ -0,0 +1,80 @@ +# Python script to create a fake admin user for sqlite3, +# for regtest setup as LNbits funding source + +import os +import sqlite3 +import sys +import time +from uuid import uuid4 + +import shortuuid + +adminkey = "d08a3313322a4514af75d488bcc27eee" +sqfolder = "./data" + +if not sqfolder or not os.path.isdir(sqfolder): + print("missing LNBITS_DATA_FOLDER") + sys.exit(1) + +file = os.path.join(sqfolder, "database.sqlite3") +conn = sqlite3.connect(file) +cursor = conn.cursor() + +old_account = cursor.execute( + "SELECT * FROM accounts WHERE id = ?", (adminkey,) +).fetchone() +if old_account: + print("fake admin does already exist") + sys.exit(1) + + +cursor.execute("INSERT INTO accounts (id) VALUES (?)", (adminkey,)) + +wallet_id = uuid4().hex +cursor.execute( + """ + INSERT INTO wallets (id, name, "user", adminkey, inkey) + VALUES (?, ?, ?, ?, ?) + """, + ( + wallet_id, + "TEST WALLET", + adminkey, + adminkey, + uuid4().hex, # invoice key is not important + ), +) + +expiration_date = time.time() + 420 + +# 1 btc in sats +amount = 100_000_000 +internal_id = f"internal_{shortuuid.uuid()}" + +cursor.execute( + """ + INSERT INTO apipayments + (wallet, checking_id, bolt11, hash, preimage, + amount, pending, memo, fee, extra, webhook, expiry) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, + ( + wallet_id, + internal_id, + "test_admin_internal", + "test_admin_internal", + None, + amount * 1000, + False, + "test_admin_internal", + 0, + None, + "", + expiration_date, + ), +) + +print(f"created test admin: {adminkey} with {amount} sats") + +conn.commit() +cursor.close()