You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rpcnamedargs.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2016 The Bitcoin Core developers
  3. # Distributed under the MIT software license, see the accompanying
  4. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. """Test using named arguments for RPCs."""
  6. from test_framework.test_framework import BitcoinTestFramework
  7. from test_framework.util import (
  8. assert_equal,
  9. assert_raises_jsonrpc,
  10. start_nodes,
  11. )
  12. class NamedArgumentTest(BitcoinTestFramework):
  13. """
  14. Test named arguments on RPC calls.
  15. """
  16. def __init__(self):
  17. super().__init__()
  18. self.setup_clean_chain = False
  19. self.num_nodes = 1
  20. def setup_network(self, split=False):
  21. self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
  22. self.is_network_split = False
  23. self.sync_all()
  24. def run_test(self):
  25. node = self.nodes[0]
  26. h = node.help(command='getinfo')
  27. assert(h.startswith('getinfo\n'))
  28. assert_raises_jsonrpc(-8, 'Unknown named parameter', node.help, random='getinfo')
  29. h = node.getblockhash(height=0)
  30. node.getblock(blockhash=h)
  31. assert_equal(node.echo(), [])
  32. assert_equal(node.echo(arg0=0,arg9=9), [0] + [None]*8 + [9])
  33. assert_equal(node.echo(arg1=1), [None, 1])
  34. assert_equal(node.echo(arg9=None), [None]*10)
  35. assert_equal(node.echo(arg0=0,arg3=3,arg9=9), [0] + [None]*2 + [3] + [None]*5 + [9])
  36. if __name__ == '__main__':
  37. NamedArgumentTest().main()