Browse Source

plugin: add in deprecated_api behavior and test

we also check that the node isn't running now, for extra pedancity
travis-debug
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
41b18050a0
  1. 6
      lightningd/plugin.c
  2. 19
      tests/test_plugin.py

6
lightningd/plugin.c

@ -1128,11 +1128,13 @@ plugin_populate_init_request(struct plugin *plugin, struct jsonrpc_request *req)
name = opt->name + 2;
if (opt->value->as_bool) {
json_add_bool(req->stream, name, *opt->value->as_bool);
continue;
if (!deprecated_apis)
continue;
}
if (opt->value->as_int) {
json_add_s64(req->stream, name, *opt->value->as_int);
continue;
if (!deprecated_apis)
continue;
}
if (opt->value->as_str) {
json_add_string(req->stream, name, opt->value->as_str);

19
tests/test_plugin.py

@ -55,7 +55,7 @@ def test_option_types(node_factory):
'plugin': plugin_path,
'str_opt': 'ok',
'int_opt': 22,
'bool_opt': 1,
'bool_opt': True,
})
n.daemon.is_in_log(r"option str_opt ok <class 'str'>")
@ -82,6 +82,7 @@ def test_option_types(node_factory):
}, expect_fail=True, may_fail=True)
# the node should fail to start, and we get a stderr msg
assert not n.daemon.running
assert n.daemon.is_in_stderr('bool_opt: ! does not parse as type bool')
# What happens if we give it a bad int-option?
@ -93,8 +94,24 @@ def test_option_types(node_factory):
}, may_fail=True, expect_fail=True)
# the node should fail to start, and we get a stderr msg
assert not n.daemon.running
assert n.daemon.is_in_stderr('--int_opt: notok does not parse as type int')
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 <class 'str'>")
n.daemon.is_in_log(r"option int_opt 22 <class 'int'>")
n.daemon.is_in_log(r"option int_opt 22 <class 'str'>")
n.daemon.is_in_log(r"option bool_opt True <class 'bool'>")
n.daemon.is_in_log(r"option bool_opt true <class 'str'>")
n.stop()
def test_millisatoshi_passthrough(node_factory):
""" Ensure that Millisatoshi arguments and return work.

Loading…
Cancel
Save