mirror of
https://github.com/daywalker90/cln-nip47.git
synced 2026-08-13 12:33:43 +02:00
init
This commit is contained in:
commit
2529bb5863
35 changed files with 6788 additions and 0 deletions
4
tests/requirements.txt
Normal file
4
tests/requirements.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pytest-asyncio<0.24
|
||||
nostr-sdk
|
||||
PyYAML
|
||||
nostr_relay
|
||||
100
tests/setup.sh
Executable file
100
tests/setup.sh
Executable file
|
|
@ -0,0 +1,100 @@
|
|||
#!/bin/bash
|
||||
set -x
|
||||
# Get the directory of the script
|
||||
script_dir=$(dirname -- "$(readlink -f -- "$0")")
|
||||
|
||||
cargo_toml_path="$script_dir/../Cargo.toml"
|
||||
|
||||
# Use grep and awk to extract the name and version
|
||||
name=$(awk -F'=' '/^\[package\]/ { in_package = 1 } in_package && /name/ { gsub(/[" ]/, "", $2); print $2; exit }' "$cargo_toml_path")
|
||||
version=$(awk -F'=' '/^\[package\]/ { in_package = 1 } in_package && /version/ { gsub(/[" ]/, "", $2); print $2; exit }' "$cargo_toml_path")
|
||||
|
||||
get_platform_file_end() {
|
||||
machine=$(uname -m)
|
||||
kernel=$(uname -s)
|
||||
|
||||
case $kernel in
|
||||
Darwin)
|
||||
echo 'universal-apple-darwin.zip'
|
||||
;;
|
||||
Linux)
|
||||
case $machine in
|
||||
x86_64)
|
||||
echo 'x86_64-linux-gnu.tar.gz'
|
||||
;;
|
||||
armv7l)
|
||||
echo 'armv7-linux-gnueabihf.tar.gz'
|
||||
;;
|
||||
aarch64)
|
||||
echo 'aarch64-linux-gnu.tar.gz'
|
||||
;;
|
||||
*)
|
||||
echo "No self-compiled binary found and unsupported release-architecture: $machine" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "No self-compiled binary found and unsupported OS: $kernel" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
platform_file_end=$(get_platform_file_end)
|
||||
archive_file=$name-v$version-$platform_file_end
|
||||
|
||||
github_url="https://github.com/daywalker90/$name/releases/download/v$version/$archive_file"
|
||||
|
||||
|
||||
# Download the archive using curl
|
||||
if ! curl -L "$github_url" -o "$script_dir/$archive_file"; then
|
||||
echo "Error downloading the file from $github_url" >&2
|
||||
# exit 1
|
||||
fi
|
||||
|
||||
# Extract the contents
|
||||
if [[ $archive_file == *.tar.gz ]]; then
|
||||
if ! tar -xzvf "$script_dir/$archive_file" -C "$script_dir"; then
|
||||
echo "Error extracting the contents of $archive_file" >&2
|
||||
# exit 1
|
||||
fi
|
||||
elif [[ $archive_file == *.zip ]]; then
|
||||
if ! unzip "$script_dir/$archive_file" -d "$script_dir"; then
|
||||
echo "Error extracting the contents of $archive_file" >&2
|
||||
# exit 1
|
||||
fi
|
||||
else
|
||||
echo "Unknown archive format or unsupported file extension: $archive_file" >&2
|
||||
# exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Function to check if a Python package is installed
|
||||
check_package() {
|
||||
python_exec="$1"
|
||||
package_name="$2"
|
||||
if $python_exec -c "import $package_name" &> /dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
proto_path="$script_dir/../proto"
|
||||
if [ -d "$proto_path" ]; then
|
||||
# Check if the package is installed in the first Python executable
|
||||
if check_package "$TEST_DIR/bin/python3" "grpc"; then
|
||||
python_exec="$TEST_DIR/bin/python3"
|
||||
elif check_package "python3" "grpc"; then
|
||||
python_exec="python3"
|
||||
else
|
||||
echo "Error: Package 'grpcio' is not installed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate grpc files
|
||||
if ! "$python_exec" -m grpc_tools.protoc --proto_path="$proto_path" --python_out=$script_dir --grpc_python_out=$script_dir $proto_path/*.proto; then
|
||||
echo "Error generating grpc files" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
1090
tests/test_clnnwc.py
Normal file
1090
tests/test_clnnwc.py
Normal file
File diff suppressed because it is too large
Load diff
63
tests/util.py
Normal file
63
tests/util.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
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-nip47"
|
||||
DOWNLOAD_PATH = Path.cwd() / "tests" / "cln-nip47"
|
||||
|
||||
|
||||
@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.info(f"holdinvoice: Error paying payment hash:{e}")
|
||||
pass
|
||||
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue