main_regtest.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 The MMGen Project <mmgen@tuta.io>
  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 = {
  24. 'sets': [('yes', True, 'quiet', True)],
  25. 'text': {
  26. 'desc': 'Coin daemon regression test mode setup and operations for the {} suite'.format(g.proj_name),
  27. 'usage': '[opts] <command>',
  28. 'options': """
  29. -h, --help Print this help message
  30. --, --longhelp Print help message for long options (common options)
  31. -e, --empty Don't fund Bob and Alice's wallets on setup
  32. -n, --setup-no-stop-daemon Don't stop daemon after setup is finished
  33. -q, --quiet Produce quieter output
  34. -v, --verbose Produce more verbose output
  35. """,
  36. 'notes': """
  37. AVAILABLE COMMANDS
  38. setup - set up system for regtest operation with MMGen
  39. fork COIN - create a fork of coin COIN
  40. stop - stop the regtest coin daemon
  41. bob - switch to Bob's wallet, starting daemon if necessary
  42. alice - switch to Alice's wallet, starting daemon if necessary
  43. user - show current user
  44. generate N - mine n blocks (defaults to 1)
  45. send ADDR AMT - send amount AMT of miner funds to address ADDR
  46. test_daemon - test whether daemon is running
  47. get_balances - get balances of Bob and Alice
  48. show_mempool - show transaction IDs in mempool
  49. cli [arguments] - execute an RPC call with arguments
  50. """
  51. }
  52. }
  53. cmd_args = opts.init(opts_data)
  54. cmds = ('setup','stop','generate','test_daemon','create_data_dir','bob','alice','miner','user','send',
  55. 'wait_for_daemon','wait_for_exit','get_current_user','get_balances','show_mempool','cli','fork')
  56. try:
  57. if cmd_args[0] == 'send':
  58. assert len(cmd_args) == 3
  59. elif cmd_args[0] == 'fork':
  60. assert len(cmd_args) == 2
  61. elif cmd_args[0] == 'generate':
  62. assert len(cmd_args) in (1,2)
  63. if len(cmd_args) == 2:
  64. cmd_args[1] = int(cmd_args[1])
  65. elif cmd_args[0] == 'cli':
  66. pass
  67. else:
  68. assert cmd_args[0] in cmds and len(cmd_args) == 1
  69. except:
  70. opts.usage()
  71. else:
  72. from mmgen.regtest import *
  73. globals()[cmd_args[0]](*cmd_args[1:])