Browse Source

test suite: minor fixes and cleanups

The MMGen Project 2 months ago
parent
commit
af50f1b328
4 changed files with 47 additions and 30 deletions
  1. 3 2
      test/daemontest_d/ut_exec.py
  2. 20 12
      test/modtest_d/ut_dep.py
  3. 14 14
      test/modtest_d/ut_testdep.py
  4. 10 2
      test/test-release.sh

+ 3 - 2
test/daemontest_d/ut_exec.py

@@ -101,10 +101,11 @@ class unit_tests:
 		return True
 
 	def avail(self, name, ut):
-		return self._test_cmd(['start', '-Vm'], 'Testing availability of coin daemons...')
+		return self._test_cmd(
+			['start', '--print-version', '--mainnet-only'], 'Testing availability of coin daemons...')
 
 	def cmds(self, name, ut):
-		return self._test_cmd(['start', '-t'], 'Testing start commands for coin daemons...')
+		return self._test_cmd(['start', '--testing'], 'Testing start commands for coin daemons...')
 
 	def start(self, name, ut):
 		return self._test_cmd(['start'], 'Starting coin daemons...')

+ 20 - 12
test/modtest_d/ut_dep.py

@@ -7,7 +7,7 @@ test.modtest_d.ut_dep: dependency unit tests for the MMGen suite
   No data verification is performed.
 """
 
-import time
+import sys, time
 
 from subprocess import run, PIPE
 
@@ -18,8 +18,21 @@ from ..include.common import cfg, vmsg, check_solc_ver
 
 class unit_tests:
 
-	altcoin_deps = ('py_ecc', 'solc', 'keccak', 'pysocks')
-	win_skip = ('led',)
+	altcoin_deps = ('py_ecc', 'solc', 'keccak', 'pysocks', 'semantic_version')
+	win_skip = ('led', 'semantic_version')
+
+	def secp256k1(self, name, ut):
+		try:
+			from mmgen.proto.secp256k1.secp256k1 import pubkey_gen
+			pubkey_gen(bytes.fromhex('deadbeef'*8), 1)
+			return True
+		except ModuleNotFoundError as e:
+			ymsg(f'{type(e).__name__}: {e}')
+			msg('Installing secp256k1 module locally...')
+			run(['python3', './setup.py', 'build_ext', '--inplace'], stdout=PIPE, stderr=PIPE, check=True)
+			ymsg('The module has been installed.  Try re-running the test')
+			sys.exit(1)
+		return False
 
 	def led(self, name, ut):
 		from mmgen.led import LEDControl
@@ -62,15 +75,6 @@ class unit_tests:
 				msg('Is the ‘pysocks’ package installed?')
 		return False
 
-	def secp256k1(self, name, ut):
-		cp = run(['python3', './setup.py', 'build_ext', '--inplace'], stdout=PIPE, stderr=PIPE)
-		if cp.stderr:
-			vmsg(cp.stderr.decode())
-		time.sleep(0.5)
-		from mmgen.proto.secp256k1.secp256k1 import pubkey_gen
-		pubkey_gen(bytes.fromhex('deadbeef'*8), 1)
-		return True
-
 	def cryptography(self, name, ut):
 		from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
 		from cryptography.hazmat.backends import default_backend
@@ -129,6 +133,10 @@ class unit_tests:
 
 		return True
 
+	def semantic_version(self, name, ut):
+		from semantic_version import Version, NpmSpec
+		return True
+
 	def solc(self, name, ut):
 		from mmgen.protocol import init_proto
 		solc_ok = check_solc_ver()

+ 14 - 14
test/modtest_d/ut_testdep.py

@@ -18,12 +18,12 @@ class unit_tests:
 	win_skip = ('losetup', 'zcash_mini', 'sudo')
 	mac_skip = ('losetup',)
 
-	def pylint(self, name, ut):
-		try:
-			return run(['pylint', '--version'], stdout=None if cfg.verbose else DEVNULL).returncode == 0
-		except OSError as e:
-			ymsg('  ' + str(e))
-			bmsg("  Install pylint with 'python3 -m pip install pylint'")
+	def sudo(self, name, ut):
+		from mmgen.util import have_sudo
+		if have_sudo():
+			return True
+		else:
+			ymsg(f'To run the test suite, please enable sudo without password for user ‘{os.getenv("USER")}’')
 			return False
 
 	def losetup(self, name, ut):
@@ -37,6 +37,14 @@ class unit_tests:
 					raise
 		return True
 
+	def pylint(self, name, ut):
+		try:
+			return run(['pylint', '--version'], stdout=None if cfg.verbose else DEVNULL).returncode == 0
+		except OSError as e:
+			ymsg('  ' + str(e))
+			bmsg("  Install pylint with 'python3 -m pip install pylint'")
+			return False
+
 	def pycoin(self, name, ut):
 		from pycoin.networks.registry import network_for_netcode as nfnc
 		network = nfnc('btc')
@@ -67,11 +75,3 @@ class unit_tests:
 	def ssh_socks_proxy(self, name, ut):
 		from test.cmdtest_d.ct_xmrwallet import CmdTestXMRWallet
 		return CmdTestXMRWallet.init_proxy(external_call=True)
-
-	def sudo(self, name, ut):
-		from mmgen.util import have_sudo
-		if have_sudo():
-			return True
-		else:
-			ymsg(f'To run the test suite, please enable sudo without password for user ‘{os.getenv("USER")}’')
-			return False

+ 10 - 2
test/test-release.sh

@@ -206,8 +206,6 @@ do_reexec() {
 
 	[ -e 'test/init.sh' ] && test/init.sh $VERBOSE_SHORTOPT
 
-	[ "$repo" == 'mmgen-wallet' ] && eval "python3 setup.py build_ext --inplace $STDOUT_DEVNULL"
-
 	echo -e "\n${BLUE}Executing test runner: ${CYAN}test/test-release $ORIG_ARGS$RESET\n"
 
 	if [ "$TYPESCRIPT" ]; then
@@ -217,6 +215,14 @@ do_reexec() {
 	fi
 }
 
+install_secp256k1_mod_maybe() {
+	if [[ "$repo" =~ ^mmgen[-_]wallet ]]; then
+		[ -e mmgen/proto/secp256k1/secp256k1*$(python3 --version | sed 's/.* //;s/\.//;s/\..*//')* ] || {
+			eval "python3 setup.py build_ext --inplace $STDOUT_DEVNULL"
+		}
+	fi
+}
+
 in_nix_environment() {
 	for path in ${PATH//:/ }; do
 		realpath -q $path | grep -q '^/nix/store/' && break
@@ -420,6 +426,8 @@ check_tests
 
 test/clean.py
 
+install_secp256k1_mod_maybe
+
 start_time=$(date +%s)
 
 run_tests "$tests"