mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-26 20:06:17 +02:00
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>
This commit is contained in:
@@ -4,7 +4,6 @@ docker
|
|||||||
docs
|
docs
|
||||||
tests
|
tests
|
||||||
venv
|
venv
|
||||||
tools
|
|
||||||
|
|
||||||
lnbits/static/css/*
|
lnbits/static/css/*
|
||||||
lnbits/static/bundle.js
|
lnbits/static/bundle.js
|
||||||
|
45
.github/workflows/regtest.yml
vendored
45
.github/workflows/regtest.yml
vendored
@@ -134,6 +134,49 @@ jobs:
|
|||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
file: ./coverage.xml
|
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:
|
EclairWallet:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
@@ -176,4 +219,4 @@ jobs:
|
|||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
file: ./coverage.xml
|
file: ./coverage.xml
|
@@ -13,7 +13,7 @@ RUN mkdir -p lnbits/data
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN poetry config virtualenvs.create false
|
RUN poetry config virtualenvs.create false
|
||||||
RUN poetry install --only main --no-root
|
RUN poetry install --only main
|
||||||
RUN poetry run python build.py
|
RUN poetry run python build.py
|
||||||
|
|
||||||
ENV LNBITS_PORT="5000"
|
ENV LNBITS_PORT="5000"
|
||||||
|
80
tools/create_fake_admin.py
Normal file
80
tools/create_fake_admin.py
Normal file
@@ -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()
|
Reference in New Issue
Block a user