Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 committed Mar 28, 2024
1 parent 800a453 commit 43f21fd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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 version
version=$(awk -F'=' '/^\[package\]/ { in_package = 1 } in_package && /version/ { gsub(/[" ]/, "", $2); print $2; exit }' "$cargo_toml_path")

get_architecture() {
machine=$(uname -m)

case $machine in
x86_64)
echo 'x86_64-linux-gnu'
;;
armv7l)
echo 'armv7-linux-gnueabihf'
;;
aarch64)
echo 'aarch64-linux-gnu'
;;
*)
echo "No self-compiled binary found and unsupported release-architecture: $machine" >&2
exit 1
;;
esac
}
architecture=$(get_architecture)

github_url="https://github.com/daywalker90/vitality/releases/download/v$version/vitality-v$version-$architecture.tar.gz"


# Download the file using curl
if ! curl -L "$github_url" -o "$script_dir/vitality-v$version-$architecture.tar.gz"; then
echo "Error downloading the file from $github_url" >&2
exit 1
fi

# Extract the contents using tar
if ! tar -xzvf "$script_dir/vitality-v$version-$architecture.tar.gz" -C "$script_dir"; then
echo "Error extracting the contents of vitality-v$version-$architecture.tar.gz" >&2
exit 1
fi
9 changes: 9 additions & 0 deletions tests/test_vitality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/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})
42 changes: 42 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
@@ -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 / "vitality"
DOWNLOAD_PATH = Path.cwd() / "tests" / "vitality"


@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"holdinvoice: Error paying payment hash:{e}")
pass

0 comments on commit 43f21fd

Please sign in to comment.