diff options
author | Andrew Chow <achow101-github@achow101.com> | 2019-01-23 15:51:35 -0500 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2019-01-31 12:37:33 -0500 |
commit | 2e023419c5e77ba66fe1182cbc2bcabce59ea795 (patch) | |
tree | 158c1588ca889f764ebdefe9eb8ad6af7c293676 /test | |
parent | efb6ddef9cb341428cbedf4373d1bdd19685a827 (diff) |
tests: unify RPC argument to cli argument conversion and handle dicts and lists
When running tests with --usecli, unify the conversion from argument objects to
strings using a new function arg_to_cli(). This fixes boolean arguments when
using named arguments.
Also use json.dumps() to get the string values for arguments that are dicts and
lists so that bitcoind's JSON parser does not become confused.
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/test_framework/test_node.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 031a8824b1..6745409964 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -402,6 +402,14 @@ class TestNodeCLIAttr: def get_request(self, *args, **kwargs): return lambda: self(*args, **kwargs) +def arg_to_cli(arg): + if isinstance(arg, bool): + return str(arg).lower() + elif isinstance(arg, dict) or isinstance(arg, list): + return json.dumps(arg) + else: + return str(arg) + class TestNodeCLI(): """Interface to bitcoin-cli for an individual node""" @@ -433,8 +441,8 @@ class TestNodeCLI(): def send_cli(self, command=None, *args, **kwargs): """Run bitcoin-cli command. Deserializes returned string as python object.""" - pos_args = [str(arg).lower() if type(arg) is bool else str(arg) for arg in args] - named_args = [str(key) + "=" + str(value) for (key, value) in kwargs.items()] + pos_args = [arg_to_cli(arg) for arg in args] + named_args = [str(key) + "=" + arg_to_cli(value) for (key, value) in kwargs.items()] assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same bitcoin-cli call" p_args = [self.binary, "-datadir=" + self.datadir] + self.options if named_args: |