ts_opts.py 3.6 KB

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