Skip to content

Commit

Permalink
Merge pull request #259 from daywalker90/modernize-cln-tests
Browse files Browse the repository at this point in the history
modernize cln tests and CI
  • Loading branch information
sr-gi authored Jul 29, 2024
2 parents c9f82bc + f6decde commit e108510
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Continuous Integration Checks

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:

jobs:
build:
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/cln-plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: CI tests for CLN watchtower-plugin

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:

env:
bitcoind_version: 0.20.1
cln_version: 0.12.1
bitcoind_version: "27.0"
cln_version: "24.02.2"

jobs:
cache-cln:
Expand All @@ -28,10 +32,10 @@ jobs:
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
if: ${{ steps.cache-cln.outputs.cache-hit != 'true' }}
run: |
sudo apt-get update && sudo apt-get install gettext
sudo apt-get update && sudo apt-get install -y gettext protobuf-compiler
git clone https://github.com/ElementsProject/lightning.git && cd lightning && git checkout v${{ env.cln_version }}
pip install --user poetry && poetry install
./configure --enable-developer && poetry run make
./configure && poetry run make
cln-plugin:
needs: cache-cln
Expand Down Expand Up @@ -69,4 +73,4 @@ jobs:
- name: Run tests
run: |
cd watchtower-plugin/tests
DEVELOPER=1 SLOW_MACHINE=1 poetry run pytest test.py --log-cli-level=INFO -s
VALGRIND=0 SLOW_MACHINE=1 poetry run pytest test.py --log-cli-level=INFO -s
4 changes: 2 additions & 2 deletions watchtower-plugin/src/retrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl RetryManager {
} else if let Some(retrier) = self.retriers.get(&tower_id) {
if retrier.is_idle() {
if !data.is_none() {
log::error!("Data was send to an idle retier. This should have never happened. Please report! ({data:?})");
log::error!("Data was send to an idle retrier. This should have never happened. Please report! ({data:?})");
continue;
}
log::info!(
Expand Down Expand Up @@ -774,7 +774,7 @@ mod tests {
.unwrap()
.is_running());

// Wait until the task gives up and check again (this gives up due to accumulation of transient errors, so the retiers will be idle).
// Wait until the task gives up and check again (this gives up due to accumulation of transient errors, so the retriers will be idle).
wait_until!(wt_client
.lock()
.unwrap()
Expand Down
15 changes: 1 addition & 14 deletions watchtower-plugin/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess

from pyln.testing.fixtures import * # noqa: F401,F403
from pyln.testing.utils import DEVELOPER, BITCOIND_CONFIG, TailableProc
from pyln.testing.utils import BITCOIND_CONFIG, TailableProc

WT_PLUGIN = Path("~/.cargo/bin/watchtower-client").expanduser()
TEOSD_CONFIG = {
Expand Down Expand Up @@ -116,19 +116,6 @@ def pytest_runtest_makereport(item, call):
setattr(item, "rep_" + rep.when, rep)


def pytest_configure(config):
config.addinivalue_line("markers", "developer: only run when developer is flagged on")


def pytest_runtest_setup(item):
for mark in item.iter_markers(name="developer"):
if not DEVELOPER:
if len(mark.args):
pytest.skip("!DEVELOPER: {}".format(mark.args[0]))
else:
pytest.skip("!DEVELOPER: Requires DEVELOPER=1")


@pytest.fixture(scope="function", autouse=True)
def log_name(request):
# Here logging is used, you can use whatever you want to use for logs
Expand Down
4 changes: 2 additions & 2 deletions watchtower-plugin/tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ black = "^22.6.0"
[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
pytest-timeout = "^2.1.0"
pyln-testing = "^0.12.1"
pyln-client = "^23.11"
pyln-testing = "^24.2.1"
pyln-client = "^24.2.1"


[build-system]
Expand Down
24 changes: 13 additions & 11 deletions watchtower-plugin/tests/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from pyln.client import RpcError
from conftest import WT_PLUGIN


Expand All @@ -16,7 +15,6 @@ def change_endianness(x):
return b[::-1].hex()


@pytest.mark.developer("Requires dev_sign_last_tx")
def test_watchtower(node_factory, bitcoind, teosd):
"""
Test watchtower hook.
Expand All @@ -27,7 +25,13 @@ def test_watchtower(node_factory, bitcoind, teosd):
commitment transaction.
"""

l1, l2 = node_factory.line_graph(2, opts=[{"allow_broken_log": True}, {"plugin": WT_PLUGIN}])
l1, l2 = node_factory.line_graph(
2,
opts=[
{"broken_log": r"Could not find resolution for output [0-9]?: did \*we\* cheat\?"},
{"plugin": WT_PLUGIN},
],
)

# We need to register l2 with the tower
tower_id = teosd.cli.gettowerinfo()["tower_id"]
Expand Down Expand Up @@ -60,7 +64,7 @@ def test_watchtower(node_factory, bitcoind, teosd):
penalty_txid = bitcoind.rpc.getrawmempool()[0]

# The channel still exists between the two peers, but it's on chain
assert l1.rpc.listpeers()["peers"][0]["channels"][0]["state"] == "ONCHAIN"
assert l1.rpc.listpeerchannels()["channels"][0]["state"] == "ONCHAIN"
assert l2.rpc.getappointment(tower_id, locator)["status"] == "dispute_responded"

# Generate blocks until the penalty gets irrevocably resolved
Expand Down Expand Up @@ -90,7 +94,6 @@ def test_unreachable_watchtower(node_factory, bitcoind, teosd):
{},
{
"plugin": WT_PLUGIN,
"allow_broken_log": True,
"dev-watchtower-max-retry-interval": max_interval_time,
},
],
Expand Down Expand Up @@ -123,7 +126,7 @@ def test_auto_retry_watchtower(node_factory, bitcoind, teosd):
{},
{
"plugin": WT_PLUGIN,
"allow_broken_log": True,
"broken_log": r"plugin-watchtower-client: Data was send to an idle retrier. This should have never happened. Please report!.*",
"watchtower-max-retry-time": 1,
"watchtower-auto-retry-delay": 1,
},
Expand All @@ -141,7 +144,7 @@ def test_auto_retry_watchtower(node_factory, bitcoind, teosd):
l1.rpc.pay(l2.rpc.invoice(25000000, "lbl1", "desc1")["bolt11"])

# Wait until the tower has been flagged as unreachable
l2.daemon.wait_for_log(f"Starting to idle")
l2.daemon.wait_for_log("Starting to idle")
assert l2.rpc.gettowerinfo(tower_id)["status"] == "unreachable"
assert l2.rpc.gettowerinfo(tower_id)["pending_appointments"]

Expand All @@ -161,7 +164,6 @@ def test_manually_retry_watchtower(node_factory, bitcoind, teosd):
{},
{
"plugin": WT_PLUGIN,
"allow_broken_log": True,
"watchtower-max-retry-time": 0,
},
],
Expand All @@ -178,7 +180,7 @@ def test_manually_retry_watchtower(node_factory, bitcoind, teosd):
l1.rpc.pay(l2.rpc.invoice(25000000, "lbl1", "desc1")["bolt11"])

# Wait until the tower has been flagged as unreachable
l2.daemon.wait_for_log(f"Starting to idle")
l2.daemon.wait_for_log("Starting to idle")
assert l2.rpc.gettowerinfo(tower_id)["status"] == "unreachable"
assert l2.rpc.gettowerinfo(tower_id)["pending_appointments"]

Expand All @@ -193,7 +195,7 @@ def test_manually_retry_watchtower(node_factory, bitcoind, teosd):


def test_misbehaving_watchtower(node_factory, bitcoind, teosd, directory):
l1, l2 = node_factory.line_graph(2, opts=[{}, {"plugin": WT_PLUGIN, "allow_broken_log": True}])
l1, l2 = node_factory.line_graph(2, opts=[{}, {"plugin": WT_PLUGIN}])

# We need to register l2 with the tower
tower_id = teosd.cli.gettowerinfo()["tower_id"]
Expand All @@ -210,7 +212,7 @@ def test_misbehaving_watchtower(node_factory, bitcoind, teosd, directory):


def test_get_appointment(node_factory, bitcoind, teosd, directory):
l1, l2 = node_factory.line_graph(2, opts=[{"allow_broken_log": True}, {"plugin": WT_PLUGIN}])
l1, l2 = node_factory.line_graph(2, opts=[{}, {"plugin": WT_PLUGIN}])

# We need to register l2 with the tower
tower_id = teosd.cli.gettowerinfo()["tower_id"]
Expand Down

0 comments on commit e108510

Please sign in to comment.