ts_main.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2022 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
  9. # https://gitlab.com/mmgen/mmgen
  10. """
  11. test_py_d.ts_main: Basic operations tests for the test.py test suite
  12. """
  13. import sys,time
  14. from ..include.common import cfg
  15. from .ts_base import TestSuiteBase
  16. class TestSuiteMain(TestSuiteBase):
  17. 'basic operations with fake RPC data'
  18. tmpdir_nums = [3]
  19. networks = ('btc',) # fake data, so test peerblocks for BTC mainnet only
  20. passthru_opts = ('daemon_data_dir','rpc_port','coin','testnet','rpc_backend')
  21. segwit_opts_ok = True
  22. color = True
  23. need_daemon = True
  24. cmd_group_in = (
  25. ('subgroup.peerblocks', []),
  26. )
  27. cmd_subgroups = {
  28. 'peerblocks': (
  29. "'mmnode-peerblocks' script",
  30. ('peerblocks1', '--help'),
  31. ('peerblocks2', 'interactive (popen spawn)'),
  32. ('peerblocks3', 'interactive, 80 columns (pexpect_spawn)'),
  33. ),
  34. }
  35. def peerblocks(self,args,expect_list=None,pexpect_spawn=False):
  36. t = self.spawn(
  37. f'mmnode-peerblocks',
  38. args,
  39. pexpect_spawn = pexpect_spawn )
  40. if cfg.exact_output: # disable echoing of input
  41. t.p.logfile = None
  42. t.p.logfile_read = sys.stdout
  43. if expect_list:
  44. t.match_expect_list(expect_list)
  45. return t
  46. def peerblocks1(self):
  47. t = self.peerblocks(['--help'])
  48. if t.pexpect_spawn:
  49. t.send('q')
  50. return t
  51. def peerblocks2(self,args=[],pexpect_spawn=False):
  52. t = self.peerblocks(args,pexpect_spawn=pexpect_spawn)
  53. for i in range(5):
  54. t.expect('PEERS')
  55. t.send('x')
  56. for i in range(3):
  57. t.expect('PEERS')
  58. sleep_secs = 0.2
  59. t.send('0')
  60. time.sleep(sleep_secs)
  61. t.send('\n' if pexpect_spawn else '0\n') # TODO: check for readline availability
  62. t.expect('Unable to disconnect peer 0')
  63. t.expect('PEERS')
  64. t.send('1')
  65. time.sleep(sleep_secs)
  66. t.send('1\n' if pexpect_spawn else '11\n')
  67. t.expect('11: invalid peer number')
  68. t.expect('PEERS')
  69. t.send('2')
  70. time.sleep(sleep_secs)
  71. t.send('\n' if pexpect_spawn else '2\n')
  72. t.expect('Disconnecting peer 2')
  73. t.expect('PEERS')
  74. t.send('q')
  75. return t
  76. def peerblocks3(self):
  77. return self.peerblocks2(['--columns=80'],pexpect_spawn=True)