From fcc75b65e53ba473eb98f15838c83ee398b8f0cb Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 1 Sep 2021 16:56:34 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/addr.py | 4 +++- mmgen/obj.py | 6 +++--- test/gentest.py | 2 +- test/objtest.py | 4 +++- test/test-release.sh | 6 ++++++ test/test_py_d/ts_autosign.py | 1 + 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mmgen/addr.py b/mmgen/addr.py index ac5ed285..8716abce 100755 --- a/mmgen/addr.py +++ b/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 diff --git a/mmgen/obj.py b/mmgen/obj.py index 0efbb827..521c23d1 100755 --- a/mmgen/obj.py +++ b/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' diff --git a/test/gentest.py b/test/gentest.py index cb0bbb3b..ad42f398 100755 --- a/test/gentest.py +++ b/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() diff --git a/test/objtest.py b/test/objtest.py index 4d6e7112..7cb71e40 100755 --- a/test/objtest.py +++ b/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 diff --git a/test/test-release.sh b/test/test-release.sh index cb708743..3399d274 100755 --- a/test/test-release.sh +++ b/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' diff --git a/test/test_py_d/ts_autosign.py b/test/test_py_d/ts_autosign.py index 14d6deac..746ecc82 100755 --- a/test/test_py_d/ts_autosign.py +++ b/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)'), )