ut_testdep.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 pylint(self, name, ut):
  15. try:
  16. return run(['pylint', '--version'], stdout=None if cfg.verbose else DEVNULL).returncode == 0
  17. except OSError as e:
  18. ymsg(' ' + str(e))
  19. bmsg(" Install pylint with 'python3 -m pip install pylint'")
  20. return False
  21. def losetup(self, name, ut):
  22. os.stat('/dev/loop0')
  23. run(['/sbin/losetup', '-f'], check=True, stdout=DEVNULL)
  24. return True
  25. def pycoin(self, name, ut):
  26. from pycoin.networks.registry import network_for_netcode as nfnc
  27. network = nfnc('btc')
  28. key = network.keys.private(secret_exponent=int(sec, 16), is_compressed=True)
  29. hash160_c = key.hash160(is_compressed=True)
  30. network.address.for_p2pkh_wit(hash160_c)
  31. return True
  32. def monero_python(self, name, ut):
  33. from mmgen.util2 import load_cryptodome
  34. load_cryptodome()
  35. from monero.seed import Seed
  36. Seed('deadbeef' * 8).public_address()
  37. return True
  38. def keyconv(self, name, ut):
  39. run(['keyconv', '-G', 'ltc'], stdout=DEVNULL, stderr=DEVNULL, check=True)
  40. return True
  41. def zcash_mini(self, name, ut):
  42. run(['zcash-mini'], stdout=DEVNULL, check=True)
  43. return True
  44. def eth_keys(self, name, ut):
  45. from eth_keys import keys
  46. return True
  47. def ssh_socks_proxy(self, name, ut):
  48. from test.cmdtest_d.ct_xmrwallet import CmdTestXMRWallet
  49. return CmdTestXMRWallet.init_proxy(external_call=True)
  50. def sudo(self, name, ut):
  51. from mmgen.util import have_sudo
  52. if have_sudo():
  53. return True
  54. else:
  55. ymsg(f'To run the test suite, please enable sudo without password for user ‘{os.getenv("USER")}’')
  56. return False