test suite: minor fixes and cleanups

This commit is contained in:
The MMGen Project 2023-10-13 09:51:14 +00:00
commit 653827c15e
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
12 changed files with 43 additions and 28 deletions

View file

@ -125,7 +125,7 @@ class Signable:
for f in bad_files:
yield red(f.name)
class xmr_signable(transaction): # virtual class
class xmr_signable(transaction): # mixin class
def need_daemon_restart(self,m,new_idx):
old_idx = self.parent.xmr_cur_wallet_idx

View file

@ -74,8 +74,7 @@ def exec_wrapper_write_traceback(e,exit_val):
sys.stdout.write('{}\n{}\n'.format( c.yellow( '\n'.join(tb_lines) ), c.red(exc_line) ))
from test.include.common import cmdtest_py_error_fn
with open(cmdtest_py_error_fn,'w') as fp:
with open('test.err','w') as fp:
fp.write('\n'.join(tb_lines + [exc_line]))
print(c.blue('{} script exited with error').format(

View file

@ -37,6 +37,7 @@ class CmdTestBase:
color = False
need_daemon = False
win_skip = False
tmpdir_nums = []
def __init__(self,trunner,cfgs,spawn):
if hasattr(self,'name'): # init will be called multiple times for classes with multiple inheritance
@ -65,14 +66,6 @@ class CmdTestBase:
def tmpdir(self):
return os.path.join('test','tmp','{}{}'.format(self.tmpdir_num,'' if cfg.debug_utf8 else ''))
@property
def segwit_mmtype(self):
return ('segwit','bech32')[bool(cfg.bech32)] if self.segwit else None
@property
def segwit_arg(self):
return ['--type=' + self.segwit_mmtype] if self.segwit_mmtype else []
def get_file_with_ext(self,ext,**kwargs):
return get_file_with_ext(self.tmpdir,ext,**kwargs)

View file

@ -23,7 +23,7 @@ This module is unmaintained and currently non-functional
from mmgen.util import die
from .common import get_file_with_ext
from .common import get_file_with_ext,rt_pw
from .ct_regtest import CmdTestRegtest
class CmdTestChainsplit(CmdTestRegtest):

View file

@ -25,7 +25,7 @@ import sys,os,re,time
from mmgen.util import ymsg
from ..include.common import cfg,start_test_daemons,stop_test_daemons,imsg
from .common import get_file_with_ext
from .common import get_file_with_ext,dfl_words_file
from .ct_base import CmdTestBase
from .ct_main import CmdTestMain

View file

@ -20,7 +20,7 @@
test.cmdtest_py_d.ct_regtest: Regtest tests for the cmdtest.py test suite
"""
import os,json,time,re
import sys,os,json,time,re
from decimal import Decimal
from mmgen.color import yellow
@ -59,6 +59,7 @@ pat_date_time = r'\b\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d\b'
dfl_wcls = get_wallet_cls('mmgen')
tx_fee = rtFundAmt = rtFee = rtBals = rtBals_gb = rtBobOp3 = rtAmts = {} # pylint
rt_pw = 'abc-α'
rt_data = {
'tx_fee': {'btc':'0.0001','bch':'0.001','ltc':'0.01'},
@ -172,6 +173,8 @@ class CmdTestRegtest(CmdTestBase,CmdTestShared):
color = True
deterministic = False
test_rbf = False
proto = None # pylint
cmd_group_in = (
('setup', 'regtest (Bob and Alice) mode setup'),
('subgroup.misc', []),
@ -445,9 +448,8 @@ class CmdTestRegtest(CmdTestBase,CmdTestShared):
self.proto = init_proto( cfg, self.proto.coin, network='regtest', need_amt=True )
coin = self.proto.coin.lower()
import test.cmdtest_py_d.ct_regtest as rt_mod
for k in rt_data:
setattr( rt_mod, k, rt_data[k][coin] if coin in rt_data[k] else None )
setattr( sys.modules[__name__], k, rt_data[k][coin] if coin in rt_data[k] else None )
if self.proto.coin == 'BTC':
self.test_rbf = True # tests are non-coin-dependent, so run just once for BTC

View file

@ -23,12 +23,20 @@ test.cmdtest_py_d.ct_shared: Shared methods for the cmdtest.py test suite
from mmgen.util import get_extension
from mmgen.wallet import get_wallet_cls
from ..include.common import cmp_or_die,strip_ansi_escapes,joinpath
from ..include.common import cfg,cmp_or_die,strip_ansi_escapes,joinpath
from .common import ref_bw_file,ref_bw_hash_preset,ref_dir
class CmdTestShared:
'shared methods for the cmdtest.py test suite'
@property
def segwit_mmtype(self):
return ('segwit','bech32')[bool(cfg.bech32)] if self.segwit else None
@property
def segwit_arg(self):
return ['--type=' + self.segwit_mmtype] if self.segwit_mmtype else []
def txcreate_ui_common(
self,
t,

View file

@ -119,7 +119,10 @@ class TestKeccak(TestHashFunc):
from Cryptodome.Hash import keccak
self.hashlib = hashlib
else:
import sha3
try:
import sha3
except ImportError as e:
die(2,str(e))
self.hashlib = sha3
def test_constants(self):
@ -172,9 +175,10 @@ class TestSha512(TestSha2):
0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc,
0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 )
from test.include.common import getrand,set_globals
from mmgen.cfg import Config
if __name__ == '__main__':
from test.include.common import getrand,set_globals
from mmgen.cfg import Config
assert len(sys.argv) in (2,3),"Test takes 1 or 2 arguments: test name, plus optional rounds count"
test = sys.argv[1].capitalize()

View file

@ -35,10 +35,14 @@ if not os.getenv('MMGEN_DEVTOOLS'):
from mmgen.cfg import Config,gc
from mmgen.color import green,gray
from mmgen.util import msg,gmsg,ymsg,Msg,die,async_run
from mmgen.util import msg,gmsg,ymsg,Msg,async_run
from test.include.common import set_globals,end_msg
def die(ev,s):
msg(s)
sys.exit(ev)
opts_data = {
'text': {
'desc': "Unit tests for the MMGen suite",

View file

@ -35,10 +35,14 @@ class unit_tests:
if python_version >= '3.11':
ut.skip_msg(f'Python version {python_version}')
else:
from sha3 import keccak_256
try:
from sha3 import keccak_256
except ImportError as e:
ymsg(str(e))
return False
return True
def pycryptodomex(self,name,ut): # ETH,XMR
def pycryptodomex(self,name,ut): # ETH,XMR (keccak)
from mmgen.pyversion import python_version
if python_version >= '3.11' or sys.platform == 'win32':
try:

View file

@ -5,7 +5,7 @@ test.unit_tests_d.ut_testdep: test dependency unit tests for the MMGen suite
"""
import sys,os
from subprocess import run,PIPE
from subprocess import run,DEVNULL
from mmgen.util import ymsg
@ -25,7 +25,7 @@ class unit_tests:
def losetup(self,name,ut):
os.stat('/dev/loop0')
run(['/sbin/losetup','-f'],check=True,stdout=PIPE)
run(['/sbin/losetup','-f'],check=True,stdout=DEVNULL)
return True
def pycoin(self,name,ut):
@ -42,11 +42,11 @@ class unit_tests:
return True
def keyconv(self,name,ut):
run(['keyconv','-G','ltc'],stdout=PIPE,stderr=PIPE,check=True)
run(['keyconv','-G','ltc'],stdout=DEVNULL,stderr=DEVNULL,check=True)
return True
def zcash_mini(self,name,ut):
run(['zcash-mini'],stdout=PIPE,check=True)
run(['zcash-mini'],stdout=DEVNULL,check=True)
return True
def ethkey(self,name,ut):

View file

@ -88,7 +88,8 @@ async def test_tx(tx_proto,tx_hex,desc,n):
assert A == B, fs.format(i,A,B)
async def do_mmgen_ref(daemons,fns,name,desc):
start_test_daemons(*daemons)
# NB: remove_datadir is required here for some reason (seems to be Bitcoin Core version-dependent)
start_test_daemons(*daemons,remove_datadir=True)
print_info(name,desc)
for n,fn in enumerate(fns):
tx = await CompletedTX( cfg=cfg, filename=fn, quiet_open=True )