mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
pytest: Add a test for plugin featurebits
This commit is contained in:
parent
a13591400a
commit
966ac95098
2
Makefile
2
Makefile
@ -266,7 +266,7 @@ ifeq ($(PYTEST),)
|
|||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Explicitly hand DEVELOPER and VALGRIND so you can override on make cmd line.
|
# 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
|
endif
|
||||||
|
|
||||||
# Keep includes in alpha order.
|
# Keep includes in alpha order.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
bitstring==3.1.6
|
bitstring==3.1.6
|
||||||
cryptography==2.7
|
cryptography==2.8
|
||||||
coincurve==12.0.0
|
coincurve==12.0.0
|
||||||
base58==1.0.2
|
base58==1.0.2
|
||||||
secp256k1==0.13.2
|
secp256k1==0.13.2
|
||||||
|
14
tests/plugins/feature-test.py
Executable file
14
tests/plugins/feature-test.py
Executable file
@ -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()
|
@ -2,6 +2,7 @@ from collections import OrderedDict
|
|||||||
from fixtures import * # noqa: F401,F403
|
from fixtures import * # noqa: F401,F403
|
||||||
from flaky import flaky # noqa: F401
|
from flaky import flaky # noqa: F401
|
||||||
from pyln.client import RpcError, Millisatoshi
|
from pyln.client import RpcError, Millisatoshi
|
||||||
|
from pyln.proto import Invoice
|
||||||
from utils import (
|
from utils import (
|
||||||
DEVELOPER, only_one, sync_blockheight, TIMEOUT, wait_for, TEST_NETWORK
|
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 ?
|
# Test RPC calls FIXME: test concurrent ones ?
|
||||||
assert l1.rpc.call("testrpc") == l1.rpc.getinfo()
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user