start-coin-daemons.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python3
  2. import sys
  3. from tests_header import repo_root
  4. from mmgen.common import *
  5. from mmgen.daemon import CoinDaemon
  6. from mmgen.regtest import MMGenRegtest
  7. action = g.prog_name.split('-')[0]
  8. opts_data = {
  9. 'sets': [('debug',True,'verbose',True)],
  10. 'text': {
  11. 'desc': '{} coin daemons for the MMGen test suite'.format(action.capitalize()),
  12. 'usage':'[opts] <network IDs>',
  13. 'options': """
  14. -h, --help Print this help message
  15. --, --longhelp Print help message for long options (common options)
  16. -d, --debug Produce debugging output (implies --verbose)
  17. -r, --regtest-user=U {a} a regtest daemon for user 'U'
  18. -s, --get-state Get the state of the daemon(s) and exit
  19. -t, --testing Testing mode. Print commands but don't execute them
  20. -v, --verbose Produce more verbose output
  21. -W, --no-wait Don't wait for daemons to change state before exiting
  22. """,
  23. 'notes': """
  24. Valid network IDs: {nid}, all, or no_xmr
  25. Valid Regtest network IDs: {rid}, or all
  26. Valid Regtest users: {ru}
  27. """
  28. },
  29. 'code': {
  30. 'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name),
  31. 'notes': lambda s: s.format(
  32. nid=', '.join(CoinDaemon.network_ids),
  33. rid=', '.join(MMGenRegtest.coins),
  34. ru=', '.join(MMGenRegtest.users),
  35. )
  36. }
  37. }
  38. cmd_args = opts.init(opts_data)
  39. if 'all' in cmd_args or 'no_xmr' in cmd_args:
  40. if len(cmd_args) != 1:
  41. die(1,"'all' or 'no_xmr' must be the sole argument")
  42. if opt.regtest_user:
  43. ids = MMGenRegtest.coins
  44. else:
  45. ids = list(CoinDaemon.network_ids)
  46. if cmd_args[0] == 'no_xmr':
  47. ids.remove('xmr')
  48. else:
  49. ids = cmd_args
  50. if not ids:
  51. opts.usage()
  52. for i in ids:
  53. if i not in CoinDaemon.network_ids:
  54. die(1,'{!r}: invalid network ID'.format(i))
  55. if 'eth' in ids and 'etc' in ids:
  56. msg('Cannot run ETH and ETC simultaneously, so skipping ETC')
  57. ids.remove('etc')
  58. for network_id in ids:
  59. network_id = network_id.lower()
  60. if opt.regtest_user:
  61. d = MMGenRegtest(network_id).test_daemon(opt.regtest_user)
  62. else:
  63. if network_id.endswith('_rt'):
  64. continue
  65. d = CoinDaemon(network_id,test_suite=True)
  66. d.debug = opt.debug
  67. d.wait = not opt.no_wait
  68. if opt.get_state:
  69. print('{} {} is {}'.format(d.net_desc,d.desc,d.state))
  70. elif opt.testing:
  71. print(' '.join(getattr(d,action+'_cmd')))
  72. else:
  73. d.cmd(action)