minor fixes and cleanups

This commit is contained in:
The MMGen Project 2022-07-26 14:02:36 +00:00
commit 401744bf88
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 49 additions and 45 deletions

View file

@ -92,11 +92,15 @@ class CoinAmt(Decimal,Hilite,InitErrors): # abstract class
def hl(self,color=True):
return self.colorize(self.__str__(),color=color)
def hl2(self,color=True,encl=''): # display with coin symbol
# fancy highlighting with coin unit, enclosure, formatting
def hl2(self,color=True,unit=False,fs='{}',encl=''):
res = fs.format(self)
return (
encl[:-1]
+ self.colorize(self.__str__(),color=color)
+ ' ' + type(self).__name__[:-3]
+ self.colorize(
(res.rstrip('0').rstrip('.') if '.' in res else res) +
((' ' + type(self).__name__[:-3]) if unit else ''),
color = color )
+ encl[1:]
)

View file

@ -228,7 +228,7 @@ class tool_cmd(tool_cmd_base):
The restored tracking wallet will have correct balances but no record of
historical transactions. These may be restored by running mmgen-tool
rescan_blockchain.
rescan_blockchain.
"""
from ..tw.json import TwJSON
await TwJSON.Import( self.proto, filename, ignore_checksum=ignore_checksum, batch=batch )

View file

@ -33,31 +33,35 @@ def exec_wrapper_init(): # don't change: name is used to test if script is runni
pass
def exec_wrapper_write_traceback(e):
import traceback,re
lines = traceback.format_exception(*sys.exc_info()) # returns a list
import traceback
pat = re.compile('File "<string>"')
repl = f'File "{exec_wrapper_execed_file}"'
lines = [pat.sub(repl,line,count=1) for line in lines]
def gen_output():
cwd = os.path.abspath('.')
yield 'Traceback (most recent call last):'
for e in traceback.extract_tb(sys.exc_info()[2]):
yield ' File "{f}", line {l}, in {n}\n {L}'.format(
f = (
exec_wrapper_execed_file if e.filename == '<string>' else
e.filename.removeprefix(cwd+'/').removeprefix('test/overlay/tree/').replace('_orig.py','.py')
),
l = '(scrubbed)' if os.getenv('MMGEN_TEST_SUITE_DETERMINISTIC') else e.lineno,
n = e.name,
L = e.line or 'N/A' )
exc = lines.pop()
if exc.startswith('SystemExit:'):
lines.pop()
tb_lines = list( gen_output() )
exc_line = (
repr(e) if type(e).__name__ in ('MMGenError','MMGenSystemExit') else
'{}: {}'.format( type(e).__name__, e ))
if os.getenv('MMGEN_TEST_SUITE_DETERMINISTIC'):
pat = re.compile(", line [0-9]+,")
lines = [pat.sub(", line (scrubbed),",line) for line in lines]
if 'SystemExit' in exc_line:
tb_lines.pop()
c = exec_wrapper_get_colors()
message = ( repr(e) if type(e).__name__ in ('MMGenError','MMGenSystemExit') else exc )
sys.stdout.write('{}{}'.format(
c.yellow( ''.join(lines) ),
c.red(message) )
+ '\n' )
sys.stdout.write('{}\n{}\n'.format( c.yellow( '\n'.join(tb_lines) ), c.red(exc_line) ))
if not os.getenv('EXEC_WRAPPER_NO_TRACEBACK'):
with open('test.py.err','w') as fp:
fp.write(''.join(lines+[exc]))
fp.write('\n'.join(tb_lines + [exc_line]))
def exec_wrapper_end_msg():
if os.getenv('EXEC_WRAPPER_SPAWN') and not os.getenv('MMGEN_TEST_SUITE_DETERMINISTIC'):

View file

@ -2,14 +2,13 @@
# Tested on Linux, Armbian, Raspbian, MSYS2
REFDIR='test/ref'
SUDO='sudo'
if [ "$(uname -m)" == 'armv7l' ]; then
ARM32=1
elif [ "$(uname -m)" == 'aarch64' ]; then
ARM64=1
elif uname -a | grep -q 'MSYS'; then
SUDO='' MSYS2=1;
MSYS2=1;
fi
trap 'echo -e "${GREEN}Exiting at user request$RESET"; exit' INT
@ -23,7 +22,6 @@ export PYTHONPATH=.
test_py='test/test.py -n'
objtest_py='test/objtest.py'
objattrtest_py='test/objattrtest.py'
colortest_py='test/colortest.py'
unit_tests_py='test/unit_tests.py --names --quiet'
tooltest_py='test/tooltest.py'
tooltest2_py='test/tooltest2.py --names --quiet'
@ -31,7 +29,6 @@ gentest_py='test/gentest.py --quiet'
scrambletest_py='test/scrambletest.py'
altcoin_mod_opts='--quiet'
mmgen_tool='cmds/mmgen-tool'
mmgen_keygen='cmds/mmgen-keygen'
python='python3'
rounds=100 rounds_min=20 rounds_mid=250 rounds_max=500
@ -63,7 +60,7 @@ do
echo " -O Use pexpect.spawn rather than popen_spawn where applicable"
echo " -p Pause between tests"
echo " -s LIST Skip tests in LIST (space-separated)"
echo " -S Build SDIST distribution, unpack, and run test in unpacked dir"
echo " -S Build SDIST distribution, unpack, and run test"
echo " -t Print the tests without running them"
echo " -v Run test/test.py with '--exact-output' and other commands"
echo " with '--verbose' switch"
@ -119,8 +116,7 @@ do
objtest_py="$python $objtest_py"
objattrtest_py="$python $objattrtest_py"
gentest_py="$python $gentest_py"
mmgen_tool="$python $mmgen_tool"
mmgen_keygen="$python $mmgen_keygen" ;&
mmgen_tool="$python $mmgen_tool" ;&
d) export PYTHONDEVMODE=1
export PYTHONWARNINGS='error' ;;
D) export MMGEN_TEST_SUITE_DETERMINISTIC=1
@ -556,7 +552,7 @@ run_tests() {
done
}
check_args() {
check_tests() {
for i in $tests; do
echo "$dfl_tests $extra_tests" | grep -q "\<$i\>" || {
echo "$i: unrecognized argument"
@ -575,7 +571,7 @@ remove_skipped_tests() {
remove_skipped_tests
check_args
check_tests
start_time=$(date +%s)

View file

@ -1005,14 +1005,14 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
self.write_to_tmpfile( fn, json.dumps(text,indent=4) )
return 'ok'
def carol_twimport(self,add_args=[],expect_str=None):
def carol_twimport(self,add_args=[],add_parms=[],expect_str=None):
from mmgen.tw.json import TwJSON
fn = joinpath( self.tmpdir, TwJSON.Base(self.proto).dump_fn )
t = self.spawn('mmgen-tool',['--carol','twimport',fn] + add_args)
t = self.spawn('mmgen-tool', add_args + ['--carol','twimport',fn] + add_parms)
t.expect('(y/N): ','y')
if expect_str:
t.expect(expect_str)
elif 'batch=true' in add_args:
elif 'batch=true' in add_parms:
t.expect('{} addresses imported'.format(15 if self.proto.coin == 'BCH' else 25))
else:
t.expect('import completed OK')
@ -1020,13 +1020,13 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
return t
def carol_twimport_nochksum(self):
return self.carol_twimport(add_args=['ignore_checksum=true'])
return self.carol_twimport(add_args=['--rpc-backend=aio'],add_parms=['ignore_checksum=true'])
def carol_twimport_batch(self):
return self.carol_twimport(add_args=['batch=true'])
return self.carol_twimport(add_parms=['batch=true'])
def carol_twimport_pretty(self):
return self.carol_twimport(add_args=['ignore_checksum=true'],expect_str='ignoring incorrect checksum')
return self.carol_twimport(add_parms=['ignore_checksum=true'],expect_str='ignoring incorrect checksum')
def carol_listaddresses(self):
return self.spawn('mmgen-tool',['--carol','listaddresses','showempty=1'])

View file

@ -236,11 +236,11 @@ class TestSuiteSeedSplit(TestSuiteBase):
def ss_bad_invocation3(self):
return self.ss_bad_invocation(
'mmgen-seedsplit',[self.tmpdir+'/no.mmdat','1:9'],1,'exception.FileNotFound')
'mmgen-seedsplit',[self.tmpdir+'/no.mmdat','1:9'],1,'FileNotFound')
def ss_bad_invocation4(self):
return self.ss_bad_invocation(
'mmgen-seedsplit',[self.tmpdir+'/dfl.sid','1:9'],1,'exception.BadFileExtension')
'mmgen-seedsplit',[self.tmpdir+'/dfl.sid','1:9'],1,'BadFileExtension')
def ss_bad_invocation5(self):
return self.ss_bad_invocation(
@ -252,11 +252,11 @@ class TestSuiteSeedSplit(TestSuiteBase):
def ss_bad_invocation7(self):
return self.ss_bad_invocation(
'mmgen-seedjoin',[self.tmpdir+'/a',self.tmpdir+'/b'],1,'exception.BadFileExtension')
'mmgen-seedjoin',[self.tmpdir+'/a',self.tmpdir+'/b'],1,'BadFileExtension')
def ss_bad_invocation8(self):
return self.ss_bad_invocation(
'mmgen-seedjoin',[self.tmpdir+'/a.mmdat',self.tmpdir+'/b.mmdat'],1,'exception.FileNotFound')
'mmgen-seedjoin',[self.tmpdir+'/a.mmdat',self.tmpdir+'/b.mmdat'],1,'FileNotFound')
def ss_bad_invocation9(self):
return self.ss_bad_invocation(
@ -264,8 +264,8 @@ class TestSuiteSeedSplit(TestSuiteBase):
def ss_bad_invocation10(self):
return self.ss_bad_invocation(
'mmgen-seedsplit',[self.tmpdir+'/a.mmdat','1:2'],1,'exception.FileNotFound')
'mmgen-seedsplit',[self.tmpdir+'/a.mmdat','1:2'],1,'FileNotFound')
def ss_bad_invocation11(self):
return self.ss_bad_invocation(
'mmgen-seedsplit',[self.tmpdir+'/dfl.sid','1:2'],1,'exception.BadFileExtension')
'mmgen-seedsplit',[self.tmpdir+'/dfl.sid','1:2'],1,'BadFileExtension')