mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 19:06:26 +00:00
Fix tests failures when LND node is not used
This commit is contained in:
parent
605a37bb87
commit
3a42195bba
17
.github/workflows/django-test.yml
vendored
17
.github/workflows/django-test.yml
vendored
@ -18,26 +18,27 @@ 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
|
||||
sed -i "s/^LNVENDOR=.*/LNVENDOR='${{ matrix.ln-vendor }}'/" .env-sample
|
||||
|
||||
- uses: satackey/action-docker-layer-caching@v0.0.11
|
||||
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-
|
||||
|
||||
@ -46,13 +47,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:
|
||||
|
@ -67,7 +67,7 @@ class CLNNode:
|
||||
return response.version
|
||||
except Exception as e:
|
||||
print(f"Cannot get CLN version: {e}")
|
||||
return None
|
||||
return "Not installed"
|
||||
|
||||
@classmethod
|
||||
def get_info(cls):
|
||||
|
@ -87,8 +87,8 @@ class LNDNode:
|
||||
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):
|
||||
|
@ -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,13 +95,17 @@ class TestUtils(TestCase):
|
||||
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"
|
||||
|
26
api/utils.py
26
api/utils.py
@ -176,12 +176,15 @@ lnd_version_cache = {}
|
||||
|
||||
@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 = {}
|
||||
@ -189,12 +192,15 @@ 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 = {}
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user