Skip to content

Commit

Permalink
Fix tests failures when LND node is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Nov 14, 2023
1 parent 5f67f8f commit 3c8a437
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/django-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
max-parallel: 2
max-parallel: 4
matrix:
python-tag: ['3.11.6-slim-bookworm', '3.12-slim-bookworm']
lnd-version: ["v0.17.0-beta"] # , "v0.17.0-beta.rc1"]
cln-version: ["v23.08.1"]
ln-vendor: ["LND", "CLN"]
lnd-version: ['v0.17.0-beta'] # , 'v0.17.0-beta.rc1']
cln-version: ['v23.08.1']
ln-vendor: ['LND', 'CLN']

steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: Update Python version in Dockerfile
- name: Patch Dockerfile and .env-sample
run: |
sed -i "1s/FROM python:.*/FROM python:${{ matrix.python-tag }}/" Dockerfile
sed -i '/RUN pip install --no-cache-dir -r requirements.txt/a COPY requirements_dev.txt .\nRUN pip install --no-cache-dir -r requirements_dev.txt' Dockerfile
ln_vendor="${{ matrix.ln-vendor }}"
ln_vendor_escaped="${ln_vendor//\//\\/}"
sed -i sed -i "s/^LNVENDOR=.*/LNVENDOR='${ln_vendor_escaped}'/" .env-sample
- uses: satackey/[email protected]
continue-on-error: true
with:
key: coordinator-docker-cache-${{ hashFiles('./Dockerfile') }}
key: coordinator-docker-cache-${{ hashFiles('Dockerfile', 'requirements.txt', 'requirements_dev.txt') }}
restore-keys: |
coordinator-docker-cache-
Expand All @@ -46,13 +49,11 @@ jobs:
with:
compose-file: "./docker-tests.yml"
down-flags: "--volumes"
# Ideally we run only coordinator-${{ matrix.ln-vendor }} , at the moment some tests fail if LND is not around.
services: |
bitcoind
postgres
redis
coordinator-CLN
coordinator-LND
coordinator-${{ matrix.ln-vendor }}
robot-LND
coordinator
env:
Expand Down
2 changes: 1 addition & 1 deletion api/lightning/cln.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_version(cls):
return response.version
except Exception as e:
print(f"Cannot get CLN version: {e}")
return None
return "Not installed"

@classmethod
def get_info(cls):
Expand Down
4 changes: 2 additions & 2 deletions api/lightning/lnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def get_version(cls):
log("verstub.GetVersion", request, response)
return "v" + response.version
except Exception as e:
print(e)
return None
print(f"Cannot get CLN version: {e}")
return "Not installed"

@classmethod
def decode_payreq(cls, invoice):
Expand Down
17 changes: 11 additions & 6 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,13 +95,17 @@ 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()

def test_get_lnd_version(self):
version = get_lnd_version()
self.assertTrue(isinstance(version, str))
if config("LNVENDOR", cast=str) == "LND":

def test_get_cln_version(self):
version = get_cln_version()
self.assertTrue(isinstance(version, str))
def test_get_lnd_version(self):
version = get_lnd_version()
self.assertTrue(isinstance(version, str))

elif config("LNVENDOR", cast=str) == "CLN":

def test_get_cln_version(self):
version = get_cln_version()
self.assertTrue(isinstance(version, str))

@patch(
"builtins.open", new_callable=mock_open, read_data="00000000000000000000 dev"
Expand Down
26 changes: 16 additions & 10 deletions api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,31 @@ def get_exchange_rates(currencies):

@ring.dict(lnd_version_cache, expire=3600)
def get_lnd_version():
try:
from api.lightning.lnd import LNDNode
if LNVENDOR == "LND":
try:
from api.lightning.lnd import LNDNode

return LNDNode.get_version()
except Exception:
return "No LND"
return LNDNode.get_version()
except Exception:
return "Not installed"
else:
return "Not installed"


cln_version_cache = {}


@ring.dict(cln_version_cache, expire=3600)
def get_cln_version():
try:
from api.lightning.cln import CLNNode
if LNVENDOR == "CLN":
try:
from api.lightning.cln import CLNNode

return CLNNode.get_version()
except Exception:
return "No CLN"
return CLNNode.get_version()
except Exception:
return "Not installed"
else:
return "Not installed"


robosats_commit_cache = {}
Expand Down
3 changes: 2 additions & 1 deletion tests/node_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ def connect_to_node(node_name, node_id, ip_port):
headers=node["headers"],
)
if response.json() == {}:
print("Peered robot node to coordinator node!")
return response.json()
else:
if "already connected to peer" in response.json()["message"]:
return response.json()
print(f"Could not connect to coordinator node: {response.json()}")
print(f"Could not peer coordinator node: {response.json()}")
time.sleep(wait_step)


Expand Down

0 comments on commit 3c8a437

Please sign in to comment.