Skip to content

Commit

Permalink
plugin: add in deprecated_api behavior and test
Browse files Browse the repository at this point in the history
we also check that the node isn't running now, for extra pedancity
  • Loading branch information
niftynei authored and rustyrussell committed Mar 10, 2020
1 parent b25a8ba commit 41b1805
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'>")
Expand All @@ -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?
Expand All @@ -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.
Expand Down

0 comments on commit 41b1805

Please sign in to comment.