diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2020-08-18 11:43:42 -0400 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2022-11-05 05:32:39 -0400 |
commit | d8b12a75dbfdc1d3e62352f0fa815bbbdc685caf (patch) | |
tree | bb0ff4c040506be8802d35c8e53e3777e9b4a649 /test/functional/interface_bitcoin_cli.py | |
parent | 50422b770a40f5fa964201d1e99fd6b5dc1653ca (diff) |
rpc: Allow named and positional arguments to be used together
It's nice to be able to use named options and positional arguments together.
Most shell tools accept both, and python functions combine options and
arguments allowing them to be passed with even more flexibility. This change
adds support for python's approach so as a motivating example:
bitcoin-cli -named createwallet wallet_name=mywallet load_on_startup=1
Can be shortened to:
bitcoin-cli -named createwallet mywallet load_on_startup=1
JSON-RPC standard doesn't have a convention for passing named and positional
parameters together, so this implementation makes one up and interprets any
unused "args" named parameter as a positional parameter array.
Diffstat (limited to 'test/functional/interface_bitcoin_cli.py')
-rwxr-xr-x | test/functional/interface_bitcoin_cli.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py index db5564ac50..9a6366b083 100755 --- a/test/functional/interface_bitcoin_cli.py +++ b/test/functional/interface_bitcoin_cli.py @@ -84,6 +84,11 @@ class TestBitcoinCli(BitcoinTestFramework): rpc_response = self.nodes[0].getblockchaininfo() assert_equal(cli_response, rpc_response) + self.log.info("Test named arguments") + assert_equal(self.nodes[0].cli.echo(0, 1, arg3=3, arg5=5), ['0', '1', None, '3', None, '5']) + assert_raises_rpc_error(-8, "Parameter arg1 specified twice both as positional and named argument", self.nodes[0].cli.echo, 0, 1, arg1=1) + assert_raises_rpc_error(-8, "Parameter arg1 specified twice both as positional and named argument", self.nodes[0].cli.echo, 0, None, 2, arg1=1) + user, password = get_auth_cookie(self.nodes[0].datadir, self.chain) self.log.info("Test -stdinrpcpass option") |