ts_ref_altcoin.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. ts_ref_altcoin.py: Altcoin reference file tests for the test.py test suite
  20. """
  21. import os
  22. from mmgen.globalvars import g
  23. from mmgen.opts import opt
  24. from test.test_py_d.common import *
  25. from test.test_py_d.ts_ref import *
  26. from test.test_py_d.ts_base import *
  27. class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
  28. 'saved and generated altcoin reference files'
  29. tmpdir_nums = [8]
  30. networks = ('btc',)
  31. chk_data = {
  32. 'ref_addrfile_chksum_zec': '903E 7225 DD86 6E01',
  33. 'ref_addrfile_chksum_zec_z': '9C7A 72DC 3D4A B3AF',
  34. 'ref_addrfile_chksum_xmr': '4369 0253 AC2C 0E38',
  35. 'ref_addrfile_chksum_dash':'FBC1 6B6A 0988 4403',
  36. 'ref_addrfile_chksum_eth': 'E554 076E 7AF6 66A3',
  37. 'ref_addrfile_chksum_etc': 'E97A D796 B495 E8BC',
  38. 'ref_keyaddrfile_chksum_zec': 'F05A 5A5C 0C8E 2617',
  39. 'ref_keyaddrfile_chksum_zec_z': '6B87 9B2D 0D8D 8D1E',
  40. 'ref_keyaddrfile_chksum_xmr': 'E0D7 9612 3D67 404A',
  41. 'ref_keyaddrfile_chksum_dash': 'E83D 2C63 FEA2 4142',
  42. 'ref_keyaddrfile_chksum_eth': 'E400 70D9 0AE3 C7C2',
  43. 'ref_keyaddrfile_chksum_etc': 'EF49 967D BD6C FE45',
  44. }
  45. cmd_group = (
  46. ('ref_altcoin_tx_chk', 'signing saved reference tx files'),
  47. ('ref_addrfile_gen_eth', 'generate address file (ETH)'),
  48. ('ref_addrfile_gen_etc', 'generate address file (ETC)'),
  49. ('ref_addrfile_gen_dash', 'generate address file (DASH)'),
  50. ('ref_addrfile_gen_zec', 'generate address file (ZEC-T)'),
  51. ('ref_addrfile_gen_zec_z','generate address file (ZEC-Z)'),
  52. ('ref_addrfile_gen_xmr', 'generate address file (XMR)'),
  53. # we test the old ed25519 library in test-release.sh, so skip this
  54. # ('ref_addrfile_gen_xmr_old','generate address file (XMR - old (slow) ed25519 library)'),
  55. ('ref_keyaddrfile_gen_eth', 'generate key-address file (ETH)'),
  56. ('ref_keyaddrfile_gen_etc', 'generate key-address file (ETC)'),
  57. ('ref_keyaddrfile_gen_dash', 'generate key-address file (DASH)'),
  58. ('ref_keyaddrfile_gen_zec', 'generate key-address file (ZEC-T)'),
  59. ('ref_keyaddrfile_gen_zec_z','generate key-address file (ZEC-Z)'),
  60. ('ref_keyaddrfile_gen_xmr', 'generate key-address file (XMR)'),
  61. ('ref_addrfile_chk_eth', 'reference address file (ETH)'),
  62. ('ref_addrfile_chk_etc', 'reference address file (ETC)'),
  63. ('ref_addrfile_chk_dash','reference address file (DASH)'),
  64. ('ref_addrfile_chk_zec', 'reference address file (ZEC-T)'),
  65. ('ref_addrfile_chk_zec_z','reference address file (ZEC-Z)'),
  66. ('ref_addrfile_chk_xmr', 'reference address file (XMR)'),
  67. ('ref_keyaddrfile_chk_eth', 'reference key-address file (ETH)'),
  68. ('ref_keyaddrfile_chk_etc', 'reference key-address file (ETC)'),
  69. ('ref_keyaddrfile_chk_dash','reference key-address file (DASH)'),
  70. ('ref_keyaddrfile_chk_zec', 'reference key-address file (ZEC-T)'),
  71. ('ref_keyaddrfile_chk_zec_z','reference key-address file (ZEC-Z)'),
  72. ('ref_keyaddrfile_chk_xmr', 'reference key-address file (XMR)'),
  73. )
  74. # Check saved transaction files for *all* configured altcoins
  75. # Though this basically duplicates the autosign test, here we do everything
  76. # via the command line, so it's worth doing
  77. def ref_altcoin_tx_chk(self):
  78. self.write_to_tmpfile(pwfile,dfl_wpasswd)
  79. pf = joinpath(self.tmpdir,pwfile)
  80. from mmgen.protocol import init_coin
  81. for k in ('bch','eth','mm1','etc'):
  82. coin,token = ('eth','mm1') if k == 'mm1' else (k,None)
  83. ref_subdir = self._get_ref_subdir_by_coin(coin)
  84. for tn in (False,True):
  85. if tn and coin == 'etc': continue
  86. g.testnet = tn
  87. init_coin(coin)
  88. fn = TestSuiteRef.sources['ref_tx_file'][token or coin][bool(tn)]
  89. tf = joinpath(ref_dir,ref_subdir,fn)
  90. wf = dfl_words_file
  91. e = ['--coin='+coin,'--testnet='+('0','1')[tn]]
  92. if token: e += ['--token='+token]
  93. t = self.txsign(tf, wf, pf,
  94. save = False,
  95. has_label = True,
  96. do_passwd = False,
  97. extra_desc = '({}{})'.format(token or coin,' testnet' if tn else ''),
  98. extra_opts = e )
  99. ok_msg()
  100. g.testnet = False
  101. init_coin('btc')
  102. t.skip_ok = True
  103. return t
  104. def ref_altcoin_addrgen(self,coin,mmtype,gen_what='addr',coin_suf='',add_args=[]):
  105. wf = dfl_words_file
  106. t = self.spawn('mmgen-{}gen'.format(gen_what),
  107. ['-Sq','--coin='+coin] +
  108. (['--type='+mmtype] if mmtype else []) +
  109. add_args +
  110. [wf,dfl_addr_idx_list])
  111. if gen_what == 'key':
  112. t.expect('Encrypt key list? (y/N): ','N')
  113. chk = t.expect_getend(r'.* data checksum for \S*: ',regex=True)
  114. chk_ref = self.chk_data['ref_{}addrfile_chksum_{}{}'.format(('','key')[gen_what=='key'],coin.lower(),coin_suf)]
  115. t.read()
  116. cmp_or_die(chk,chk_ref,desc='{}list data checksum'.format(gen_what))
  117. return t
  118. def ref_addrfile_gen_eth(self):
  119. return self.ref_altcoin_addrgen(coin='ETH',mmtype='ethereum')
  120. def ref_addrfile_gen_etc(self):
  121. return self.ref_altcoin_addrgen(coin='ETC',mmtype='ethereum')
  122. def ref_addrfile_gen_dash(self):
  123. return self.ref_altcoin_addrgen(coin='DASH',mmtype='compressed')
  124. def ref_addrfile_gen_zec(self):
  125. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='compressed')
  126. def ref_addrfile_gen_zec_z(self):
  127. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='zcash_z',coin_suf='_z')
  128. def ref_addrfile_gen_xmr(self):
  129. return self.ref_altcoin_addrgen(coin='XMR',mmtype='monero')
  130. def ref_addrfile_gen_xmr_old(self):
  131. return self.ref_altcoin_addrgen(coin='XMR',mmtype='monero',add_args=['--use-old-ed25519'])
  132. def ref_keyaddrfile_gen_eth(self):
  133. return self.ref_altcoin_addrgen(coin='ETH',mmtype='ethereum',gen_what='key')
  134. def ref_keyaddrfile_gen_etc(self):
  135. return self.ref_altcoin_addrgen(coin='ETC',mmtype='ethereum',gen_what='key')
  136. def ref_keyaddrfile_gen_dash(self):
  137. return self.ref_altcoin_addrgen(coin='DASH',mmtype='compressed',gen_what='key')
  138. def ref_keyaddrfile_gen_zec(self):
  139. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='compressed',gen_what='key')
  140. def ref_keyaddrfile_gen_zec_z(self):
  141. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='zcash_z',coin_suf='_z',gen_what='key')
  142. def ref_keyaddrfile_gen_xmr(self):
  143. return self.ref_altcoin_addrgen(coin='XMR',mmtype='monero',gen_what='key')
  144. def ref_addrfile_chk_eth(self):
  145. return self.ref_addrfile_chk(ftype='addr',coin='ETH',subdir='ethereum',pfx='-ETH')
  146. def ref_addrfile_chk_etc(self):
  147. return self.ref_addrfile_chk(ftype='addr',coin='ETC',subdir='ethereum_classic',pfx='-ETC')
  148. def ref_addrfile_chk_dash(self):
  149. return self.ref_addrfile_chk(ftype='addr',coin='DASH',subdir='dash',pfx='-DASH-C')
  150. def ref_addrfile_chk_zec(self):
  151. return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-C')
  152. def ref_addrfile_chk_zec_z(self):
  153. if self.skip_for_win(): return 'skip'
  154. return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z')
  155. def ref_addrfile_chk_xmr(self):
  156. return self.ref_addrfile_chk(ftype='addr',coin='XMR',subdir='monero',pfx='-XMR-M')
  157. def ref_keyaddrfile_chk_eth(self):
  158. return self.ref_addrfile_chk(ftype='keyaddr',coin='ETH',subdir='ethereum',pfx='-ETH')
  159. def ref_keyaddrfile_chk_etc(self):
  160. return self.ref_addrfile_chk(ftype='keyaddr',coin='ETC',subdir='ethereum_classic',pfx='-ETC')
  161. def ref_keyaddrfile_chk_dash(self):
  162. return self.ref_addrfile_chk(ftype='keyaddr',coin='DASH',subdir='dash',pfx='-DASH-C')
  163. def ref_keyaddrfile_chk_zec(self):
  164. return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-C')
  165. def ref_keyaddrfile_chk_zec_z(self):
  166. if self.skip_for_win(): return 'skip'
  167. return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z')
  168. def ref_keyaddrfile_chk_xmr(self):
  169. return self.ref_addrfile_chk(ftype='keyaddr',coin='XMR',subdir='monero',pfx='-XMR-M')