ut_testdep.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python3
  2. """
  3. test.unit_tests_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')
  13. def pylint(self,name,ut):
  14. try:
  15. return run(['pylint','--version'],stdout=None if cfg.verbose else DEVNULL).returncode == 0
  16. except OSError as e:
  17. ymsg(' ' + str(e))
  18. bmsg(" Install pylint with 'python3 -m pip install pylint'")
  19. return False
  20. def core_repo(self,name,ut):
  21. crr = os.getenv('CORE_REPO_ROOT')
  22. if not crr or not os.path.exists(os.path.join(crr,'src/test/data/tx_valid.json')):
  23. ymsg('CORE_REPO_ROOT not set, or does not point to Bitcoin Core repository')
  24. return False
  25. return True
  26. def losetup(self,name,ut):
  27. os.stat('/dev/loop0')
  28. run(['/sbin/losetup','-f'],check=True,stdout=DEVNULL)
  29. return True
  30. def pycoin(self,name,ut):
  31. from pycoin.networks.registry import network_for_netcode as nfnc
  32. network = nfnc('btc')
  33. key = network.keys.private(secret_exponent=int(sec,16),is_compressed=True)
  34. hash160_c = key.hash160(is_compressed=True)
  35. network.address.for_p2pkh_wit(hash160_c)
  36. return True
  37. def monero_python(self,name,ut):
  38. from mmgen.util2 import load_cryptodomex
  39. load_cryptodomex()
  40. from monero.seed import Seed
  41. Seed('deadbeef' * 8).public_address()
  42. return True
  43. def keyconv(self,name,ut):
  44. run(['keyconv','-G','ltc'],stdout=DEVNULL,stderr=DEVNULL,check=True)
  45. return True
  46. def zcash_mini(self,name,ut):
  47. run(['zcash-mini'],stdout=DEVNULL,check=True)
  48. return True
  49. def ethkey(self,name,ut):
  50. if sys.platform == 'linux' and os.uname().machine != 'x86_64':
  51. distro = [l for l in open('/etc/os-release').read().split('\n') if l.startswith('ID=')][0][3:]
  52. if distro != 'archarm':
  53. ut.skip_msg(f'distro {distro!r} on architecture {os.uname().machine!r}')
  54. return True
  55. from test.include.common import get_ethkey
  56. get_ethkey()
  57. return True
  58. def ssh_socks_proxy(self,name,ut):
  59. from test.cmdtest_py_d.ct_xmrwallet import CmdTestXMRWallet
  60. return CmdTestXMRWallet.init_proxy(external_call=True)