runeswap.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.runeswap: THORChain swap tests for the cmdtest.py test suite
  12. """
  13. from .httpd.thornode.swap import ThornodeSwapServer
  14. from .regtest import CmdTestRegtest
  15. from .swap import CmdTestSwapMethods, create_cross_methods
  16. from .rune import CmdTestRune
  17. class CmdTestRuneSwap(CmdTestSwapMethods, CmdTestRegtest):
  18. 'RUNE swap operations'
  19. bdb_wallet = True
  20. tmpdir_nums = [57]
  21. networks = ('btc',)
  22. passthru_opts = ('coin', 'rpc_backend')
  23. cross_group = 'runeswap_rune'
  24. cross_coin = 'rune'
  25. cmd_group_in = (
  26. ('setup', 'regtest (Bob and Alice) mode setup'),
  27. ('subgroup.init', []),
  28. ('subgroup.rune_init', ['init']),
  29. ('subgroup.rune_swap', ['rune_init']),
  30. ('stop', 'stopping the regtest daemon'),
  31. ('swap_server_stop', 'stopping the Thornode swap server'),
  32. ('rune_rpc_server_stop', 'stopping the Thornode RPC server'),
  33. )
  34. cmd_subgroups = {
  35. 'init': (
  36. 'creating Bob’s MMGen wallet and tracking wallet',
  37. ('walletconv_bob', 'wallet creation (Bob)'),
  38. ('addrgen_bob', 'address generation (Bob)'),
  39. ('addrimport_bob', 'importing Bob’s addresses'),
  40. ),
  41. 'rune_init': (
  42. 'initializing the RUNE tracking wallet',
  43. ('rune_addrgen', ''),
  44. ('rune_addrimport', ''),
  45. ('rune_bal_refresh', ''),
  46. ('rune_twview', ''),
  47. ),
  48. 'rune_swap': (
  49. 'swap operations (RUNE -> BTC)',
  50. ('rune_swaptxcreate1', ''),
  51. ('rune_swaptxsign1', ''),
  52. ('rune_swaptxsend1', ''),
  53. ('rune_swaptxstatus1', ''),
  54. ('rune_swaptxreceipt1', ''),
  55. ),
  56. }
  57. exec(create_cross_methods(cross_coin, cross_group, cmd_group_in, cmd_subgroups))
  58. def __init__(self, cfg, trunner, cfgs, spawn):
  59. super().__init__(cfg, trunner, cfgs, spawn)
  60. if not trunner:
  61. return
  62. globals()[self.cross_group] = self.create_cross_runner(trunner)
  63. self.swap_server = ThornodeSwapServer()
  64. self.swap_server.start()
  65. def swap_server_stop(self):
  66. return self._thornode_server_stop()
  67. class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune):
  68. 'RUNE swap operations - RUNE wallet'
  69. networks = ('rune',)
  70. tmpdir_nums = [58]
  71. input_sels_prompt = 'to spend from: '
  72. cmd_group_in = CmdTestRune.cmd_group_in + (
  73. # rune_swap:
  74. ('swaptxcreate1', 'creating a RUNE->BTC swap transaction'),
  75. ('swaptxsign1', 'signing the transaction'),
  76. ('swaptxsend1', 'sending the transaction'),
  77. ('swaptxstatus1', 'getting the transaction status'),
  78. ('swaptxreceipt1', 'getting the transaction receipt'),
  79. ('thornode_server_stop', 'stopping Thornode server'),
  80. )
  81. def swaptxcreate1(self):
  82. t = self._swaptxcreate(['RUNE', '8.765', 'BTC'])
  83. t.expect('OK? (Y/n): ', 'y')
  84. return self._swaptxcreate_ui_common(t, inputs='3')
  85. def swaptxsign1(self):
  86. return self._swaptxsign()
  87. def swaptxsend1(self):
  88. return self._swaptxsend()
  89. def swaptxstatus1(self):
  90. return self._swaptxsend(add_opts=['--verbose', '--status'], status=True)
  91. def swaptxreceipt1(self):
  92. return self._swaptxsend(add_opts=['--receipt'], spawn_only=True)