mirror of
https://github.com/daywalker90/cln-nip47.git
synced 2026-08-13 12:33:43 +02:00
tests: use nostr-rs-relay instead of nostr_relay
This commit is contained in:
parent
7dff9f83e7
commit
727f710646
9 changed files with 1128 additions and 2553 deletions
19
.github/workflows/ci.yml
vendored
19
.github/workflows/ci.yml
vendored
|
|
@ -27,14 +27,14 @@ jobs:
|
|||
bitcoind-version: ["30.0"]
|
||||
experimental: [1]
|
||||
deprecated: [0]
|
||||
python-version: ["3.9", "3.13"]
|
||||
python-version: ["3.9", "3.14"]
|
||||
os: ["ubuntu-latest"]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Create cache paths
|
||||
run: |
|
||||
|
|
@ -44,7 +44,7 @@ jobs:
|
|||
sudo chown -R $USER /usr/local/libexec
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ jobs:
|
|||
|
||||
- name: Restore CLN cache
|
||||
id: cache-cln
|
||||
uses: actions/cache/restore@v4
|
||||
uses: actions/cache/restore@v5
|
||||
with:
|
||||
path: |
|
||||
/usr/local/bin/lightning*
|
||||
|
|
@ -69,13 +69,13 @@ jobs:
|
|||
|
||||
- name: Restore bitcoind cache
|
||||
id: cache-bitcoind
|
||||
uses: actions/cache/restore@v4
|
||||
uses: actions/cache/restore@v5
|
||||
with:
|
||||
path: /usr/local/bin/bitcoin*
|
||||
key: cache-bitcoind-${{ matrix.bitcoind-version }}-${{ steps.exact_versions.outputs.os_version }}
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v6
|
||||
uses: astral-sh/setup-uv@v7
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "**/pyproject.toml"
|
||||
|
|
@ -93,7 +93,7 @@ jobs:
|
|||
- name: Save bitcoind cache
|
||||
id: save-cache-bitcoind
|
||||
if : ${{ always() && steps.cache-bitcoind.outputs.cache-hit != 'true'}}
|
||||
uses: actions/cache/save@v4
|
||||
uses: actions/cache/save@v5
|
||||
with:
|
||||
path: /usr/local/bin/bitcoin*
|
||||
key: ${{ steps.cache-bitcoind.outputs.cache-primary-key }}
|
||||
|
|
@ -111,7 +111,7 @@ jobs:
|
|||
- name: Save CLN cache
|
||||
id: save-cache-cln
|
||||
if : ${{ always() && steps.cache-cln.outputs.cache-hit != 'true' }}
|
||||
uses: actions/cache/save@v4
|
||||
uses: actions/cache/save@v5
|
||||
with:
|
||||
path: |
|
||||
/usr/local/bin/lightning*
|
||||
|
|
@ -123,7 +123,7 @@ jobs:
|
|||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Set up protoc
|
||||
if: ${{ inputs.tagged-release == false}} && ${{ steps.cache-cln.outputs.cache-hit != 'true' }}
|
||||
if: ${{ inputs.tagged-release == false}}
|
||||
uses: arduino/setup-protoc@v3
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
@ -155,5 +155,6 @@ jobs:
|
|||
export PYTEST_TIMEOUT=600
|
||||
|
||||
cd tests
|
||||
tar -xf nostr-rs-relay.tar.gz
|
||||
uv add --dev pyln-testing==${{ inputs.pyln-version }} pyln-client==${{ inputs.pyln-version }} pyln-proto==${{ inputs.pyln-version }}
|
||||
uv run -v pytest -n=10
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@
|
|||
/result/
|
||||
/tests/holdinvoice
|
||||
/tests/hold
|
||||
/tests/nostr-rs-relay
|
||||
|
|
|
|||
12
tests/config.toml
Normal file
12
tests/config.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
[info]
|
||||
relay_url = "ws://127.0.0.1/"
|
||||
name = "nostr-rs-relay"
|
||||
description = "test relay"
|
||||
|
||||
[options]
|
||||
reject_future_seconds = 1800
|
||||
[limits]
|
||||
limit_scrapers = false
|
||||
[network]
|
||||
address = "0.0.0.0"
|
||||
64
tests/conftest.py
Normal file
64
tests/conftest.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import os
|
||||
import socket
|
||||
import pytest
|
||||
import tempfile
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def nostr_relay(worker_id):
|
||||
worker_index = int(worker_id[2:]) if worker_id and worker_id.startswith("gw") else 0
|
||||
base_port = 50000 + (worker_index * 100)
|
||||
port = get_free_port(base_port)
|
||||
|
||||
config_path = Path(__file__).parent / "config.toml"
|
||||
if not config_path.exists():
|
||||
raise FileNotFoundError(f"config.toml not found at {config_path}")
|
||||
|
||||
temp_dir = Path(tempfile.mkdtemp())
|
||||
|
||||
# Copy your original config.toml into it
|
||||
original_config = Path(__file__).parent / "config.toml"
|
||||
temp_config = temp_dir / "config.toml"
|
||||
shutil.copy(original_config, temp_config)
|
||||
|
||||
with temp_config.open("a") as f:
|
||||
f.write(f"port = {port}\n")
|
||||
|
||||
proc = subprocess.Popen(
|
||||
["./nostr-rs-relay", "--config", str(temp_config), "--db", str(temp_dir)],
|
||||
cwd=Path(__file__).parent,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=os.environ | {"RUST_LOG": "warn,nostr_rs_relay=debug"},
|
||||
)
|
||||
|
||||
try:
|
||||
import time
|
||||
|
||||
time.sleep(1.0)
|
||||
|
||||
ws_url = f"ws://127.0.0.1:{port}"
|
||||
yield ws_url
|
||||
|
||||
finally:
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
proc.wait()
|
||||
|
||||
|
||||
def get_free_port(start_port=50000):
|
||||
for port in range(start_port, start_port + 100):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
try:
|
||||
s.bind(("127.0.0.1", port))
|
||||
s.listen(1)
|
||||
return port
|
||||
except OSError:
|
||||
continue
|
||||
raise RuntimeError(f"No free ports found starting from {start_port}")
|
||||
BIN
tests/nostr-rs-relay.tar.gz
Normal file
BIN
tests/nostr-rs-relay.tar.gz
Normal file
Binary file not shown.
|
|
@ -11,8 +11,6 @@ dev = [
|
|||
"pytest-xdist>=3.7,<4",
|
||||
"pytest-timeout>=2.4,<3",
|
||||
"nostr-sdk>=0.44",
|
||||
"PyYAML>=6.0.2,<7",
|
||||
"nostr_relay>=1.14",
|
||||
"pyln-testing>=24.11.1",
|
||||
"pyln-client>=24.11.1",
|
||||
"pyln-proto>=24.11.1",
|
||||
|
|
|
|||
|
|
@ -68,6 +68,11 @@ else
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if ! tar -xzvf "$script_dir/nostr-rs-relay.tar.gz" -C "$script_dir"; then
|
||||
echo "Error extracting the contents of nostr-rs-relay.tar.gz" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
proto_path="$script_dir/../proto"
|
||||
if [ -d "$proto_path" ]; then
|
||||
# Generate grpc files
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
2930
tests/uv.lock
generated
2930
tests/uv.lock
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue