rune.py 4.1 KB

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