ut_testdep.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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', 'ethkey', '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 core_repo(self, name, ut):
  22. crr = os.getenv('CORE_REPO_ROOT')
  23. if not crr or not os.path.exists(os.path.join(crr, 'src/test/data/tx_valid.json')):
  24. ymsg('CORE_REPO_ROOT not set, or does not point to Bitcoin Core repository')
  25. return False
  26. return True
  27. def losetup(self, name, ut):
  28. os.stat('/dev/loop0')
  29. run(['/sbin/losetup', '-f'], check=True, stdout=DEVNULL)
  30. return True
  31. def pycoin(self, name, ut):
  32. from pycoin.networks.registry import network_for_netcode as nfnc
  33. network = nfnc('btc')
  34. key = network.keys.private(secret_exponent=int(sec, 16), is_compressed=True)
  35. hash160_c = key.hash160(is_compressed=True)
  36. network.address.for_p2pkh_wit(hash160_c)
  37. return True
  38. def monero_python(self, name, ut):
  39. from mmgen.util2 import load_cryptodomex
  40. load_cryptodomex()
  41. from monero.seed import Seed
  42. Seed('deadbeef' * 8).public_address()
  43. return True
  44. def keyconv(self, name, ut):
  45. run(['keyconv', '-G', 'ltc'], stdout=DEVNULL, stderr=DEVNULL, check=True)
  46. return True
  47. def zcash_mini(self, name, ut):
  48. run(['zcash-mini'], stdout=DEVNULL, check=True)
  49. return True
  50. def ethkey(self, name, ut):
  51. if sys.platform == 'linux' and os.uname().machine != 'x86_64':
  52. distro = [l for l in open('/etc/os-release').read().split('\n') if l.startswith('ID=')][0][3:]
  53. if distro != 'archarm':
  54. ut.skip_msg(f'distro {distro!r} on architecture {os.uname().machine!r}')
  55. return True
  56. from test.include.common import get_ethkey
  57. get_ethkey()
  58. return True
  59. def ssh_socks_proxy(self, name, ut):
  60. from test.cmdtest_d.ct_xmrwallet import CmdTestXMRWallet
  61. return CmdTestXMRWallet.init_proxy(external_call=True)
  62. def sudo(self, name, ut):
  63. from mmgen.util import have_sudo
  64. if have_sudo():
  65. return True
  66. else:
  67. ymsg(f'To run the test suite, please enable sudo without password for user ‘{os.getenv("USER")}’')
  68. return False