Skip to content

Commit

Permalink
first useful test
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 committed Mar 29, 2024
1 parent aa5ee52 commit bdef293
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
17 changes: 14 additions & 3 deletions src/channelwatch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, path::PathBuf, time::Duration};
use std::{collections::HashMap, env, path::PathBuf, time::Duration};

use anyhow::{anyhow, Error};
use cln_plugin::Plugin;
Expand All @@ -16,7 +16,7 @@ use tokio::time::{self, Instant};
use crate::{
rpc::{connect, disconnect, get_info, list_channels, list_nodes, list_peer_channels},
structs::{Config, PluginState},
util::{make_rpc_path, send_mail, send_telegram},
util::{make_rpc_path, parse_boolean, send_mail, send_telegram},
};

async fn check_channel(plugin: Plugin<PluginState>) -> Result<(), Error> {
Expand Down Expand Up @@ -424,7 +424,18 @@ fn update_slackers(
}

pub async fn check_channels_loop(plugin: Plugin<PluginState>) -> Result<(), Error> {
time::sleep(Duration::from_secs(600)).await;
let mut skip_sleep = false;
if let Ok(dbg) = env::var("TEST_DEBUG") {
if let Some(bl) = parse_boolean(&dbg) {
if bl {
skip_sleep = true
}
}
}
if !skip_sleep {
time::sleep(Duration::from_secs(600)).await;
}

loop {
{
match check_channel(plugin.clone()).await {
Expand Down
8 changes: 8 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ pub async fn send_telegram(config: &Config, subject: &String, body: &String) ->
pub fn make_rpc_path(plugin: &Plugin<PluginState>) -> PathBuf {
Path::new(&plugin.configuration().lightning_dir).join(plugin.configuration().rpc_file)
}

pub fn parse_boolean(s: &str) -> Option<bool> {
match s.to_lowercase().as_str() {
"true" | "1" => Some(true),
"false" | "0" => Some(false),
_ => None,
}
}
31 changes: 27 additions & 4 deletions tests/test_vitality.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
#!/usr/bin/python

import time
from pathlib import Path

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, "vitality-fail": "lol"}
)
node = node_factory.get_node()
lightning_dir = Path(node.rpc.call("getinfo")["lightning-dir"])
config_file = lightning_dir / "config"
option_lines = [
"vitality-amboss=true\n",
"vitality-expiring-htlcs=50\n",
"vitality-watch-channels=true\n",
"vitality-watch-gossip=true\n",
"vitality-telegram-token=4582169472:Og4grGKROE3OR-x-O3kfOsks\n",
"vitality-telegram-usernames=936723718\n",
"[email protected]\n",
"vitality-smtp-password=WEJF§IFJseo32\n",
"vitality-smtp-server=mail.gmx.net\n",
"vitality-smtp-port=587\n",
"[email protected]\n",
"[email protected]\n",
]

with config_file.open(mode="a") as file:
file.writelines(option_lines)

node.rpc.call("plugin", {"subcommand": "start", "plugin": str(get_plugin)})
node.daemon.wait_for_log(r"Error in amboss_ping")
time.sleep(5)
assert node.daemon.is_in_log(r"check_channel: All good.")
24 changes: 0 additions & 24 deletions tests/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import logging
import os
import random
import string
from pathlib import Path

import pytest
Expand All @@ -19,24 +16,3 @@ def get_plugin(directory):
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 bdef293

Please sign in to comment.