diff --git a/tests/plugins/options.py b/tests/plugins/options.py new file mode 100755 index 000000000..cb08d0b0b --- /dev/null +++ b/tests/plugins/options.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +"""This plugin is used to check that plugin options are parsed properly. + +The plugin offers 3 options, one of each supported type. +""" +from lightning import Plugin + +plugin = Plugin() + + +@plugin.init() +def init(configuration, options, plugin): + for name, val in options.items(): + plugin.log("option {} {} {}".format(name, val, type(val))) + + +plugin.add_option('str_opt', 'i am a string', 'an example string option') +plugin.add_option('int_opt', 7, 'an example int type option', opt_type='int') +plugin.add_option('bool_opt', True, 'an example bool type option', opt_type='bool') +plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 6351ba7f2..f3eebbbfd 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -46,6 +46,56 @@ def test_option_passthrough(node_factory, directory): n.stop() +def test_option_types(node_factory): + """Ensure that desired types of options are + respected in output """ + + plugin_path = os.path.join(os.getcwd(), 'tests/plugins/options.py') + n = node_factory.get_node(options={ + 'plugin': plugin_path, + 'str_opt': 'ok', + 'int_opt': 22, + 'bool_opt': 1, + }) + + n.daemon.is_in_log(r"option str_opt ok ") + n.daemon.is_in_log(r"option int_opt 22 ") + n.daemon.is_in_log(r"option bool_opt True ") + n.stop() + + # A blank bool_opt should default to false + n = node_factory.get_node(options={ + 'plugin': plugin_path, 'str_opt': 'ok', + 'int_opt': 22, + 'bool_opt': '', + }) + + n.daemon.is_in_log(r"option bool_opt False ") + n.stop() + + # What happens if we give it a bad bool-option? + n = node_factory.get_node(options={ + 'plugin': plugin_path, + 'str_opt': 'ok', + 'int_opt': 22, + 'bool_opt': '!', + }, expect_fail=True, may_fail=True) + + # the node should fail to start, and we get a stderr msg + assert n.daemon.is_in_stderr('bool_opt: ! does not parse as type bool') + + # What happens if we give it a bad int-option? + n = node_factory.get_node(options={ + 'plugin': plugin_path, + 'str_opt': 'ok', + 'int_opt': 'notok', + 'bool_opt': 1, + }, may_fail=True, expect_fail=True) + + # the node should fail to start, and we get a stderr msg + assert n.daemon.is_in_stderr('--int_opt: notok does not parse as type int') + + def test_millisatoshi_passthrough(node_factory): """ Ensure that Millisatoshi arguments and return work. """