Skip to content

Commit 2e02341

Browse files
committed
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.
1 parent efb6dde commit 2e02341

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/functional/test_framework/test_node.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ def __call__(self, *args, **kwargs):
402402
def get_request(self, *args, **kwargs):
403403
return lambda: self(*args, **kwargs)
404404

405+
def arg_to_cli(arg):
406+
if isinstance(arg, bool):
407+
return str(arg).lower()
408+
elif isinstance(arg, dict) or isinstance(arg, list):
409+
return json.dumps(arg)
410+
else:
411+
return str(arg)
412+
405413
class TestNodeCLI():
406414
"""Interface to bitcoin-cli for an individual node"""
407415

@@ -433,8 +441,8 @@ def batch(self, requests):
433441

434442
def send_cli(self, command=None, *args, **kwargs):
435443
"""Run bitcoin-cli command. Deserializes returned string as python object."""
436-
pos_args = [str(arg).lower() if type(arg) is bool else str(arg) for arg in args]
437-
named_args = [str(key) + "=" + str(value) for (key, value) in kwargs.items()]
444+
pos_args = [arg_to_cli(arg) for arg in args]
445+
named_args = [str(key) + "=" + arg_to_cli(value) for (key, value) in kwargs.items()]
438446
assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same bitcoin-cli call"
439447
p_args = [self.binary, "-datadir=" + self.datadir] + self.options
440448
if named_args:

0 commit comments

Comments
 (0)