cln-nip47/tests/util.py

66 lines
1.6 KiB
Python
Raw Permalink Normal View History

2025-04-02 17:38:52 +02:00
import os
import random
import string
from pathlib import Path
2025-11-08 13:41:11 +01:00
from hashlib import sha256
2025-04-02 17:38:52 +02:00
import pytest
RUST_PROFILE = os.environ.get("RUST_PROFILE", "debug")
2025-12-09 16:23:34 +01:00
plugin_dir = Path(__file__).parent.parent.resolve()
COMPILED_PATH = plugin_dir / "target" / RUST_PROFILE / "cln-nip47"
DOWNLOAD_PATH = plugin_dir / "tests" / "cln-nip47"
2025-04-02 17:38:52 +02:00
2025-11-08 13:41:11 +01:00
DOWNLOAD_HOLD_PATH = plugin_dir / "tests" / "hold"
2025-04-02 17:38:52 +02:00
@pytest.fixture
2025-11-08 13:41:11 +01:00
def get_plugin():
2025-04-02 17:38:52 +02:00
if COMPILED_PATH.is_file():
return COMPILED_PATH
elif DOWNLOAD_PATH.is_file():
return DOWNLOAD_PATH
else:
raise ValueError("No files were found.")
2025-11-08 13:41:11 +01:00
@pytest.fixture
def get_hold():
if DOWNLOAD_HOLD_PATH.is_file():
return DOWNLOAD_HOLD_PATH
else:
raise ValueError("No files were found.")
2025-04-02 17:38:52 +02:00
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 update_config_file_option(lightning_dir, option_name, option_value):
with open(lightning_dir + "/config", "r") as file:
lines = file.readlines()
for i, line in enumerate(lines):
if line.startswith(option_name):
lines[i] = option_name + "=" + option_value + "\n"
with open(lightning_dir + "/config", "w") as file:
file.writelines(lines)
def experimental_anchors_check(node_factory):
l1 = node_factory.get_node()
version = l1.rpc.getinfo()["version"]
if version.startswith("v23"):
return True
else:
return False