From 2d02af152e0d7fb4966d9abb7571f1beb6eb65a0 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 14 Nov 2019 17:22:15 +0000 Subject: [PATCH] [msys2]: test suite fixes --- mmgen/main_passgen.py | 2 ++ mmgen/util.py | 6 +++++- test/test_py_d/ts_ref.py | 22 +++++++++++----------- test/test_py_d/ts_regtest.py | 17 ++++++++++------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/mmgen/main_passgen.py b/mmgen/main_passgen.py index 397b8477..6c82d1d3 100755 --- a/mmgen/main_passgen.py +++ b/mmgen/main_passgen.py @@ -160,4 +160,6 @@ if keypress_confirm('Encrypt password list?'): al.encrypt(desc='password list') al.write_to_file(binary=True,desc='encrypted password list') else: + if g.test_suite_popen_spawn and g.platform == 'win': + time.sleep(0.1) al.write_to_file(desc='password list') diff --git a/mmgen/util.py b/mmgen/util.py index 0d9f476d..c47577e6 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -520,7 +520,11 @@ def write_data_to_file( outfile,data,desc='data', import msvcrt msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY) - sys.stdout.write(data.decode() if isinstance(data,bytes) else data) + # MSWin workaround. See msg_r() + try: + sys.stdout.write(data.decode() if isinstance(data,bytes) else data) + except: + os.write(1,data if isinstance(data,bytes) else data.encode()) def do_file(outfile,ask_write_prompt): if opt.outdir and not ignore_opt_outdir and not os.path.isabs(outfile): diff --git a/test/test_py_d/ts_ref.py b/test/test_py_d/ts_ref.py index e59b1df1..8aa2184d 100755 --- a/test/test_py_d/ts_ref.py +++ b/test/test_py_d/ts_ref.py @@ -242,17 +242,17 @@ class TestSuiteRef(TestSuiteBase,TestSuiteShared): def ref_passwdfile_chk(self,key,pat): return self.ref_addrfile_chk(ftype='passwd',id_key=key,pat=pat) - def ref_passwdfile_chk_b58_20(self): return self.ref_passwdfile_chk(key='b58_20',pat='Base58.*len.* 20\n') - def ref_passwdfile_chk_b58_10(self): return self.ref_passwdfile_chk(key='b58_10',pat='Base58.*len.* 10\n') - def ref_passwdfile_chk_b32_24(self): return self.ref_passwdfile_chk(key='b32_24',pat='Base32.*len.* 24\n') - def ref_passwdfile_chk_b32_12(self): return self.ref_passwdfile_chk(key='b32_12',pat='Base32.*len.* 12\n') - def ref_passwdfile_chk_hex_32(self): return self.ref_passwdfile_chk(key='hex_32',pat='Hexadec.*len.* 32\n') - def ref_passwdfile_chk_hex_48(self): return self.ref_passwdfile_chk(key='hex_48',pat='Hexadec.*len.* 48\n') - def ref_passwdfile_chk_hex_64(self): return self.ref_passwdfile_chk(key='hex_64',pat='Hexadec.*len.* 64\n') - def ref_passwdfile_chk_bip39_12(self): return self.ref_passwdfile_chk(key='bip39_12',pat='BIP39.*len.* 12\n') - def ref_passwdfile_chk_bip39_18(self): return self.ref_passwdfile_chk(key='bip39_18',pat='BIP39.*len.* 18\n') - def ref_passwdfile_chk_bip39_24(self): return self.ref_passwdfile_chk(key='bip39_24',pat='BIP39.*len.* 24\n') - def ref_passwdfile_chk_hex2bip39_12(self): return self.ref_passwdfile_chk(key='hex2bip39_12',pat='BIP39.*len.* 12\n') + def ref_passwdfile_chk_b58_20(self): return self.ref_passwdfile_chk(key='b58_20',pat=r'Base58.*len.* 20\b') + def ref_passwdfile_chk_b58_10(self): return self.ref_passwdfile_chk(key='b58_10',pat=r'Base58.*len.* 10\b') + def ref_passwdfile_chk_b32_24(self): return self.ref_passwdfile_chk(key='b32_24',pat=r'Base32.*len.* 24\b') + def ref_passwdfile_chk_b32_12(self): return self.ref_passwdfile_chk(key='b32_12',pat=r'Base32.*len.* 12\b') + def ref_passwdfile_chk_hex_32(self): return self.ref_passwdfile_chk(key='hex_32',pat=r'Hexadec.*len.* 32\b') + def ref_passwdfile_chk_hex_48(self): return self.ref_passwdfile_chk(key='hex_48',pat=r'Hexadec.*len.* 48\b') + def ref_passwdfile_chk_hex_64(self): return self.ref_passwdfile_chk(key='hex_64',pat=r'Hexadec.*len.* 64\b') + def ref_passwdfile_chk_bip39_12(self): return self.ref_passwdfile_chk(key='bip39_12',pat=r'BIP39.*len.* 12\b') + def ref_passwdfile_chk_bip39_18(self): return self.ref_passwdfile_chk(key='bip39_18',pat=r'BIP39.*len.* 18\b') + def ref_passwdfile_chk_bip39_24(self): return self.ref_passwdfile_chk(key='bip39_24',pat=r'BIP39.*len.* 24\b') + def ref_passwdfile_chk_hex2bip39_12(self): return self.ref_passwdfile_chk(key='hex2bip39_12',pat=r'BIP39.*len.* 12\b') def ref_tx_chk(self): fn = self.sources['ref_tx_file'][g.coin.lower()][bool(self.tn_ext)] diff --git a/test/test_py_d/ts_regtest.py b/test/test_py_d/ts_regtest.py index 24478d6e..7890a5bd 100755 --- a/test/test_py_d/ts_regtest.py +++ b/test/test_py_d/ts_regtest.py @@ -499,8 +499,8 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): os.environ['MMGEN_BOGUS_SEND'] = ('','1')[bool(bogus_send)] t = self.spawn('mmgen-txsend',['-d',self.tmpdir,'--'+user,'--status'] + extra_args + [tx_file]) os.environ['MMGEN_BOGUS_SEND'] = '1' - if exp1: t.expect(exp1) - if exp2: t.expect(exp2) + if exp1: t.expect(exp1,regex=True) + if exp2: t.expect(exp2,regex=True) return t def user_txdo( self, user, fee, outputs_cl, outputs_list, @@ -626,8 +626,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): disable_debug() ret = self.spawn('mmgen-regtest',['show_mempool']).read() restore_debug() - self.mempool = literal_eval(ret.split('\n')[0]) # allow for extra output by handler at end - return self.mempool + return literal_eval(ret.split('\n')[0]) # allow for extra output by handler at end def get_mempool1(self): mp = self._get_mempool() @@ -654,12 +653,14 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): chk = self.read_from_tmpfile('rbf_txid') if chk.strip() == mp[0]: rdie(2,'TX in mempool has not changed! RBF bump failed') + self.write_to_tmpfile('rbf_txid2',mp[0]+'\n') return 'ok' def bob_rbf_status2(self): if not g.proto.cap('rbf'): return 'skip' + new_txid = self.read_from_tmpfile('rbf_txid2').strip() return self.bob_rbf_status(rtFee[1], - 'Transaction has been replaced','{} in mempool'.format(self.mempool[0])) + 'Transaction has been replaced','{} in mempool'.format(new_txid)) def bob_rbf_status3(self): if not g.proto.cap('rbf'): return 'skip' @@ -667,9 +668,10 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): def bob_rbf_status4(self): if not g.proto.cap('rbf'): return 'skip' + new_txid = self.read_from_tmpfile('rbf_txid2').strip() return self.bob_rbf_status(rtFee[1], 'Replacement transaction has 1 confirmation', - 'Replacing transactions:\n {}'.format(self.mempool[0])) + 'Replacing transactions:\s+{}'.format(new_txid)) def bob_rbf_status5(self): if not g.proto.cap('rbf'): return 'skip' @@ -677,9 +679,10 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): def bob_rbf_status6(self): if not g.proto.cap('rbf'): return 'skip' + new_txid = self.read_from_tmpfile('rbf_txid2').strip() return self.bob_rbf_status(rtFee[1], 'Replacement transaction has 2 confirmations', - 'Replacing transactions:\n {}'.format(self.mempool[0])) + 'Replacing transactions:\s+{}'.format(new_txid)) @staticmethod def _gen_pairs(n):