ts_base.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2021 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. ts_base.py: Base class for the test.py test suite
  20. """
  21. import os
  22. from mmgen.globalvars import g
  23. from mmgen.opts import opt
  24. from ..include.common import *
  25. from .common import *
  26. class TestSuiteBase(object):
  27. 'initializer class for the test.py test suite'
  28. base_passthru_opts = ('data_dir',)
  29. passthru_opts = ()
  30. extra_spawn_args = []
  31. networks = ()
  32. segwit_opts_ok = False
  33. color = False
  34. def __init__(self,trunner,cfgs,spawn):
  35. from mmgen.protocol import init_proto_from_opts
  36. self.proto = init_proto_from_opts()
  37. self.tr = trunner
  38. self.cfgs = cfgs
  39. self.spawn = spawn
  40. self.have_dfl_wallet = False
  41. self.usr_rand_chars = (5,30)[bool(opt.usr_random)]
  42. self.usr_rand_arg = '-r{}'.format(self.usr_rand_chars)
  43. self.altcoin_pfx = '' if self.proto.base_coin == 'BTC' else '-'+self.proto.base_coin
  44. self.tn_ext = ('','.testnet')[self.proto.testnet]
  45. d = {'bch':'btc','btc':'btc','ltc':'ltc'}
  46. self.fork = d[self.proto.coin.lower()] if self.proto.coin.lower() in d else None
  47. @property
  48. def tmpdir(self):
  49. return os.path.join('test','tmp{}{}'.format(self.tmpdir_num,'-α' if g.debug_utf8 else ''))
  50. @property
  51. def segwit_mmtype(self):
  52. return ('segwit','bech32')[bool(opt.bech32)] if self.segwit else None
  53. @property
  54. def segwit_arg(self):
  55. return ['--type=' + self.segwit_mmtype] if self.segwit_mmtype else []
  56. def get_file_with_ext(self,ext,**kwargs):
  57. return get_file_with_ext(self.tmpdir,ext,**kwargs)
  58. def read_from_tmpfile(self,fn,binary=False):
  59. return read_from_file(os.path.join(self.tmpdir,fn),binary=binary)
  60. def write_to_tmpfile(self,fn,data,binary=False):
  61. return write_to_file(os.path.join(self.tmpdir,fn),data,binary=binary)
  62. def skip_for_win(self):
  63. if g.platform == 'win':
  64. msg("Skipping test '{}': not supported on MSys2 platform".format(self.test_name))
  65. return True
  66. else:
  67. return False