main_regtest.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2017 Philemon <mmgen-py@yandex.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. mmgen-regtest: Coin daemon regression test mode setup and operations for the MMGen
  20. suite
  21. """
  22. from mmgen.common import *
  23. opts_data = lambda: {
  24. 'desc': 'Coin daemon regression test mode setup and operations for the {} suite'.format(g.proj_name),
  25. 'usage': '[opts] <command>',
  26. 'sets': ( ('yes', True, 'quiet', True), ),
  27. 'options': """
  28. -h, --help Print this help message
  29. --, --longhelp Print help message for long options (common options)
  30. -e, --empty Don't fund Bob and Alice's wallets on setup
  31. -n, --setup-no-stop-daemon Don't stop daemon after setup is finished
  32. -q, --quiet Produce quieter output
  33. -v, --verbose Produce more verbose output
  34. """,
  35. 'notes': """
  36. AVAILABLE COMMANDS
  37. setup - set up system for regtest operation with MMGen
  38. fork COIN - create a fork of coin COIN
  39. stop - stop the regtest coin daemon
  40. bob - switch to Bob's wallet, starting daemon if necessary
  41. alice - switch to Alice's wallet, starting daemon if necessary
  42. user - show current user
  43. generate N - mine n blocks (defaults to 1)
  44. send ADDR AMT - send amount AMT of miner funds to address ADDR
  45. test_daemon - test whether daemon is running
  46. get_balances - get balances of Bob and Alice
  47. show_mempool - show transaction IDs in mempool
  48. cli [arguments] - execute an RPC call with arguments
  49. """
  50. }
  51. cmd_args = opts.init(opts_data)
  52. cmds = ('setup','stop','generate','test_daemon','create_data_dir','bob','alice','miner','user','send',
  53. 'wait_for_daemon','wait_for_exit','get_current_user','get_balances','show_mempool','cli','fork')
  54. try:
  55. if cmd_args[0] == 'send':
  56. assert len(cmd_args) == 3
  57. elif cmd_args[0] == 'fork':
  58. assert len(cmd_args) == 2
  59. elif cmd_args[0] == 'generate':
  60. assert len(cmd_args) in (1,2)
  61. if len(cmd_args) == 2:
  62. cmd_args[1] = int(cmd_args[1])
  63. elif cmd_args[0] == 'cli':
  64. pass
  65. else:
  66. assert cmd_args[0] in cmds and len(cmd_args) == 1
  67. except:
  68. opts.usage()
  69. else:
  70. from mmgen.regtest import *
  71. globals()[cmd_args[0]](*cmd_args[1:])