scrambletest.py 5.6 KB

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