From 966ac9509856707c05b50c418e9ac22aefdfa356 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 29 Jan 2020 22:33:10 +0100 Subject: [PATCH] pytest: Add a test for plugin featurebits --- Makefile | 2 +- contrib/pyln-proto/requirements.txt | 2 +- tests/plugins/feature-test.py | 14 +++++++++++ tests/test_plugin.py | 39 +++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100755 tests/plugins/feature-test.py diff --git a/Makefile b/Makefile index 35b91d553..749e6ddab 100644 --- a/Makefile +++ b/Makefile @@ -266,7 +266,7 @@ ifeq ($(PYTEST),) exit 1 else # Explicitly hand DEVELOPER and VALGRIND so you can override on make cmd line. - PYTHONPATH=`pwd`/contrib/pyln-client:`pwd`/contrib/pyln-testing:`pwd`/contrib/pylightning:$$PYTHONPATH TEST_DEBUG=1 DEVELOPER=$(DEVELOPER) VALGRIND=$(VALGRIND) $(PYTEST) tests/ $(PYTEST_OPTS) + PYTHONPATH=`pwd`/contrib/pyln-client:`pwd`/contrib/pyln-testing:`pwd`/contrib/pylightning:`pwd`/contrib/pyln-proto/:$(PYTHONPATH) TEST_DEBUG=1 DEVELOPER=$(DEVELOPER) VALGRIND=$(VALGRIND) $(PYTEST) tests/ $(PYTEST_OPTS) endif # Keep includes in alpha order. diff --git a/contrib/pyln-proto/requirements.txt b/contrib/pyln-proto/requirements.txt index 7784497bf..5f6659d85 100644 --- a/contrib/pyln-proto/requirements.txt +++ b/contrib/pyln-proto/requirements.txt @@ -1,5 +1,5 @@ bitstring==3.1.6 -cryptography==2.7 +cryptography==2.8 coincurve==12.0.0 base58==1.0.2 secp256k1==0.13.2 diff --git a/tests/plugins/feature-test.py b/tests/plugins/feature-test.py new file mode 100755 index 000000000..e43954208 --- /dev/null +++ b/tests/plugins/feature-test.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +from pyln.client import Plugin + +# Register a different set feature of feature bits for each location so we can +# later check that they are being passed correctly. +plugin = Plugin( + init_features=1 << 101, + node_features=1 << 103, + invoice_features=1 << 105, +) + + +plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 53a4eb233..5b6710641 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2,6 +2,7 @@ from collections import OrderedDict from fixtures import * # noqa: F401,F403 from flaky import flaky # noqa: F401 from pyln.client import RpcError, Millisatoshi +from pyln.proto import Invoice from utils import ( DEVELOPER, only_one, sync_blockheight, TIMEOUT, wait_for, TEST_NETWORK ) @@ -823,3 +824,41 @@ def test_libplugin(node_factory): # Test RPC calls FIXME: test concurrent ones ? assert l1.rpc.call("testrpc") == l1.rpc.getinfo() + + +@pytest.mark.xfail(strict=True) +@unittest.skipIf(not DEVELOPER, "needs LIGHTNINGD_DEV_LOG_IO") +def test_plugin_feature_announce(node_factory): + """Check that features registered by plugins show up in messages. + + l1 is the node under test, l2 only serves as the counterparty for a + channel to check the featurebits in the `channel_announcement`. The plugin + registers an individual featurebit for each of the locations we can stash + feature bits in: + + - 1 << 101 for `init` messages + - 1 << 103 for `node_announcement` + - 1 << 105 for bolt11 invoices + + """ + plugin = os.path.join(os.path.dirname(__file__), 'plugins/feature-test.py') + l1, l2 = node_factory.line_graph( + 2, opts=[{'plugin': plugin, 'log-level': 'io'}, {}], + wait_for_announce=True + ) + + # Check the featurebits we've set in the `init` message from + # feature-test.py. (1 << 101) results in 13 bytes featutebits (000d) and + # has a leading 0x20, the remainder is added to avoid false positives, but + # may cause failures if we add support for more native featurebits. + init = l1.daemon.is_in_log(r'\[OUT\] 001000.*000d2000000000000000000002aaa2') + assert(init is not None) # Make sure we caught the log message + + # Check the invoice featurebit we set in feature-test.py + inv = l1.rpc.invoice(123, 'lbl', 'desc')['bolt11'] + details = Invoice.decode(inv) + assert(details.featurebits.int & (1 << 105) != 0) + + # Check the featurebit set in the `node_announcement` + node = l1.rpc.listnodes(l1.info['id'])['nodes'][0] + assert(int(node['features'], 16) & (1 << 103) != 0)