scrambletest.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2017 Philemon <mmgen-py@yandex.com>
  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. test/scrambletest.py: seed scrambling and addrlist data generation tests for all supported altcoins
  20. """
  21. import sys,os,subprocess
  22. repo_root = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),os.pardir)))
  23. os.chdir(repo_root)
  24. sys.path.__setitem__(0,repo_root)
  25. # Import this _after_ local path's been added to sys.path
  26. from mmgen.common import *
  27. opts_data = lambda: {
  28. 'desc': 'Test seed scrambling and addrlist data generation for all supported altcoins',
  29. 'usage':'[options] [command]',
  30. 'options': """
  31. -h, --help Print this help message
  32. --, --longhelp Print help message for long options (common options)
  33. -l, --list-cmds List and describe the tests and commands in this test suite
  34. -s, --system Test scripts and modules installed on system rather than
  35. those in the repo root
  36. -v, --verbose Produce more verbose output
  37. """,
  38. 'notes': """
  39. If no command is given, the whole suite of tests is run.
  40. """
  41. }
  42. cmd_args = opts.init(opts_data)
  43. os.environ['MMGEN_DEBUG_ADDRLIST'] = '1'
  44. if not opt.system:
  45. os.environ['PYTHONPATH'] = repo_root
  46. from collections import OrderedDict
  47. test_data = OrderedDict([
  48. # SCRAMBLED_SEED[:8] SCRAMBLE_KEY ID_STR LBL FIRST ADDR
  49. ('btc', ('456d7f5f1c4bfe3b','(none)', '', '', '1MU7EdgqYy9JX35L25hR6CmXXcSEBDAwyv')),
  50. ('btc_compressed',('bf98a4af5464a4ef','compressed', '-C', 'COMPRESSED','1F97Jd89wwmu4ELadesAdGDzg3d8Y6j5iP')),
  51. ('btc_segwit', ('b56962d829ffc678','segwit', '-S', 'SEGWIT', '36TvVzU5mxSjJ3D9qKAmYzCV7iUqtTDezF')),
  52. ('bch', ('456d7f5f1c4bfe3b','(none)', '', '', '1MU7EdgqYy9JX35L25hR6CmXXcSEBDAwyv')),
  53. ('bch_compressed',('bf98a4af5464a4ef','compressed', '-C', 'COMPRESSED','1F97Jd89wwmu4ELadesAdGDzg3d8Y6j5iP')),
  54. ('ltc', ('b11f16632e63ba92','ltc:legacy', '-LTC','LTC', 'LMxB474SVfxeYdqxNrM1WZDZMnifteSMv1')),
  55. ('ltc_compressed',('7ccf465d466ee7d3','ltc:compressed', '-LTC-C', 'LTC:COMPRESSED', 'LdkebBKVXSs6NNoPJWGM8KciDnL8LhXXjb')),
  56. ('ltc_segwit', ('9460f5ba15e82768','ltc:segwit', '-LTC-S', 'LTC:SEGWIT', 'MQrY3vEbqKMBgegXrSaR93R2HoTDE5bKrY')),
  57. ('eth', ('213ed116869b19f2','eth', '-ETH', 'ETH','e704b6cfd9f0edb2e6cfbd0c913438d37ede7b35')),
  58. ('etc', ('909def37096f5ab8','etc', '-ETC', 'ETC','1a6acbef8c38f52f20d04ecded2992b04d8608d7')),
  59. ('dash', ('bb21cf88c198ab8c','dash:compressed','-DASH-C','DASH:COMPRESSED','XsjAJvCxkxYh55ZvCZMFEv2eJUVo5xxbwi')),
  60. ('zec', ('637f7b8117b524ed','zec:compressed', '-ZEC-C', 'ZEC:COMPRESSED', 't1d47QeTehQye4Mms1Lmx7dPjKVoTtHXKmu')),
  61. ('zec_zcash_z', ('b15570d033df9b1a','zec:zcash_z', '-ZEC-Z', 'ZEC:ZCASH_Z', 'zcLMMsnzfFYZWU4avRBnuc83yh4jTtJXbtP32uWrs3ickzu1krMU4ppZCQPTwwfE9hLnRuFDSYF8VFW13aT9eeQK8aov3Ge')),
  62. ])
  63. def run_tests():
  64. for test in test_data:
  65. try: coin,mmtype = test.split('_',1)
  66. except: coin,mmtype = test,None
  67. cmd_name = 'cmds/mmgen-addrgen'
  68. wf = 'test/ref/98831F3A.mmwords'
  69. type_arg = ['--type='+mmtype] if mmtype else []
  70. cmd = [cmd_name,'-qS','--coin='+coin] + type_arg + [wf,'1']
  71. vmsg(green('Executing: {}'.format(' '.join(cmd))))
  72. msg_r('Testing: --coin {:4} {:22}'.format(coin.upper(),type_arg[0] if type_arg else ''))
  73. p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  74. o = p.stdout.read()
  75. vmsg(o)
  76. o = o.splitlines()
  77. d = [e for e in o if len(e) > 4 and e[:9] == 'sc_debug_']
  78. d.append('sc_debug_addr: ' + o[-2].split()[-1])
  79. for n,k in enumerate(['seed','str','id_str','lbl','addr']):
  80. kk = 'sc_debug_'+k
  81. a = test_data[test][n]
  82. b = [e for e in d if e[:len(kk)] == kk][0][len(kk)+2:]
  83. if b == a:
  84. vmsg('sc_{}: {}'.format(k,a))
  85. else:
  86. rdie(1,'\nError: sc_{} value {} does not match reference value {}'.format(k,b,a))
  87. msg('OK')
  88. start_time = int(time.time())
  89. run_tests()
  90. t = int(time.time()) - start_time
  91. m = '\nAll requested tests finished OK, elapsed time: {:02}:{:02}'
  92. msg(green(m.format(t/60,t%60)))