Skip to content

Commit

Permalink
Merge #15301: tests: When testing with --usecli, unify RPC arg to cli…
Browse files Browse the repository at this point in the history
… arg conversion and handle dicts and lists

2e02341 tests: unify RPC argument to cli argument conversion and handle dicts and lists (Andrew Chow)

Pull request description:

  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.

Tree-SHA512: 472bef3cd78410a8552fd342b1852bcd7c57721cfa9176b26bacda6b0791cc0b3758561a529c4117a7428242f98bb7d5482b2a2dcd06bea0ef2b15ae26183405
  • Loading branch information
MarcoFalke committed Jan 31, 2019
2 parents 3b19d8e + 2e02341 commit cb35f1d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ def __call__(self, *args, **kwargs):
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"""

Expand Down Expand Up @@ -433,8 +441,8 @@ def batch(self, requests):

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:
Expand Down

0 comments on commit cb35f1d

Please sign in to comment.