rune.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2025 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.rune: THORChain RUNE tests for the cmdtest.py test suite
  12. """
  13. from .include.common import dfl_sid, dfl_words_file
  14. from .httpd.thornode.rpc import ThornodeRPCServer
  15. from .ethdev import CmdTestEthdevMethods
  16. from .base import CmdTestBase
  17. from .shared import CmdTestShared
  18. from .swap import CmdTestSwapMethods
  19. class CmdTestRune(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
  20. 'THORChain RUNE tracking wallet and transacting operations'
  21. networks = ('rune',)
  22. passthru_opts = ('coin', 'http_timeout')
  23. tmpdir_nums = [50]
  24. color = True
  25. menu_prompt = 'efresh balance:\b'
  26. cmd_group_in = (
  27. ('subgroup.init', []),
  28. ('subgroup.main', ['init']),
  29. ('thornode_server_stop', 'stopping Thornode server'),
  30. )
  31. cmd_subgroups = {
  32. 'init': (
  33. 'initializing wallets',
  34. ('addrgen', 'generating addresses'),
  35. ('addrimport', 'importing addresses'),
  36. ),
  37. 'main': (
  38. 'tracking wallet and transaction operations',
  39. ('twview', 'viewing unspent outputs in tracking wallet'),
  40. ('bal_refresh', 'refreshing address balance in tracking wallet'),
  41. ('txcreate1', 'creating a transaction'),
  42. ('txsign1', 'signing the transaction'),
  43. ('txsend1_test', 'testing whether the transaction can be sent'),
  44. ('txsend1', 'sending the transaction'),
  45. ),
  46. }
  47. def __init__(self, cfg, trunner, cfgs, spawn):
  48. CmdTestBase.__init__(self, cfg, trunner, cfgs, spawn)
  49. if trunner is None:
  50. return
  51. self.eth_opts = [f'--outdir={self.tmpdir}', '--regtest=1', '--quiet']
  52. self.eth_opts_noquiet = [f'--outdir={self.tmpdir}', '--regtest=1']
  53. self.rune_opts = self.eth_opts
  54. from mmgen.protocol import init_proto
  55. self.proto = init_proto(cfg, network_id=self.proto.coin + '_rt', need_amt=True)
  56. self.spawn_env['MMGEN_BOGUS_SEND'] = ''
  57. self.thornode_server = ThornodeRPCServer()
  58. self.thornode_server.start()
  59. def addrgen(self):
  60. return self._addrgen()
  61. def addrimport(self):
  62. return self._addrimport()
  63. def twview(self):
  64. return self.spawn('mmgen-tool', self.rune_opts + ['twview'])
  65. def bal_refresh(self):
  66. t = self.spawn('mmgen-tool', self.rune_opts + ['listaddresses', 'interactive=1'])
  67. t.expect(self.menu_prompt, 'R')
  68. t.expect('menu): ', '3\n')
  69. t.expect('(y/N): ', 'y')
  70. t.expect(r'Total RUNE: \S*\D9876.54321321\D', regex=True)
  71. t.expect('address #3 refreshed')
  72. t.expect(self.menu_prompt, 'q')
  73. return t
  74. def txcreate1(self):
  75. t = self.spawn('mmgen-txcreate', self.rune_opts + ['98831F3A:X:2,54.321'])
  76. t.expect(self.menu_prompt, 'q')
  77. t.expect('spend from: ', '3\n')
  78. t.expect('(y/N): ', 'y') # add comment?
  79. t.expect('Comment: ', 'RUNE Boy\n')
  80. t.expect('view: ', 'y')
  81. t.expect('to continue: ', 'z')
  82. t.expect('(y/N): ', 'y') # save?
  83. t.written_to_file('Unsigned transaction')
  84. return t
  85. def txsign1(self):
  86. return self.txsign_ui_common(
  87. self.spawn(
  88. 'mmgen-txsign',
  89. self.rune_opts + [self.get_file_with_ext('rawtx'), dfl_words_file],
  90. no_passthru_opts = ['coin']),
  91. has_label = True)
  92. def txsend1_test(self):
  93. return self._txsend(add_args=['--test'])
  94. def txsend1(self):
  95. return self._txsend()
  96. def _txsend(self, add_args=[]):
  97. t = self.spawn(
  98. 'mmgen-txsend',
  99. self.rune_opts + add_args + [self.get_file_with_ext('sigtx')],
  100. no_passthru_opts = ['coin'])
  101. t.expect('view: ', 'y')
  102. t.expect('to continue: ', 'z')
  103. t.expect('(y/N): ', 'n') # edit comment?
  104. if add_args == ['--test']:
  105. t.expect('can be sent')
  106. else:
  107. t.expect('to confirm: ', 'YES\n')
  108. t.written_to_file('Sent transaction')
  109. return t
  110. def thornode_server_stop(self):
  111. return CmdTestSwapMethods._thornode_server_stop(
  112. self, attrname='thornode_server', name='thornode server')