Browse Source

minor fixes and cleanups

The MMGen Project 3 years ago
parent
commit
fcc75b65e5
6 changed files with 17 additions and 6 deletions
  1. 3 1
      mmgen/addr.py
  2. 3 3
      mmgen/obj.py
  3. 1 1
      test/gentest.py
  4. 3 1
      test/objtest.py
  5. 6 0
      test/test-release.sh
  6. 1 0
      test/test_py_d/ts_autosign.py

+ 3 - 1
mmgen/addr.py

@@ -246,7 +246,9 @@ class KeyGenerator(MMGenObject):
 			m = 'Unable to execute priv2pub() from secp256k1 extension module'
 			assert priv2pub(bytes.fromhex('deadbeef'*8),1),m
 			return True
-		except:
+		except Exception as e:
+			if not silent:
+				ymsg(str(e))
 			return False
 
 import ecdsa

+ 3 - 3
mmgen/obj.py

@@ -144,7 +144,7 @@ class InitErrors:
 	def method_not_implemented(cls):
 		import traceback
 		raise NotImplementedError(
-			'method {!r} not implemented for class {!r}'.format(
+			'method {}() not implemented for class {!r}'.format(
 				traceback.extract_stack()[-2].name, cls.__name__) )
 
 class Hilite(object):
@@ -472,7 +472,7 @@ class BTCAmt(Decimal,Hilite,InitErrors):
 				me = Decimal.__new__(cls,num * getattr(cls,from_unit))
 			elif from_decimal:
 				assert type(num) == Decimal, f'number must be of type Decimal, not {type(num).__name__})'
-				me = Decimal.__new__(cls,num).quantize(cls.min_coin_unit)
+				me = Decimal.__new__(cls,num.quantize(Decimal('10') ** -cls.max_prec))
 			else:
 				for t in cls.forbidden_types:
 					assert type(num) is not t, f'number is of forbidden type {t.__name__}'
@@ -927,7 +927,7 @@ class IPPort(str,Hilite,InitErrors,MMGenObject):
 			assert m is not None, f'{s!r}: invalid IP:HOST specifier'
 			for e in m.groups():
 				if len(e) != 1 and e[0] == '0':
-					die(2,f'{e}: leading zeroes not permitted in dotted decimal element or port number')
+					raise ValueError(f'{e}: leading zeroes not permitted in dotted decimal element or port number')
 			res = [int(e) for e in m.groups()]
 			for e in res[:4]:
 				assert e <= 255, f'{e}: dotted decimal element > 255'

+ 1 - 1
test/gentest.py

@@ -413,7 +413,7 @@ else:
 	opts.usage()
 
 if type(a) == type(b):
-	die(1,'Address generators are the same!')
+	rdie(1,'Address generators are the same!')
 
 arg2 = parse_arg2()
 

+ 3 - 1
test/objtest.py

@@ -139,6 +139,8 @@ def run_test(test,arg,input_data,arg1,exc_name):
 			ret.pmsg() if hasattr(ret,'pmsg') else pmsg(ret)
 
 	except Exception as e:
+		if input_data == 'good':
+			raise ValueError('Error on good input data')
 		if not type(e).__name__ == exc_name:
 			msg(f'Incorrect exception: expected {exc_name} but got {type(e).__name__}')
 			raise
@@ -186,7 +188,7 @@ def do_loop():
 					arg,
 					input_data = k,
 					arg1       = arg1,
-					exc_name   = test_data[test].get('exc_name') or 'ObjectInitError',
+					exc_name   = test_data[test].get('exc_name') or ('ObjectInitError','None')[k=='good'],
 				)
 
 from mmgen.protocol import init_proto_from_opts

+ 6 - 0
test/test-release.sh

@@ -4,6 +4,11 @@
 REFDIR='test/ref'
 SUDO='sudo'
 
+[ -e "$CORE_REPO_ROOT/src/test/data/tx_valid.json" ] || {
+	echo "CORE_REPO_ROOT not set, or does not point to Bitcoin Core repository"
+	exit 1
+}
+
 if [ "$(uname -m)" == 'armv7l' ]; then
 	ARM32=1
 elif uname -a | grep -q 'MSYS'; then
@@ -264,6 +269,7 @@ f_hash='Hash function tests completed'
 
 [ "$ARM32" ] && t_hash_skip='512'        # gmpy produces invalid init constants
 [ "$MSYS2" ] && t_hash_skip='512 keccak' # 2:py_long_long issues, 3:no pysha3 for keccak reference
+[ "$SKIP_ALT_DEP" ] && t_hash_skip+=' keccak'
 
 i_ref='Miscellaneous reference data'
 s_ref='The following tests will test some generated values against reference data'

+ 1 - 0
test/test_py_d/ts_autosign.py

@@ -36,6 +36,7 @@ class TestSuiteAutosign(TestSuiteBase):
 	'autosigning with BTC, BCH, LTC, ETH and ETC'
 	networks = ('btc',)
 	tmpdir_nums = [18]
+	color = True
 	cmd_group = (
 		('autosign', 'transaction autosigning (BTC,BCH,LTC,ETH,ETC)'),
 	)