diff --git a/.github/workflows/regtest.yml b/.github/workflows/regtest.yml new file mode 100644 index 000000000..1df083b9f --- /dev/null +++ b/.github/workflows/regtest.yml @@ -0,0 +1,97 @@ +name: regtest + +on: pull_request + +jobs: + LndRestWallet: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Setup Regtest + run: | + docker build -t lnbits-legend . + git clone https://github.com/lnbits/legend-regtest-enviroment.git docker + cd docker + source docker-scripts.sh + lnbits-regtest-start + echo "sleeping 60 seconds" + sleep 60 + echo "continue" + lnbits-regtest-init + bitcoin-cli-sim -generate 1 + lncli-sim 1 listpeers + sudo chmod -R a+rwx . + - name: Install dependencies + env: + VIRTUAL_ENV: ./venv + PATH: ${{ env.VIRTUAL_ENV }}/bin:${{ env.PATH }} + run: | + python -m venv ${{ env.VIRTUAL_ENV }} + ./venv/bin/python -m pip install --upgrade pip + ./venv/bin/pip install -r requirements.txt + ./venv/bin/pip install pylightning + ./venv/bin/pip install pytest pytest-asyncio pytest-cov requests mock + - name: Run tests + env: + PYTHONUNBUFFERED: 1 + PORT: 5123 + LNBITS_DATA_FOLDER: ./data + LNBITS_BACKEND_WALLET_CLASS: LndRestWallet + LND_REST_ENDPOINT: https://localhost:8081/ + LND_REST_CERT: docker/data/lnd-1/tls.cert + LND_REST_MACAROON: docker/data/lnd-1/data/chain/bitcoin/regtest/admin.macaroon + run: | + sudo chmod -R a+rwx . && rm -rf ./data && mkdir -p ./data + make test-real-wallet + CLightningWallet: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Setup Regtest + run: | + docker build -t lnbits-legend . + git clone https://github.com/lnbits/legend-regtest-enviroment.git docker + cd docker + source docker-scripts.sh + lnbits-regtest-start + echo "sleeping 60 seconds" + sleep 60 + echo "continue" + lnbits-regtest-init + bitcoin-cli-sim -generate 1 + lncli-sim 1 listpeers + sudo chmod -R a+rwx . + - name: Install dependencies + env: + VIRTUAL_ENV: ./venv + PATH: ${{ env.VIRTUAL_ENV }}/bin:${{ env.PATH }} + run: | + python -m venv ${{ env.VIRTUAL_ENV }} + ./venv/bin/python -m pip install --upgrade pip + ./venv/bin/pip install -r requirements.txt + ./venv/bin/pip install pylightning + ./venv/bin/pip install pytest pytest-asyncio pytest-cov requests mock + - name: Run tests + env: + PYTHONUNBUFFERED: 1 + PORT: 5123 + LNBITS_DATA_FOLDER: ./data + LNBITS_BACKEND_WALLET_CLASS: CLightningWallet + CLIGHTNING_RPC: docker/data/clightning-1/regtest/lightning-rpc + run: | + sudo chmod -R a+rwx . && rm -rf ./data && mkdir -p ./data + make test-real-wallet \ No newline at end of file diff --git a/Makefile b/Makefile index 37c61b66f..5cc3f0509 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: format check requirements.txt -format: prettier black +format: prettier isort black check: mypy checkprettier checkblack @@ -17,12 +17,18 @@ mypy: $(shell find lnbits -name "*.py") ./venv/bin/mypy lnbits/core ./venv/bin/mypy lnbits/extensions/* +isort: $(shell find lnbits -name "*.py") + ./venv/bin/isort --profile black lnbits + checkprettier: $(shell find lnbits -name "*.js" -name ".html") ./node_modules/.bin/prettier --check lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js checkblack: $(shell find lnbits -name "*.py") ./venv/bin/black --check lnbits +checkisort: $(shell find lnbits -name "*.py") + ./venv/bin/isort --profile black --check-only lnbits + Pipfile.lock: Pipfile ./venv/bin/pipenv lock @@ -32,18 +38,27 @@ requirements.txt: Pipfile.lock test: rm -rf ./tests/data mkdir -p ./tests/data + LNBITS_BACKEND_WALLET_CLASS="FakeWallet" \ FAKE_WALLET_SECRET="ToTheMoon1" \ LNBITS_DATA_FOLDER="./tests/data" \ PYTHONUNBUFFERED=1 \ - ./venv/bin/pytest --durations=1 -s --cov=lnbits --cov-report=xml + ./venv/bin/pytest --durations=1 -s --cov=lnbits --cov-report=xml tests + +test-real-wallet: + rm -rf ./tests/data + mkdir -p ./tests/data + LNBITS_DATA_FOLDER="./tests/data" \ + PYTHONUNBUFFERED=1 \ + ./venv/bin/pytest --durations=1 -s --cov=lnbits --cov-report=xml tests test-pipenv: rm -rf ./tests/data mkdir -p ./tests/data + LNBITS_BACKEND_WALLET_CLASS="FakeWallet" \ FAKE_WALLET_SECRET="ToTheMoon1" \ LNBITS_DATA_FOLDER="./tests/data" \ PYTHONUNBUFFERED=1 \ - pipenv run pytest --durations=1 -s --cov=lnbits --cov-report=xml + pipenv run pytest --durations=1 -s --cov=lnbits --cov-report=xml tests bak: # LNBITS_DATABASE_URL=postgres://postgres:postgres@0.0.0.0:5432/postgres diff --git a/tests/mocks.py b/tests/mocks.py index eb08f20b2..c99691cbc 100644 --- a/tests/mocks.py +++ b/tests/mocks.py @@ -27,7 +27,8 @@ WALLET.status = AsyncMock( ) ) -WALLET.create_invoice = generate_mock_invoice +# Note: if this line is uncommented, invoices will always be generated by FakeWallet +# 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