Skip to content

Commit

Permalink
Enable coordinator test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Oct 23, 2023
1 parent 1b65e33 commit 2b085a8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .env-sample
Original file line number Diff line number Diff line change
@@ -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/'
Expand Down
47 changes: 39 additions & 8 deletions .github/workflows/django-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,24 +22,55 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.11"]
python-version: ["3.11.6"] # , "3.12", "3.13"]

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
pip install coverage
coverage run manage.py test
coverage report
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/lightning/cln.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

#######
Expand Down
29 changes: 18 additions & 11 deletions api/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2b085a8

Please sign in to comment.