ut_testdep.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. """
  3. test.unit_tests_d.ut_testdep: test dependency unit tests for the MMGen suite
  4. """
  5. from mmgen.common import *
  6. from subprocess import run,PIPE
  7. sec = 'deadbeef' * 8
  8. class unit_tests:
  9. altcoin_deps = ('pycoin','moneropy','keyconv','zcash_mini','ethkey','ssh_socks_proxy')
  10. win_skip = ('losetup','moneropy','zcash_mini')
  11. def core_repo(self,name,ut):
  12. crr = os.getenv('CORE_REPO_ROOT')
  13. if not crr or not os.path.exists(os.path.join(crr,'src/test/data/tx_valid.json')):
  14. ymsg('CORE_REPO_ROOT not set, or does not point to Bitcoin Core repository')
  15. return False
  16. return True
  17. def losetup(self,name,ut):
  18. os.stat('/dev/loop0')
  19. run(['/sbin/losetup','-f'],check=True,stdout=PIPE)
  20. return True
  21. def pycoin(self,name,ut):
  22. from pycoin.networks.registry import network_for_netcode as nfnc
  23. network = nfnc('btc')
  24. key = network.keys.private(secret_exponent=int(sec,16),is_compressed=True)
  25. hash160_c = key.hash160(is_compressed=True)
  26. addr = network.address.for_p2pkh_wit(hash160_c)
  27. return True
  28. def moneropy(self,name,ut):
  29. from moneropy import account
  30. res = account.account_from_spend_key(sec)
  31. return True
  32. def keyconv(self,name,ut):
  33. res = run(['keyconv','-G','ltc'],stdout=PIPE,stderr=PIPE,check=True)
  34. return True
  35. def zcash_mini(self,name,ut):
  36. res = run(['zcash-mini'],stdout=PIPE,check=True)
  37. return True
  38. def ethkey(self,name,ut):
  39. if g.platform == 'linux':
  40. distro = [l for l in open('/etc/os-release').read().split('\n') if l.startswith('ID=')][0][3:]
  41. if distro not in ('arch','archarm'):
  42. ymsg(f'Skipping ethkey availability test for distro {distro!r}')
  43. return True
  44. from test.include.common import get_ethkey
  45. get_ethkey()
  46. return True
  47. def ssh_socks_proxy(self,name,ut):
  48. from test.test_py_d.ts_xmrwallet import TestSuiteXMRWallet
  49. return TestSuiteXMRWallet.init_proxy(external_call=True)