ct_automount_eth.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line 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_py_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. ('autosign_start_thread', '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. ('autosign_kill_thread', '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.txcreate_args = ['--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.txcreate(
  73. args = ['--autosign', '98831F3A:E:11,54.321'],
  74. menu = [],
  75. print_listing = False,
  76. acct = '1')
  77. t.read()
  78. self.remove_device_online()
  79. return t
  80. def run_autosign_setup(self):
  81. self.insert_device()
  82. t = self.run_setup(mn_type='bip39', mn_file='test/ref/98831F3A.bip39', use_dfl_wallet=None)
  83. t.read()
  84. self.remove_device()
  85. return t
  86. def send_tx(self, add_args=[]):
  87. self._wait_signed('transaction')
  88. self.insert_device_online()
  89. t = self.spawn('mmgen-txsend', ['--quiet', '--autosign'] + 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. self.remove_device_online()
  95. return t
  96. def token_fund_user(self):
  97. return self.token_transfer_ops(op='do_transfer', num_tokens=1)
  98. def token_addrgen_addr1(self):
  99. return self.token_addrgen(num_tokens=1)
  100. def token_bal1(self):
  101. return self.token_bal(pat=r':E:11\s+1000\s+54\.321\s+')
  102. def token_bal2(self):
  103. return self.token_bal(pat=r':E:11\s+998.76544\s+54.318\d+\s+.*:E:12\s+1\.23456\s+')
  104. def token_bal(self, pat):
  105. t = self.spawn('mmgen-tool', ['--quiet', '--token=mm1', 'twview', 'wide=1'])
  106. text = t.read(strip_color=True)
  107. assert re.search(pat, text, re.DOTALL), f'output failed to match regex {pat}'
  108. return t
  109. def create_token_tx(self):
  110. self.insert_device_online()
  111. t = self.token_txcreate(
  112. args = ['--autosign', '98831F3A:E:12,1.23456'],
  113. token = 'MM1',
  114. file_desc = 'Unsigned automount transaction')
  115. t.read()
  116. self.remove_device_online()
  117. return t
  118. def send_token_tx(self):
  119. return self.send_tx(add_args=['--token=MM1'])