From 79ec640f1ea7553c4c7e81cca2d16e23f1c1165b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 31 May 2024 16:20:04 +0200 Subject: [PATCH] pytest: Update tests to work for CLN v24.02 --- libs/gl-testing/gltesting/__init__.py | 4 ++ libs/gl-testing/gltesting/fixtures.py | 3 +- libs/gl-testing/gltesting/network.py | 56 +++++++++++++++++++++++++++ libs/gl-testing/gltesting/node.py | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 libs/gl-testing/gltesting/network.py diff --git a/libs/gl-testing/gltesting/__init__.py b/libs/gl-testing/gltesting/__init__.py index f3ba972f8..0f651bad8 100644 --- a/libs/gl-testing/gltesting/__init__.py +++ b/libs/gl-testing/gltesting/__init__.py @@ -1 +1,5 @@ from .scheduler import Scheduler + +__all__ = [ + Scheduler +] diff --git a/libs/gl-testing/gltesting/fixtures.py b/libs/gl-testing/gltesting/fixtures.py index 1cf99c6cf..913439008 100644 --- a/libs/gl-testing/gltesting/fixtures.py +++ b/libs/gl-testing/gltesting/fixtures.py @@ -10,7 +10,8 @@ from pathlib import Path import logging import sys -from pyln.testing.fixtures import bitcoind, teardown_checks, node_factory, node_cls, test_name, executor, db_provider, test_base_dir, jsonschemas +from pyln.testing.fixtures import bitcoind, teardown_checks, node_cls, test_name, executor, db_provider, test_base_dir, jsonschemas +from gltesting.network import node_factory from pyln.testing.fixtures import directory as str_directory from decimal import Decimal diff --git a/libs/gl-testing/gltesting/network.py b/libs/gl-testing/gltesting/network.py new file mode 100644 index 000000000..8e36b50f1 --- /dev/null +++ b/libs/gl-testing/gltesting/network.py @@ -0,0 +1,56 @@ +from pyln.testing.utils import NodeFactory +import pytest +from pyln.testing.fixtures import ( + bitcoind, # noqa: F401 + node_cls, # noqa: F401 + test_name, # noqa: F401 + executor, # noqa: F401 + db_provider, # noqa: F401 + jsonschemas, # noqa: F401 +) + + +class GlNodeFactory(NodeFactory): + """A temporary shim until pyln-testing learns to run multiple versions + + This adds the v24.02 `--developer` option, which was not required before. + + TODO Remove this shim onces pyln-testing learns about versions + PR: https://github.com/ElementsProject/lightning/pull/7173 + """ + + def get_node(self, options=None, *args, **kwargs): + # Until pyln-testing learns to differentiate versions we need + # to do this whenever we start a new node. pyln-testing v24.05 + # promises to be multi-version compatible. + if options is None: + options = {} + options["allow-deprecated-apis"] = True + options["developer"] = None + return NodeFactory.get_node(self, options=options, *args, **kwargs) + + +@pytest.fixture +def node_factory( + request, # noqa: F811 + directory, + test_name, + bitcoind, + executor, + db_provider, + node_cls, + jsonschemas, +): + nf = GlNodeFactory( + request, + test_name, + bitcoind, + executor, + directory=directory, + db_provider=db_provider, + node_cls=node_cls, + jsonschemas=jsonschemas, + ) + + yield nf + nf.killall([not n.may_fail for n in nf.nodes]) diff --git a/libs/gl-testing/gltesting/node.py b/libs/gl-testing/gltesting/node.py index e4a126d36..0f6f73578 100644 --- a/libs/gl-testing/gltesting/node.py +++ b/libs/gl-testing/gltesting/node.py @@ -96,6 +96,7 @@ def __init__( '--dev-fast-gossip', '--offline', '--experimental-anchors', + '--developer', # TODO Make this multi-version capable ] def write_node_config(self, network: str):