ct_ref_altcoin.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2023 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.cmdtest_py_d.ct_ref_altcoin: Altcoin reference file tests for the cmdtest.py test suite
  20. """
  21. from mmgen.color import set_vt100
  22. from .common import pwfile,dfl_wpasswd,ref_dir,dfl_words_file,dfl_addr_idx_list
  23. from ..include.common import cfg,joinpath,start_test_daemons,stop_test_daemons,cmp_or_die
  24. from .ct_ref import CmdTestRef
  25. from .ct_base import CmdTestBase
  26. class CmdTestRefAltcoin(CmdTestRef,CmdTestBase):
  27. 'saved and generated altcoin reference files'
  28. tmpdir_nums = [8]
  29. networks = ('btc',)
  30. chk_data = {
  31. 'ref_addrfile_chksum_zec': '903E 7225 DD86 6E01',
  32. 'ref_addrfile_chksum_zec_z': '9C7A 72DC 3D4A B3AF',
  33. 'ref_addrfile_chksum_xmr': '4369 0253 AC2C 0E38',
  34. 'ref_addrfile_chksum_dash':'FBC1 6B6A 0988 4403',
  35. 'ref_addrfile_chksum_eth': 'E554 076E 7AF6 66A3',
  36. 'ref_addrfile_chksum_etc': 'E97A D796 B495 E8BC',
  37. 'ref_keyaddrfile_chksum_zec': 'F05A 5A5C 0C8E 2617',
  38. 'ref_keyaddrfile_chksum_zec_z': '6B87 9B2D 0D8D 8D1E',
  39. 'ref_keyaddrfile_chksum_xmr': 'E0D7 9612 3D67 404A',
  40. 'ref_viewkeyaddrfile_chksum_xmr': '40C9 0E61 B743 229C',
  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 unoptimized ed25519 mod in unit_tests.py, so skip this
  54. # ('ref_addrfile_gen_xmr_slow','generate address file (XMR - unoptimized ed25519 module)'),
  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_viewkeyaddrfile_gen_xmr','generate viewkey-address file (XMR)'),
  62. ('ref_addrfile_chk_eth', 'reference address file (ETH)'),
  63. ('ref_addrfile_chk_etc', 'reference address file (ETC)'),
  64. ('ref_addrfile_chk_dash','reference address file (DASH)'),
  65. ('ref_addrfile_chk_zec', 'reference address file (ZEC-T)'),
  66. ('ref_addrfile_chk_zec_z','reference address file (ZEC-Z)'),
  67. ('ref_addrfile_chk_xmr', 'reference address file (XMR)'),
  68. ('ref_keyaddrfile_chk_eth', 'reference key-address file (ETH)'),
  69. ('ref_keyaddrfile_chk_etc', 'reference key-address file (ETC)'),
  70. ('ref_keyaddrfile_chk_dash','reference key-address file (DASH)'),
  71. ('ref_keyaddrfile_chk_zec', 'reference key-address file (ZEC-T)'),
  72. ('ref_keyaddrfile_chk_zec_z','reference key-address file (ZEC-Z)'),
  73. ('ref_keyaddrfile_chk_xmr', 'reference key-address file (XMR)'),
  74. ('ref_viewkeyaddrfile_chk_xmr', 'reference viewkey-address file (XMR)'),
  75. )
  76. def ref_altcoin_tx_chk(self):
  77. """
  78. Check saved transaction files for *all* configured altcoins
  79. Though this basically duplicates the autosign test, here we do everything
  80. via the command line, so it's worth doing
  81. """
  82. self.write_to_tmpfile(pwfile,dfl_wpasswd)
  83. passfile = joinpath(self.tmpdir,pwfile)
  84. from mmgen.tx.file import MMGenTxFile
  85. src = CmdTestRef.sources['ref_tx_file']
  86. for coin,files in src.items():
  87. if coin == 'mm1':
  88. coin = 'eth'
  89. token_desc = ':MM1'
  90. else:
  91. token_desc = ''
  92. for fn in files:
  93. if not fn: # no etc testnet TX file
  94. continue
  95. txfile = joinpath(
  96. ref_dir,
  97. self._get_ref_subdir_by_coin(coin),
  98. fn )
  99. proto = MMGenTxFile.get_proto(cfg,txfile,quiet_open=True)
  100. if proto.sign_mode == 'daemon':
  101. start_test_daemons(proto.network_id)
  102. set_vt100()
  103. t = self.spawn(
  104. 'mmgen-txsign',
  105. ['--outdir=test/trash','--yes', f'--passwd-file={passfile}', dfl_words_file, txfile],
  106. extra_desc = f'{proto.coin}{token_desc} {proto.network}')
  107. t.read()
  108. t.ok()
  109. if proto.sign_mode == 'daemon' and not proto.network_id == 'btc':
  110. stop_test_daemons(proto.network_id)
  111. return 'ok'
  112. def ref_altcoin_addrgen(self,coin,mmtype,gen_what='addr',coin_suf='',add_args=[],addr_idx_list=None):
  113. wf = dfl_words_file
  114. t = self.spawn(
  115. 'mmgen-keygen' if 'key' in gen_what else 'mmgen-addrgen',
  116. ['-Sq','--coin='+coin] +
  117. (['--type='+mmtype] if mmtype else []) +
  118. add_args +
  119. [wf,addr_idx_list or dfl_addr_idx_list])
  120. if 'key' in gen_what:
  121. t.expect('Encrypt key list? (y/N): ','N')
  122. chk = t.expect_getend(r'.* data checksum for \S*: ',regex=True)
  123. chk_ref = self.chk_data[
  124. 'ref_{}addrfile_chksum_{}{}'.format(
  125. (gen_what if 'key' in gen_what else ''),
  126. coin.lower(),
  127. coin_suf )
  128. ]
  129. cmp_or_die(chk,chk_ref,desc=f'{gen_what}list data checksum')
  130. return t
  131. def ref_addrfile_gen_eth(self):
  132. return self.ref_altcoin_addrgen(coin='ETH',mmtype='ethereum')
  133. def ref_addrfile_gen_etc(self):
  134. return self.ref_altcoin_addrgen(coin='ETC',mmtype='ethereum')
  135. def ref_addrfile_gen_dash(self):
  136. return self.ref_altcoin_addrgen(coin='DASH',mmtype='compressed')
  137. def ref_addrfile_gen_zec(self):
  138. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='compressed')
  139. def ref_addrfile_gen_zec_z(self):
  140. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='zcash_z',coin_suf='_z')
  141. def ref_addrfile_gen_xmr(self):
  142. return self.ref_altcoin_addrgen(coin='XMR',mmtype='monero')
  143. def ref_addrfile_gen_xmr_slow(self):
  144. return self.ref_altcoin_addrgen(coin='XMR',mmtype='monero',add_args=['--keygen-backend=2'])
  145. def ref_keyaddrfile_gen_eth(self):
  146. return self.ref_altcoin_addrgen(coin='ETH',mmtype='ethereum',gen_what='key')
  147. def ref_keyaddrfile_gen_etc(self):
  148. return self.ref_altcoin_addrgen(coin='ETC',mmtype='ethereum',gen_what='key')
  149. def ref_keyaddrfile_gen_dash(self):
  150. return self.ref_altcoin_addrgen(coin='DASH',mmtype='compressed',gen_what='key')
  151. def ref_keyaddrfile_gen_zec(self):
  152. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='compressed',gen_what='key')
  153. def ref_keyaddrfile_gen_zec_z(self):
  154. return self.ref_altcoin_addrgen(coin='ZEC',mmtype='zcash_z',coin_suf='_z',gen_what='key')
  155. def ref_keyaddrfile_gen_xmr(self):
  156. return self.ref_altcoin_addrgen(coin='XMR',mmtype='monero',gen_what='key')
  157. def ref_viewkeyaddrfile_gen_xmr(self):
  158. return self.ref_altcoin_addrgen(
  159. coin = 'XMR',
  160. mmtype = 'monero',
  161. gen_what = 'viewkey',
  162. add_args = ['--viewkeys'],
  163. addr_idx_list = '1-3' )
  164. def ref_addrfile_chk_eth(self):
  165. return self.ref_addrfile_chk(ftype='addr',coin='ETH',subdir='ethereum',pfx='-ETH',
  166. pat='ETH Mainnet.*Ethereum')
  167. def ref_addrfile_chk_etc(self):
  168. return self.ref_addrfile_chk(ftype='addr',coin='ETC',subdir='ethereum_classic',pfx='-ETC',
  169. pat='ETH Mainnet.*Ethereum')
  170. def ref_addrfile_chk_dash(self):
  171. return self.ref_addrfile_chk(ftype='addr',coin='DASH',subdir='dash',pfx='-DASH-C',
  172. pat='DASH Mainnet.*Compressed')
  173. def ref_addrfile_chk_zec(self):
  174. return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-C',
  175. pat='ZEC Mainnet.*Compressed')
  176. def ref_addrfile_chk_zec_z(self):
  177. return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z',
  178. pat='ZEC Mainnet.*Zcash_z')
  179. def ref_addrfile_chk_xmr(self):
  180. return self.ref_addrfile_chk(ftype='addr',coin='XMR',subdir='monero',pfx='-XMR-M',
  181. pat='XMR Mainnet.*Monero')
  182. def ref_keyaddrfile_chk_eth(self):
  183. return self.ref_addrfile_chk(ftype='keyaddr',coin='ETH',subdir='ethereum',pfx='-ETH',
  184. pat='ETH Mainnet.*Ethereum')
  185. def ref_keyaddrfile_chk_etc(self):
  186. return self.ref_addrfile_chk(ftype='keyaddr',coin='ETC',subdir='ethereum_classic',pfx='-ETC',
  187. pat='ETH Mainnet.*Ethereum')
  188. def ref_keyaddrfile_chk_dash(self):
  189. return self.ref_addrfile_chk(ftype='keyaddr',coin='DASH',subdir='dash',pfx='-DASH-C',
  190. pat='DASH Mainnet.*Compressed')
  191. def ref_keyaddrfile_chk_zec(self):
  192. return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-C',
  193. pat='ZEC Mainnet.*Compressed')
  194. def ref_keyaddrfile_chk_zec_z(self):
  195. return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z',
  196. pat='ZEC Mainnet.*Zcash_z')
  197. def ref_keyaddrfile_chk_xmr(self):
  198. return self.ref_addrfile_chk(ftype='keyaddr',coin='XMR',subdir='monero',pfx='-XMR-M',
  199. pat='XMR Mainnet.*Monero')
  200. def ref_viewkeyaddrfile_chk_xmr(self):
  201. return self.ref_addrfile_chk(ftype='viewkeyaddr',coin='XMR',subdir='monero',pfx='-XMR-M',
  202. pat='XMR Mainnet.*Monero')