ct_ref_altcoin.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2024 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_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. ('ref_keyaddrfile_gen_eth', 'generate key-address file (ETH)'),
  54. ('ref_keyaddrfile_gen_etc', 'generate key-address file (ETC)'),
  55. ('ref_keyaddrfile_gen_dash', 'generate key-address file (DASH)'),
  56. ('ref_keyaddrfile_gen_zec', 'generate key-address file (ZEC-T)'),
  57. ('ref_keyaddrfile_gen_zec_z', 'generate key-address file (ZEC-Z)'),
  58. ('ref_keyaddrfile_gen_xmr', 'generate key-address file (XMR)'),
  59. ('ref_viewkeyaddrfile_gen_xmr', 'generate viewkey-address file (XMR)'),
  60. ('ref_addrfile_chk_eth', 'reference address file (ETH)'),
  61. ('ref_addrfile_chk_etc', 'reference address file (ETC)'),
  62. ('ref_addrfile_chk_dash', 'reference address file (DASH)'),
  63. ('ref_addrfile_chk_zec', 'reference address file (ZEC-T)'),
  64. ('ref_addrfile_chk_zec_z', 'reference address file (ZEC-Z)'),
  65. ('ref_addrfile_chk_xmr', 'reference address file (XMR)'),
  66. ('ref_keyaddrfile_chk_eth', 'reference key-address file (ETH)'),
  67. ('ref_keyaddrfile_chk_etc', 'reference key-address file (ETC)'),
  68. ('ref_keyaddrfile_chk_dash', 'reference key-address file (DASH)'),
  69. ('ref_keyaddrfile_chk_zec', 'reference key-address file (ZEC-T)'),
  70. ('ref_keyaddrfile_chk_zec_z', 'reference key-address file (ZEC-Z)'),
  71. ('ref_keyaddrfile_chk_xmr', 'reference key-address file (XMR)'),
  72. ('ref_viewkeyaddrfile_chk_xmr', 'reference viewkey-address file (XMR)'),
  73. )
  74. def ref_altcoin_tx_chk(self):
  75. """
  76. Check saved transaction files for *all* configured altcoins
  77. Though this basically duplicates the autosign test, here we do everything
  78. via the command line, so it's worth doing
  79. """
  80. self.write_to_tmpfile(pwfile, dfl_wpasswd)
  81. passfile = joinpath(self.tmpdir, pwfile)
  82. from mmgen.tx.file import MMGenTxFile
  83. src = CmdTestRef.sources['ref_tx_file']
  84. for coin, files in src.items():
  85. if coin == 'mm1':
  86. coin = 'eth'
  87. token_desc = ':MM1'
  88. else:
  89. token_desc = ''
  90. for fn in files:
  91. if not fn: # no etc testnet TX file
  92. continue
  93. txfile = joinpath(
  94. ref_dir,
  95. self._get_ref_subdir_by_coin(coin),
  96. fn)
  97. proto = MMGenTxFile.get_proto(cfg, txfile, quiet_open=True)
  98. if proto.sign_mode == 'daemon':
  99. start_test_daemons(proto.network_id)
  100. set_vt100()
  101. t = self.spawn(
  102. 'mmgen-txsign',
  103. ['--outdir=test/trash', '--yes', f'--passwd-file={passfile}', dfl_words_file, txfile],
  104. extra_desc = f'{proto.coin}{token_desc} {proto.network}')
  105. t.read()
  106. t.ok()
  107. if proto.sign_mode == 'daemon' and not proto.network_id == 'btc':
  108. stop_test_daemons(proto.network_id)
  109. return 'ok'
  110. def ref_altcoin_addrgen(
  111. self,
  112. coin,
  113. mmtype,
  114. gen_what = 'addr',
  115. coin_suf = '',
  116. add_args = [],
  117. addr_idx_list = None):
  118. wf = dfl_words_file
  119. t = self.spawn(
  120. 'mmgen-keygen' if 'key' in gen_what else 'mmgen-addrgen',
  121. ['-Sq', '--coin='+coin] +
  122. (['--type='+mmtype] if mmtype else []) +
  123. add_args +
  124. [wf, addr_idx_list or dfl_addr_idx_list])
  125. if 'key' in gen_what:
  126. t.expect('Encrypt key list? (y/N): ', 'N')
  127. chk = t.expect_getend(r'.* data checksum for \S*: ', regex=True)
  128. chk_ref = self.chk_data[
  129. 'ref_{}addrfile_chksum_{}{}'.format(
  130. (gen_what if 'key' in gen_what else ''),
  131. coin.lower(),
  132. coin_suf)
  133. ]
  134. cmp_or_die(chk, chk_ref, desc=f'{gen_what}list data checksum')
  135. return t
  136. def ref_addrfile_gen_eth(self):
  137. return self.ref_altcoin_addrgen(coin='ETH', mmtype='ethereum')
  138. def ref_addrfile_gen_etc(self):
  139. return self.ref_altcoin_addrgen(coin='ETC', mmtype='ethereum')
  140. def ref_addrfile_gen_dash(self):
  141. return self.ref_altcoin_addrgen(coin='DASH', mmtype='compressed')
  142. def ref_addrfile_gen_zec(self):
  143. return self.ref_altcoin_addrgen(coin='ZEC', mmtype='compressed')
  144. def ref_addrfile_gen_zec_z(self):
  145. return self.ref_altcoin_addrgen(coin='ZEC', mmtype='zcash_z', coin_suf='_z')
  146. def ref_addrfile_gen_xmr(self):
  147. return self.ref_altcoin_addrgen(coin='XMR', mmtype='monero')
  148. def ref_addrfile_gen_xmr_slow(self):
  149. return self.ref_altcoin_addrgen(coin='XMR', mmtype='monero', add_args=['--keygen-backend=2'])
  150. def ref_keyaddrfile_gen_eth(self):
  151. return self.ref_altcoin_addrgen(coin='ETH', mmtype='ethereum', gen_what='key')
  152. def ref_keyaddrfile_gen_etc(self):
  153. return self.ref_altcoin_addrgen(coin='ETC', mmtype='ethereum', gen_what='key')
  154. def ref_keyaddrfile_gen_dash(self):
  155. return self.ref_altcoin_addrgen(coin='DASH', mmtype='compressed', gen_what='key')
  156. def ref_keyaddrfile_gen_zec(self):
  157. return self.ref_altcoin_addrgen(coin='ZEC', mmtype='compressed', gen_what='key')
  158. def ref_keyaddrfile_gen_zec_z(self):
  159. return self.ref_altcoin_addrgen(coin='ZEC', mmtype='zcash_z', coin_suf='_z', gen_what='key')
  160. def ref_keyaddrfile_gen_xmr(self):
  161. return self.ref_altcoin_addrgen(coin='XMR', mmtype='monero', gen_what='key')
  162. def ref_viewkeyaddrfile_gen_xmr(self):
  163. return self.ref_altcoin_addrgen(
  164. coin = 'XMR',
  165. mmtype = 'monero',
  166. gen_what = 'viewkey',
  167. add_args = ['--viewkeys'],
  168. addr_idx_list = '1-3')
  169. def ref_addrfile_chk_eth(self):
  170. return self.ref_addrfile_chk(ftype='addr', coin='ETH', subdir='ethereum', pfx='-ETH',
  171. pat='ETH Mainnet.*Ethereum')
  172. def ref_addrfile_chk_etc(self):
  173. return self.ref_addrfile_chk(ftype='addr', coin='ETC', subdir='ethereum_classic', pfx='-ETC',
  174. pat='ETH Mainnet.*Ethereum')
  175. def ref_addrfile_chk_dash(self):
  176. return self.ref_addrfile_chk(ftype='addr', coin='DASH', subdir='dash', pfx='-DASH-C',
  177. pat='DASH Mainnet.*Compressed')
  178. def ref_addrfile_chk_zec(self):
  179. return self.ref_addrfile_chk(ftype='addr', coin='ZEC', subdir='zcash', pfx='-ZEC-C',
  180. pat='ZEC Mainnet.*Compressed')
  181. def ref_addrfile_chk_zec_z(self):
  182. return self.ref_addrfile_chk(ftype='addr', coin='ZEC', subdir='zcash', pfx='-ZEC-Z', mmtype='z',
  183. pat='ZEC Mainnet.*Zcash_z')
  184. def ref_addrfile_chk_xmr(self):
  185. return self.ref_addrfile_chk(ftype='addr', coin='XMR', subdir='monero', pfx='-XMR-M',
  186. pat='XMR Mainnet.*Monero')
  187. def ref_keyaddrfile_chk_eth(self):
  188. return self.ref_addrfile_chk(ftype='keyaddr', coin='ETH', subdir='ethereum', pfx='-ETH',
  189. pat='ETH Mainnet.*Ethereum')
  190. def ref_keyaddrfile_chk_etc(self):
  191. return self.ref_addrfile_chk(ftype='keyaddr', coin='ETC', subdir='ethereum_classic', pfx='-ETC',
  192. pat='ETH Mainnet.*Ethereum')
  193. def ref_keyaddrfile_chk_dash(self):
  194. return self.ref_addrfile_chk(ftype='keyaddr', coin='DASH', subdir='dash', pfx='-DASH-C',
  195. pat='DASH Mainnet.*Compressed')
  196. def ref_keyaddrfile_chk_zec(self):
  197. return self.ref_addrfile_chk(ftype='keyaddr', coin='ZEC', subdir='zcash', pfx='-ZEC-C',
  198. pat='ZEC Mainnet.*Compressed')
  199. def ref_keyaddrfile_chk_zec_z(self):
  200. return self.ref_addrfile_chk(ftype='keyaddr', coin='ZEC', subdir='zcash', pfx='-ZEC-Z', mmtype='z',
  201. pat='ZEC Mainnet.*Zcash_z')
  202. def ref_keyaddrfile_chk_xmr(self):
  203. return self.ref_addrfile_chk(ftype='keyaddr', coin='XMR', subdir='monero', pfx='-XMR-M',
  204. pat='XMR Mainnet.*Monero')
  205. def ref_viewkeyaddrfile_chk_xmr(self):
  206. return self.ref_addrfile_chk(ftype='viewkeyaddr', coin='XMR', subdir='monero', pfx='-XMR-M',
  207. pat='XMR Mainnet.*Monero')