ct_opts.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2024 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # Project source code repository: https://github.com/mmgen/mmgen-wallet
  7. # Licensed according to the terms of GPL Version 3. See LICENSE for details.
  8. """
  9. test.cmdtest_py_d.ct_opts: options processing tests for the MMGen cmdtest.py test suite
  10. """
  11. import os,time
  12. from ..include.common import cfg
  13. from .ct_base import CmdTestBase
  14. class CmdTestOpts(CmdTestBase):
  15. 'options processing'
  16. networks = ('btc',)
  17. tmpdir_nums = [41]
  18. cmd_group = (
  19. ('opt_helpscreen', (41,"helpscreen output", [])),
  20. ('opt_noargs', (41,"invocation with no user options or arguments", [])),
  21. ('opt_good', (41,"good opts", [])),
  22. ('opt_bad_infile', (41,"bad infile parameter", [])),
  23. ('opt_bad_outdir', (41,"bad outdir parameter", [])),
  24. ('opt_bad_incompatible', (41,"incompatible opts", [])),
  25. ('opt_bad_autoset', (41,"invalid autoset value", [])),
  26. )
  27. def spawn_prog(self, args, exit_val=None):
  28. return self.spawn('test/misc/opts.py', args, cmd_dir='.', exit_val=exit_val)
  29. def check_vals(self,args,vals):
  30. t = self.spawn_prog(args)
  31. for k,v in vals:
  32. t.expect(rf'{k}:\s+{v}',regex=True)
  33. return t
  34. def do_run(self,args,expect,exit_val,regex=False):
  35. t = self.spawn_prog(args, exit_val=exit_val or None)
  36. t.expect(expect,regex=regex)
  37. return t
  38. def opt_helpscreen(self):
  39. expect = r'OPTS.PY: Opts test.*USAGE:\s+opts.py'
  40. if not cfg.pexpect_spawn:
  41. expect += r'.*--minconf.*NOTES FOR THIS.*a note'
  42. t = self.do_run( ['--help'], expect, 0, regex=True )
  43. if t.pexpect_spawn:
  44. time.sleep(0.4)
  45. t.send('q')
  46. return t
  47. def opt_noargs(self):
  48. return self.check_vals(
  49. [],
  50. (
  51. ('cfg.foo', 'None'), # added opt
  52. ('cfg.print_checksum', 'None'), # sets 'quiet'
  53. ('cfg.quiet', 'False'), # _incompatible_opts
  54. ('cfg.verbose', 'False'), # _incompatible_opts
  55. ('cfg.passwd_file', ''), # _infile_opts - check_infile()
  56. ('cfg.outdir', ''), # check_outdir()
  57. ('cfg.cached_balances', 'False'),
  58. ('cfg.minconf', '1'),
  59. ('cfg.fee_estimate_mode', 'conservative'), # _autoset_opts
  60. )
  61. )
  62. def opt_good(self):
  63. pf_base = 'testfile'
  64. pf = os.path.join(self.tmpdir,pf_base)
  65. self.write_to_tmpfile(pf_base,'')
  66. return self.check_vals(
  67. [
  68. '--print-checksum',
  69. '--fee-estimate-mode=E',
  70. '--passwd-file='+pf,
  71. '--outdir='+self.tmpdir,
  72. '--cached-balances',
  73. f'--hidden-incog-input-params={pf},123',
  74. ],
  75. (
  76. ('cfg.print_checksum', 'True'),
  77. ('cfg.quiet', 'True'), # set by print_checksum
  78. ('cfg.passwd_file', pf),
  79. ('cfg.outdir', self.tmpdir),
  80. ('cfg.cached_balances', 'True'),
  81. ('cfg.hidden_incog_input_params', pf+',123'),
  82. ('cfg.fee_estimate_mode', 'economical'),
  83. )
  84. )
  85. def opt_bad_infile(self):
  86. pf = os.path.join(self.tmpdir,'fubar')
  87. return self.do_run(['--passwd-file='+pf],'not found',1)
  88. def opt_bad_outdir(self):
  89. bo = self.tmpdir+'_fubar'
  90. return self.do_run(['--outdir='+bo],'not found',1)
  91. def opt_bad_incompatible(self):
  92. return self.do_run(['--label=Label','--keep-label'],'Conflicting options',1)
  93. def opt_bad_autoset(self):
  94. return self.do_run(['--fee-estimate-mode=Fubar'],'not unique substring',1)