Skip to content

Commit 5932d3b

Browse files
nepetrustyrussell
authored andcommitted
test: check that features get removed when ...
a plugin is disabled during init. Signed-off-by: Peter Neuroth <[email protected]>
1 parent 652b3c2 commit 5932d3b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/plugins/feature-test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
from pyln.client import Plugin
4+
import os
45

56
# Register a different set feature of feature bits for each location so we can
67
# later check that they are being passed correctly.
@@ -12,4 +13,12 @@
1213
)
1314

1415

16+
@plugin.init()
17+
def init(configuration, options, plugin):
18+
disable = os.getenv("PLUGIN_DISABLE")
19+
if disable:
20+
return {'disable': 'init saying disable'}
21+
return {}
22+
23+
1524
plugin.run()

tests/test_plugin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,28 @@ def test_plugin_feature_announce(node_factory):
17481748
assert node['features'] == expected_node_features(extra=[203])
17491749

17501750

1751+
def test_plugin_feature_remove(node_factory, monkeypatch):
1752+
"""Check that features registered by plugins get removed if a plugin
1753+
disables itself.
1754+
1755+
We set the following feature bits we don't want to include if the plugin is
1756+
disabled during init.
1757+
- 1 << 201 for `init` messages
1758+
- 1 << 203 for `node_announcement`
1759+
- 1 << 205 for bolt11 invoices
1760+
"""
1761+
1762+
monkeypatch.setenv("PLUGIN_DISABLE", "1")
1763+
plugin = os.path.join(os.path.dirname(__file__), 'plugins/feature-test.py')
1764+
l1 = node_factory.get_node(options={'plugin': plugin})
1765+
1766+
# Check that we don't include the features set in getmanifest.
1767+
our_feats = l1.rpc.getinfo()["our_features"]
1768+
assert((int(our_feats["init"], 16) & (1 << 201)) == 0)
1769+
assert((int(our_feats["node"], 16) & (1 << 203)) == 0)
1770+
assert((int(our_feats["invoice"], 16) & (1 << 205)) == 0)
1771+
1772+
17511773
def test_hook_chaining(node_factory):
17521774
"""Check that hooks are called in order and the chain exits correctly
17531775

0 commit comments

Comments
 (0)