ut_testdep.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. """
  3. test.modtest_d.ut_testdep: test dependency unit tests for the MMGen suite
  4. """
  5. import sys, os
  6. from subprocess import run, DEVNULL
  7. from mmgen.util import ymsg, bmsg
  8. from ..include.common import cfg
  9. sec = 'deadbeef' * 8
  10. class unit_tests:
  11. altcoin_deps = ('pycoin', 'monero_python', 'keyconv', 'zcash_mini', 'eth_keys', 'ssh_socks_proxy')
  12. win_skip = ('losetup', 'zcash_mini', 'sudo')
  13. mac_skip = ('losetup',)
  14. def sudo(self, name, ut):
  15. from mmgen.util import have_sudo
  16. if have_sudo():
  17. return True
  18. else:
  19. ymsg(f'To run the test suite, please enable sudo without password for user ‘{os.getenv("USER")}’')
  20. return False
  21. def losetup(self, name, ut):
  22. os.stat('/dev/loop0')
  23. for cmd in ('/sbin/losetup', '/usr/sbin/losetup', 'losetup'):
  24. try:
  25. run([cmd, '-f'], check=True, stdout=DEVNULL)
  26. break
  27. except:
  28. if cmd == 'losetup':
  29. raise
  30. return True
  31. def pylint(self, name, ut):
  32. try:
  33. return run(['pylint', '--version'], stdout=None if cfg.verbose else DEVNULL).returncode == 0
  34. except OSError as e:
  35. ymsg(' ' + str(e))
  36. bmsg(" Install pylint with 'python3 -m pip install pylint'")
  37. return False
  38. def pycoin(self, name, ut):
  39. from pycoin.networks.registry import network_for_netcode as nfnc
  40. network = nfnc('btc')
  41. key = network.keys.private(secret_exponent=int(sec, 16), is_compressed=True)
  42. hash160_c = key.hash160(is_compressed=True)
  43. network.address.for_p2pkh_wit(hash160_c)
  44. return True
  45. def monero_python(self, name, ut):
  46. from mmgen.util2 import load_cryptodome
  47. load_cryptodome()
  48. from monero.seed import Seed
  49. Seed('deadbeef' * 8).public_address()
  50. return True
  51. def keyconv(self, name, ut):
  52. run(['keyconv', '-G', 'ltc'], stdout=DEVNULL, stderr=DEVNULL, check=True)
  53. return True
  54. def zcash_mini(self, name, ut):
  55. run(['zcash-mini'], stdout=DEVNULL, check=True)
  56. return True
  57. def eth_keys(self, name, ut):
  58. from eth_keys import keys
  59. return True
  60. def ssh_socks_proxy(self, name, ut):
  61. from test.cmdtest_d.ct_xmrwallet import CmdTestXMRWallet
  62. return CmdTestXMRWallet.init_proxy(external_call=True)