Skip to content

Commit 25c3c3e

Browse files
daywalker90yukibtc
authored andcommitted
tests: add basic test
1 parent 395da3f commit 25c3c3e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

tests/setup.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -x
3+
script_dir=$(dirname -- "$(readlink -f -- "$0")")
4+
cargo_toml_path="$script_dir/../Cargo.toml"
5+
6+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
7+
cargo build --manifest-path="$cargo_toml_path"

tests/test_cln_ntfy.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/python
2+
3+
from pyln.testing.fixtures import * # noqa: F403
4+
from util import get_plugin # noqa: F401
5+
6+
7+
def test_basic(node_factory, get_plugin): # noqa: F811
8+
node = node_factory.get_node(
9+
options={
10+
"plugin": get_plugin,
11+
"ntfy-url": "https://ntfy.sh",
12+
"ntfy-topic": "cln-alerts",
13+
"ntfy-username": "username",
14+
"ntfy-password": "password",
15+
}
16+
)

tests/util.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import logging
2+
import os
3+
import random
4+
import string
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
RUST_PROFILE = os.environ.get("RUST_PROFILE", "debug")
10+
COMPILED_PATH = Path.cwd() / "target" / RUST_PROFILE / "cln-ntfy"
11+
DOWNLOAD_PATH = Path.cwd() / "tests" / "cln-ntfy"
12+
13+
14+
@pytest.fixture
15+
def get_plugin(directory):
16+
if COMPILED_PATH.is_file():
17+
return COMPILED_PATH
18+
elif DOWNLOAD_PATH.is_file():
19+
return DOWNLOAD_PATH
20+
else:
21+
raise ValueError("No files were found.")
22+
23+
24+
def generate_random_label():
25+
label_length = 8
26+
random_label = "".join(
27+
random.choice(string.ascii_letters) for _ in range(label_length)
28+
)
29+
return random_label
30+
31+
32+
def generate_random_number():
33+
return random.randint(1, 20_000_000_000_000_00_000)
34+
35+
36+
def pay_with_thread(rpc, bolt11):
37+
LOGGER = logging.getLogger(__name__)
38+
try:
39+
rpc.dev_pay(bolt11, dev_use_shadow=False)
40+
except Exception as e:
41+
LOGGER.debug(f"Error paying payment hash:{e}")
42+
pass

0 commit comments

Comments
 (0)