diff --git a/.env-sample b/.env-sample index a9362b4fe..8a1045f6f 100644 --- a/.env-sample +++ b/.env-sample @@ -1,7 +1,7 @@ # Coordinator Alias (Same as longAlias) COORDINATOR_ALIAS="Local Dev" # Lightning node vendor: CLN | LND -LNVENDOR='CLN' +LNVENDOR='LND' # LND directory to read TLS cert and macaroon LND_DIR='/lnd/' diff --git a/.github/workflows/django-test.yml b/.github/workflows/django-test.yml index 8c69a2e30..91e240d0c 100644 --- a/.github/workflows/django-test.yml +++ b/.github/workflows/django-test.yml @@ -6,13 +6,13 @@ on: push: branches: [ "main" ] paths: ["api", "chat", "control", "robosats"] - pull_request: + pull_request_target: branches: [ "main" ] paths: ["api", "chat", "control", "robosats"] -# concurrency: -# group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' -# cancel-in-progress: true +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true jobs: build: @@ -22,24 +22,55 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.11"] + python-version: ["3.11.6", "3.12"] + + services: + db: + image: postgres:14.2 + env: + POSTGRES_DB: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: example + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - name: 'Checkout' uses: actions/checkout@v4 + - name: 'Set up Python ${{ matrix.python-version }}' uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + + - name: 'Cache pip dependencies' + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: 'Install Python Dependencies' run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: 'Install LND gRPC Dependencies' + + - name: 'Install LND/CLN gRPC Dependencies' run: bash ./scripts/generate_grpc.sh + - name: 'Create .env File' run: | mv .env-sample .env - - name: 'Tests' + + - name: 'Wait for PostgreSQL to become ready' + run: | + sudo apt-get install -y postgresql-client + until pg_isready -h localhost -p 5432 -U postgres; do sleep 2; done + + - name: 'Run tests with coverage' run: | - python manage.py test \ No newline at end of file + pip install coverage + coverage run manage.py test + coverage report \ No newline at end of file diff --git a/.github/workflows/py-linter.yml b/.github/workflows/py-linter.yml index 67906e5a4..7b5f785a1 100644 --- a/.github/workflows/py-linter.yml +++ b/.github/workflows/py-linter.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11.6' cache: pip - run: pip install black==22.8.0 flake8==5.0.4 isort==5.10.1 - name: Run linters diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ac654aded..7ecf6f312 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,9 +38,9 @@ jobs: fi - # django-test: - # uses: RoboSats/robosats/.github/workflows/django-test.yml@main - # needs: check-versions + django-test: + uses: RoboSats/robosats/.github/workflows/django-test.yml@main + needs: check-versions frontend-build: uses: RoboSats/robosats/.github/workflows/frontend-build.yml@main diff --git a/api/lightning/cln.py b/api/lightning/cln.py index f3b341f16..9d97d4053 100755 --- a/api/lightning/cln.py +++ b/api/lightning/cln.py @@ -10,10 +10,10 @@ from decouple import config from django.utils import timezone -from . import node_pb2 as noderpc -from . import node_pb2_grpc as nodestub from . import hold_pb2 as holdrpc from . import hold_pb2_grpc as holdstub +from . import node_pb2 as noderpc +from . import node_pb2_grpc as nodestub from . import primitives_pb2 as primitives__pb2 ####### diff --git a/api/tests/test_utils.py b/api/tests/test_utils.py index dfcabbc92..6a0184277 100644 --- a/api/tests/test_utils.py +++ b/api/tests/test_utils.py @@ -1,6 +1,7 @@ from unittest.mock import MagicMock, Mock, mock_open, patch import numpy as np +from decouple import config from django.test import TestCase from api.models import Order @@ -94,17 +95,23 @@ def test_get_exchange_rates(self, mock_get_session, mock_config): mock_response_blockchain.json.assert_called_once() mock_response_yadio.json.assert_called_once() - @patch("api.lightning.lnd.LNDNode.get_version") - def test_get_lnd_version(self, mock_get_version): - mock_get_version.return_value = "v0.17.0-beta" - version = get_lnd_version() - self.assertEqual(version, "v0.17.0-beta") - - @patch("api.lightning.cln.CLNNode.get_version") - def test_get_cln_version(self, mock_get_version): - mock_get_version.return_value = "v23.08.1" - version = get_cln_version() - self.assertEqual(version, "v23.08.1") + LNVENDOR = config("LNVENDOR", cast=str, default="LND") + + if LNVENDOR == "LND": + + @patch("api.lightning.lnd.LNDNode.get_version") + def test_get_lnd_version(self, mock_get_version): + mock_get_version.return_value = "v0.17.0-beta" + version = get_lnd_version() + self.assertEqual(version, "v0.17.0-beta") + + elif LNVENDOR == "CLN": + + @patch("api.lightning.cln.CLNNode.get_version") + def test_get_cln_version(self, mock_get_version): + mock_get_version.return_value = "v23.08.1" + version = get_cln_version() + self.assertEqual(version, "v23.08.1") @patch("builtins.open", new_callable=mock_open, read_data="test_commit_hash") def test_get_robosats_commit(self, mock_file):