minor fixes and cleanups

This commit is contained in:
The MMGen Project 2021-09-01 16:56:34 +00:00
commit fcc75b65e5
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 17 additions and 6 deletions

View file

@ -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

View file

@ -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'

View file

@ -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()

View file

@ -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

View file

@ -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'

View file

@ -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)'),
)