ct_automount_eth.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. test.cmdtest_d.ct_automount_eth: Ethereum automount autosigning tests for the cmdtest.py test suite
  12. """
  13. import os, re
  14. from .ct_autosign import CmdTestAutosignThreaded
  15. from .ct_ethdev import CmdTestEthdev, parity_devkey_fn
  16. from .common import dfl_words_file
  17. from ..include.common import cfg
  18. class CmdTestAutosignETH(CmdTestAutosignThreaded, CmdTestEthdev):
  19. 'automounted transacting operations for Ethereum via ethdev'
  20. networks = ('eth', 'etc')
  21. tmpdir_nums = [59]
  22. cmd_group = (
  23. ('setup', f'dev mode tests for coin {cfg.coin} (start daemon)'),
  24. ('addrgen', 'generating addresses'),
  25. ('addrimport', 'importing addresses'),
  26. ('addrimport_dev_addr', "importing dev faucet address 'Ox00a329c..'"),
  27. ('fund_dev_address', 'funding the default (Parity dev) address'),
  28. ('fund_mmgen_address', 'funding an MMGen address'),
  29. ('create_tx', 'creating a transaction'),
  30. ('run_autosign_setup', 'running ‘autosign setup’'),
  31. ('wait_loop_start', 'starting autosign wait loop'),
  32. ('send_tx', 'sending the transaction'),
  33. ('token_compile1', 'compiling ERC20 token #1'),
  34. ('token_deploy1a', 'deploying ERC20 token #1 (SafeMath)'),
  35. ('token_deploy1b', 'deploying ERC20 token #1 (Owned)'),
  36. ('token_deploy1c', 'deploying ERC20 token #1 (Token)'),
  37. ('tx_status2', 'getting the transaction status'),
  38. ('token_fund_user', 'transferring token funds from dev to user'),
  39. ('token_addrgen_addr1', 'generating token addresses'),
  40. ('token_addrimport_addr1', 'importing token addresses using token address (MM1)'),
  41. ('token_bal1', f'the {cfg.coin} balance and token balance'),
  42. ('create_token_tx', 'creating a token transaction'),
  43. ('send_token_tx', 'sending a token transaction'),
  44. ('token_bal2', f'the {cfg.coin} balance and token balance'),
  45. ('wait_loop_kill', 'stopping autosign wait loop'),
  46. ('stop', 'stopping daemon'),
  47. ('txview', 'viewing transactions'),
  48. )
  49. def __init__(self, trunner, cfgs, spawn):
  50. self.coins = [cfg.coin.lower()]
  51. CmdTestAutosignThreaded.__init__(self, trunner, cfgs, spawn)
  52. CmdTestEthdev.__init__(self, trunner, cfgs, spawn)
  53. self.txop_opts = ['--autosign', '--regtest=1', '--quiet']
  54. def fund_mmgen_address(self):
  55. keyfile = os.path.join(self.tmpdir, parity_devkey_fn)
  56. t = self.spawn(
  57. 'mmgen-txdo',
  58. self.eth_args
  59. + [f'--keys-from-file={keyfile}']
  60. + ['--fee=40G', '98831F3A:E:1,123.456', dfl_words_file],
  61. )
  62. t.expect('efresh balance:\b', 'q')
  63. t.expect('from: ', '10')
  64. t.expect('(Y/n): ', 'y')
  65. t.expect('(Y/n): ', 'y')
  66. t.expect('(y/N): ', 'n')
  67. t.expect('view: ', 'n')
  68. t.expect('confirm: ', 'YES')
  69. return t
  70. def create_tx(self):
  71. self.insert_device_online()
  72. t = self.spawn('mmgen-txcreate', self.txop_opts + ['-B', '98831F3A:E:11,54.321'])
  73. t = self.txcreate_ui_common(
  74. t,
  75. caller = 'txcreate',
  76. input_sels_prompt = 'to spend from',
  77. inputs = '1',
  78. file_desc = 'transaction',
  79. interactive_fee = '50G',
  80. fee_desc = 'transaction fee or gas price')
  81. t.read()
  82. self.remove_device_online()
  83. return t
  84. def run_autosign_setup(self):
  85. return self.run_setup(mn_type='bip39', mn_file='test/ref/98831F3A.bip39', use_dfl_wallet=None)
  86. def send_tx(self, add_args=[]):
  87. self._wait_signed('transaction')
  88. self.insert_device_online()
  89. t = self.spawn('mmgen-txsend', self.txop_opts + add_args)
  90. t.view_tx('t')
  91. t.expect('(y/N): ', 'n')
  92. self._do_confirm_send(t, quiet=True)
  93. t.written_to_file('Sent automount transaction')
  94. t.read()
  95. self.remove_device_online()
  96. return t
  97. def token_fund_user(self):
  98. return self.token_transfer_ops(op='do_transfer', num_tokens=1)
  99. def token_addrgen_addr1(self):
  100. return self.token_addrgen(num_tokens=1)
  101. def token_bal1(self):
  102. return self.token_bal(pat=r':E:11\s+1000\s+54\.321\s+')
  103. def token_bal2(self):
  104. return self.token_bal(pat=r':E:11\s+998.76544\s+54.318\d+\s+.*:E:12\s+1\.23456\s+')
  105. def token_bal(self, pat):
  106. t = self.spawn('mmgen-tool', ['--regtest=1', '--token=mm1', 'twview', 'wide=1'])
  107. text = t.read(strip_color=True)
  108. assert re.search(pat, text, re.DOTALL), f'output failed to match regex {pat}'
  109. return t
  110. def create_token_tx(self):
  111. self.insert_device_online()
  112. t = self.txcreate_ui_common(
  113. self.spawn(
  114. 'mmgen-txcreate',
  115. self.txop_opts + ['--token=MM1', '-B', '--fee=50G', '98831F3A:E:12,1.23456']),
  116. inputs = '1',
  117. input_sels_prompt = 'to spend from',
  118. file_desc = 'Unsigned automount transaction')
  119. t.read()
  120. self.remove_device_online()
  121. return t
  122. def send_token_tx(self):
  123. return self.send_tx(add_args=['--token=MM1'])