From 20d9add4abc09f437c770d1cc60796018efbb2d4 Mon Sep 17 00:00:00 2001 From: daywalker90 <8257956+daywalker90@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:15:00 +0200 Subject: [PATCH] tests: add basic test --- tests/setup.sh | 7 +++++++ tests/test_cln_ntfy.py | 16 ++++++++++++++++ tests/util.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100755 tests/setup.sh create mode 100644 tests/test_cln_ntfy.py create mode 100644 tests/util.py diff --git a/tests/setup.sh b/tests/setup.sh new file mode 100755 index 0000000..4fb0314 --- /dev/null +++ b/tests/setup.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -x +script_dir=$(dirname -- "$(readlink -f -- "$0")") +cargo_toml_path="$script_dir/../Cargo.toml" + +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +cargo build --manifest-path="$cargo_toml_path" diff --git a/tests/test_cln_ntfy.py b/tests/test_cln_ntfy.py new file mode 100644 index 0000000..bd8204d --- /dev/null +++ b/tests/test_cln_ntfy.py @@ -0,0 +1,16 @@ +#!/usr/bin/python + +from pyln.testing.fixtures import * # noqa: F403 +from util import get_plugin # noqa: F401 + + +def test_basic(node_factory, get_plugin): # noqa: F811 + node = node_factory.get_node( + options={ + "plugin": get_plugin, + "ntfy-url": "https://ntfy.sh", + "ntfy-topic": "cln-alerts", + "ntfy-username": "username", + "ntfy-password": "password", + } + ) diff --git a/tests/util.py b/tests/util.py new file mode 100644 index 0000000..ac3559c --- /dev/null +++ b/tests/util.py @@ -0,0 +1,42 @@ +import logging +import os +import random +import string +from pathlib import Path + +import pytest + +RUST_PROFILE = os.environ.get("RUST_PROFILE", "debug") +COMPILED_PATH = Path.cwd() / "target" / RUST_PROFILE / "cln-ntfy" +DOWNLOAD_PATH = Path.cwd() / "tests" / "cln-ntfy" + + +@pytest.fixture +def get_plugin(directory): + if COMPILED_PATH.is_file(): + return COMPILED_PATH + elif DOWNLOAD_PATH.is_file(): + return DOWNLOAD_PATH + else: + raise ValueError("No files were found.") + + +def generate_random_label(): + label_length = 8 + random_label = "".join( + random.choice(string.ascii_letters) for _ in range(label_length) + ) + return random_label + + +def generate_random_number(): + return random.randint(1, 20_000_000_000_000_00_000) + + +def pay_with_thread(rpc, bolt11): + LOGGER = logging.getLogger(__name__) + try: + rpc.dev_pay(bolt11, dev_use_shadow=False) + except Exception as e: + LOGGER.debug(f"Error paying payment hash:{e}") + pass