Browse Source

[msys2]: test suite fixes

The MMGen Project 5 years ago
parent
commit
2d02af152e
4 changed files with 28 additions and 19 deletions
  1. 2 0
      mmgen/main_passgen.py
  2. 5 1
      mmgen/util.py
  3. 11 11
      test/test_py_d/ts_ref.py
  4. 10 7
      test/test_py_d/ts_regtest.py

+ 2 - 0
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')

+ 5 - 1
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):

+ 11 - 11
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)]

+ 10 - 7
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):