scrambletest.py 5.1 KB

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