mirror of
https://github.com/Reckless-Satoshi/robosats.git
synced 2024-09-11 11:55:26 +03: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:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
max-parallel: 2
|
max-parallel: 4
|
||||||
matrix:
|
matrix:
|
||||||
python-tag: ['3.11.6-slim-bookworm', '3.12-slim-bookworm']
|
python-tag: ['3.11.6-slim-bookworm', '3.12-slim-bookworm']
|
||||||
lnd-version: ["v0.17.0-beta"] # , "v0.17.0-beta.rc1"]
|
lnd-version: ['v0.17.0-beta'] # , 'v0.17.0-beta.rc1']
|
||||||
cln-version: ["v23.08.1"]
|
cln-version: ['v23.08.1']
|
||||||
ln-vendor: ["LND", "CLN"]
|
ln-vendor: ['LND', 'CLN']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 'Checkout'
|
- name: 'Checkout'
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Update Python version in Dockerfile
|
- name: Patch Dockerfile and .env-sample
|
||||||
run: |
|
run: |
|
||||||
sed -i "1s/FROM python:.*/FROM python:${{ matrix.python-tag }}/" Dockerfile
|
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 '/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
|
- uses: satackey/action-docker-layer-caching@v0.0.11
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
key: coordinator-docker-cache-${{ hashFiles('./Dockerfile') }}
|
key: coordinator-docker-cache-${{ hashFiles('Dockerfile', 'requirements.txt', 'requirements_dev.txt') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
coordinator-docker-cache-
|
coordinator-docker-cache-
|
||||||
|
|
||||||
@ -46,13 +47,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
compose-file: "./docker-tests.yml"
|
compose-file: "./docker-tests.yml"
|
||||||
down-flags: "--volumes"
|
down-flags: "--volumes"
|
||||||
# Ideally we run only coordinator-${{ matrix.ln-vendor }} , at the moment some tests fail if LND is not around.
|
|
||||||
services: |
|
services: |
|
||||||
bitcoind
|
bitcoind
|
||||||
postgres
|
postgres
|
||||||
redis
|
redis
|
||||||
coordinator-CLN
|
coordinator-${{ matrix.ln-vendor }}
|
||||||
coordinator-LND
|
|
||||||
robot-LND
|
robot-LND
|
||||||
coordinator
|
coordinator
|
||||||
env:
|
env:
|
||||||
|
@ -67,7 +67,7 @@ class CLNNode:
|
|||||||
return response.version
|
return response.version
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Cannot get CLN version: {e}")
|
print(f"Cannot get CLN version: {e}")
|
||||||
return None
|
return "Not installed"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_info(cls):
|
def get_info(cls):
|
||||||
|
@ -87,8 +87,8 @@ class LNDNode:
|
|||||||
log("verstub.GetVersion", request, response)
|
log("verstub.GetVersion", request, response)
|
||||||
return "v" + response.version
|
return "v" + response.version
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(f"Cannot get CLN version: {e}")
|
||||||
return None
|
return "Not installed"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def decode_payreq(cls, invoice):
|
def decode_payreq(cls, invoice):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from unittest.mock import MagicMock, Mock, mock_open, patch
|
from unittest.mock import MagicMock, Mock, mock_open, patch
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from decouple import config
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from api.models import Order
|
from api.models import Order
|
||||||
@ -94,13 +95,17 @@ class TestUtils(TestCase):
|
|||||||
mock_response_blockchain.json.assert_called_once()
|
mock_response_blockchain.json.assert_called_once()
|
||||||
mock_response_yadio.json.assert_called_once()
|
mock_response_yadio.json.assert_called_once()
|
||||||
|
|
||||||
def test_get_lnd_version(self):
|
if config("LNVENDOR", cast=str) == "LND":
|
||||||
version = get_lnd_version()
|
|
||||||
self.assertTrue(isinstance(version, str))
|
|
||||||
|
|
||||||
def test_get_cln_version(self):
|
def test_get_lnd_version(self):
|
||||||
version = get_cln_version()
|
version = get_lnd_version()
|
||||||
self.assertTrue(isinstance(version, str))
|
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(
|
@patch(
|
||||||
"builtins.open", new_callable=mock_open, read_data="00000000000000000000 dev"
|
"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)
|
@ring.dict(lnd_version_cache, expire=3600)
|
||||||
def get_lnd_version():
|
def get_lnd_version():
|
||||||
try:
|
if LNVENDOR == "LND":
|
||||||
from api.lightning.lnd import LNDNode
|
try:
|
||||||
|
from api.lightning.lnd import LNDNode
|
||||||
|
|
||||||
return LNDNode.get_version()
|
return LNDNode.get_version()
|
||||||
except Exception:
|
except Exception:
|
||||||
return "No LND"
|
return "Not installed"
|
||||||
|
else:
|
||||||
|
return "Not installed"
|
||||||
|
|
||||||
|
|
||||||
cln_version_cache = {}
|
cln_version_cache = {}
|
||||||
@ -189,12 +192,15 @@ cln_version_cache = {}
|
|||||||
|
|
||||||
@ring.dict(cln_version_cache, expire=3600)
|
@ring.dict(cln_version_cache, expire=3600)
|
||||||
def get_cln_version():
|
def get_cln_version():
|
||||||
try:
|
if LNVENDOR == "CLN":
|
||||||
from api.lightning.cln import CLNNode
|
try:
|
||||||
|
from api.lightning.cln import CLNNode
|
||||||
|
|
||||||
return CLNNode.get_version()
|
return CLNNode.get_version()
|
||||||
except Exception:
|
except Exception:
|
||||||
return "No CLN"
|
return "Not installed"
|
||||||
|
else:
|
||||||
|
return "Not installed"
|
||||||
|
|
||||||
|
|
||||||
robosats_commit_cache = {}
|
robosats_commit_cache = {}
|
||||||
|
@ -125,11 +125,12 @@ def connect_to_node(node_name, node_id, ip_port):
|
|||||||
headers=node["headers"],
|
headers=node["headers"],
|
||||||
)
|
)
|
||||||
if response.json() == {}:
|
if response.json() == {}:
|
||||||
|
print("Peered robot node to coordinator node!")
|
||||||
return response.json()
|
return response.json()
|
||||||
else:
|
else:
|
||||||
if "already connected to peer" in response.json()["message"]:
|
if "already connected to peer" in response.json()["message"]:
|
||||||
return response.json()
|
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)
|
time.sleep(wait_step)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user