diff --git a/tests/data/recklessrepo/lightningd/testplugpass/requirements.txt b/tests/data/recklessrepo/lightningd/testplugpass/requirements.txt index e69de29bb2d1..7b19e677138d 100644 --- a/tests/data/recklessrepo/lightningd/testplugpass/requirements.txt +++ b/tests/data/recklessrepo/lightningd/testplugpass/requirements.txt @@ -0,0 +1,2 @@ +pyln-client + diff --git a/tests/data/recklessrepo/lightningd/testplugpass/testplugpass.py b/tests/data/recklessrepo/lightningd/testplugpass/testplugpass.py index 444043531dab..435f979f23a0 100755 --- a/tests/data/recklessrepo/lightningd/testplugpass/testplugpass.py +++ b/tests/data/recklessrepo/lightningd/testplugpass/testplugpass.py @@ -3,6 +3,8 @@ plugin = Plugin() +__version__ = 'v1' + @plugin.init() def init(options, configuration, plugin, **kwargs): @@ -14,4 +16,10 @@ def testmethod(plugin): return ("I live.") +@plugin.method("gettestplugversion") +def gettestplugversion(plugin): + "to test commit/tag checkout" + return __version__ + + plugin.run() diff --git a/tests/data/recklessrepo/lightningd/testplugpyproj/pyproject.toml b/tests/data/recklessrepo/lightningd/testplugpyproj/pyproject.toml new file mode 100644 index 000000000000..738c943c0878 --- /dev/null +++ b/tests/data/recklessrepo/lightningd/testplugpyproj/pyproject.toml @@ -0,0 +1,17 @@ +[project] +dependencies = ["pyln-client"] + +[tool.poetry] +name = "testplugpyproj" +version = "0.1.0" +description = "testing poetry installation of python plugins" +authors = ["Alex Myers "] + +[tool.poetry.dependencies] +# Build dependencies belong here +python = "^3.8" +pyln-client = "^23.11" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/tests/data/recklessrepo/lightningd/testplugpyproj/testplugpyproj.py b/tests/data/recklessrepo/lightningd/testplugpyproj/testplugpyproj.py new file mode 100755 index 000000000000..444043531dab --- /dev/null +++ b/tests/data/recklessrepo/lightningd/testplugpyproj/testplugpyproj.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +from pyln.client import Plugin + +plugin = Plugin() + + +@plugin.init() +def init(options, configuration, plugin, **kwargs): + plugin.log("testplug initialized") + + +@plugin.method("testmethod") +def testmethod(plugin): + return ("I live.") + + +plugin.run() diff --git a/tests/data/recklessrepo/rkls_api_lightningd_plugins.json b/tests/data/recklessrepo/rkls_api_lightningd_plugins.json index 5c30a0232f36..3a0484f4f1ee 100644 --- a/tests/data/recklessrepo/rkls_api_lightningd_plugins.json +++ b/tests/data/recklessrepo/rkls_api_lightningd_plugins.json @@ -16,5 +16,14 @@ "git_url": "https://api.github.com/repos/lightningd/plugins/git/trees/testplugfail", "download_url": null, "type": "dir" + }, + { + "name": "testplugpyproj", + "path": "testplugpyproj", + "url": "https://api.github.com/repos/lightningd/plugins/contents/webhook?ref=master", + "html_url": "https://github.com/lightningd/plugins/tree/master/testplugpyproj", + "git_url": "https://api.github.com/repos/lightningd/plugins/git/trees/testplugpyproj", + "download_url": null, + "type": "dir" } ] diff --git a/tests/test_reckless.py b/tests/test_reckless.py index 08a7c39a63ae..2795ddd1270d 100644 --- a/tests/test_reckless.py +++ b/tests/test_reckless.py @@ -59,8 +59,15 @@ def canned_github_server(directory): repo_initialization = (f'cp -r {plugins_path}/* .;' 'git add --all;' 'git commit -m "initial commit - autogenerated by test_reckless.py";') + tag_and_update = ('git tag v1;' + "sed -i 's/v1/v2/g' testplugpass/testplugpass.py;" + 'git add testplugpass/testplugpass.py;' + 'git commit -m "update to v2";' + 'git tag v2;') subprocess.check_output([repo_initialization], env=my_env, shell=True, cwd=repo_dir) + subprocess.check_output([tag_and_update], env=my_env, + shell=True, cwd=repo_dir) del my_env['HOME'] del my_env['GIT_DIR'] del my_env['GIT_WORK_TREE'] @@ -189,6 +196,24 @@ def test_install(node_factory): assert os.path.exists(plugin_path) +def test_poetry_install(node_factory): + """test search, git clone, and installation to folder.""" + n = get_reckless_node(node_factory) + r = reckless([f"--network={NETWORK}", "-v", "install", "testplugpyproj"], dir=n.lightning_dir) + assert r.returncode == 0 + assert 'dependencies installed successfully' in r.stdout + assert 'plugin installed:' in r.stdout + assert 'testplugpyproj enabled' in r.stdout + check_stderr(r.stderr) + plugin_path = Path(n.lightning_dir) / 'reckless/testplugpyproj' + print(plugin_path) + assert os.path.exists(plugin_path) + n.start() + print(n.rpc.testmethod()) + assert n.daemon.is_in_log(r'plugin-manager: started\([0-9].*\) /tmp/ltests-[a-z0-9].*/test_poetry_install_1/lightning-1/reckless/testplugpyproj/testplugpyproj.py') + assert n.rpc.testmethod() == 'I live.' + + def test_local_dir_install(node_factory): """Test search and install from local directory source.""" n = get_reckless_node(node_factory) @@ -232,4 +257,26 @@ def test_disable_enable(node_factory): 'active': True, 'dynamic': True} time.sleep(1) print(n.rpc.plugin_list()['plugins']) - assert(test_plugin in n.rpc.plugin_list()['plugins']) + assert test_plugin in n.rpc.plugin_list()['plugins'] + + +def test_tag_install(node_factory): + "install a plugin from a specific commit hash or tag" + node = get_reckless_node(node_factory) + node.start() + r = reckless([f"--network={NETWORK}", "-v", "install", "testPlugPass"], + dir=node.lightning_dir) + assert r.returncode == 0 + # should install v2 (latest) without specifying + version = node.rpc.gettestplugversion() + assert version == 'v2' + r = reckless([f"--network={NETWORK}", "-v", "uninstall", "testplugpass"], + dir=node.lightning_dir) + r = reckless([f"--network={NETWORK}", "-v", "install", "testplugpass@v1"], + dir=node.lightning_dir) + assert r.returncode == 0 + # v1 should now be checked out. + version = node.rpc.gettestplugversion() + assert version == 'v1' + installed_path = Path(node.lightning_dir) / 'reckless/testplugpass' + assert installed_path.is_dir()