ts_main.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 time
  14. from ..include.common import *
  15. from .common import *
  16. from .ts_base import *
  17. class TestSuiteMain(TestSuiteBase):
  18. 'basic operations with fake RPC data'
  19. tmpdir_nums = [3]
  20. networks = ('btc',) # fake data, so test peerblocks for BTC mainnet only
  21. passthru_opts = ('daemon_data_dir','rpc_port','coin','testnet','rpc_backend')
  22. segwit_opts_ok = True
  23. color = True
  24. need_daemon = True
  25. cmd_group_in = (
  26. ('subgroup.peerblocks', []),
  27. )
  28. cmd_subgroups = {
  29. 'peerblocks': (
  30. "'mmnode-peerblocks' script",
  31. ('peerblocks1', '--help'),
  32. ('peerblocks2', 'interactive'),
  33. ('peerblocks3', 'interactive, 80 columns'),
  34. ),
  35. }
  36. def peerblocks(self,args,expect_list=None):
  37. t = self.spawn(
  38. f'mmnode-peerblocks',
  39. args )
  40. if opt.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 opt.pexpect_spawn:
  49. t.send('q')
  50. return t
  51. def peerblocks2(self,args=[]):
  52. t = self.peerblocks(args)
  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. t.send('0')
  59. time.sleep(0.2)
  60. t.send('\n')
  61. t.expect('Unable to disconnect peer 0')
  62. t.expect('PEERS')
  63. t.send('1')
  64. time.sleep(0.2)
  65. t.send('1\n')
  66. t.expect('11: invalid peer number')
  67. t.expect('PEERS')
  68. t.send('2')
  69. time.sleep(0.2)
  70. t.send('\n')
  71. t.expect('Disconnecting peer 2')
  72. t.expect('PEERS')
  73. t.send('q')
  74. return t
  75. def peerblocks3(self):
  76. return self.peerblocks2(['--columns=80'])