Browse Source

py3port: test.py: rewrite autosign()

MMGen 6 years ago
parent
commit
7c0caa3815
1 changed files with 54 additions and 33 deletions
  1. 54 33
      test/test.py

+ 54 - 33
test/test.py

@@ -2411,68 +2411,89 @@ class MMGenTestSuite(object):
 		os.unlink(f1)
 		cmp_or_die(hincog_offset,int(o))
 
-	def autosign(self,name): # tests everything except device detection, mount/unmount
-
-		if skip_for_win(): return
+	# tests everything except device detection, mount/unmount
+	def autosign(self,name):
 
 		opts = ['--mountpoint='+cfg['tmpdir'],'--coins=btc,bch,ltc,eth']
+		txfiles = ('btc','bch','ltc','eth','erc20','etc')
+		txcount = 11
+# 		opts = ['--mountpoint='+cfg['tmpdir'],'--coins=btc,eth']
+# 		txfiles = ('btc','eth','erc20','etc')
+# 		txcount = 7
 
-		def copy_files_and_make_key():
-			fdata = (   ('btc',''),
-						('bch',''),
-						('ltc','litecoin'),
-						('eth','ethereum'),
-						('erc20','ethereum'),
-						('etc','ethereum_classic'))
-			tfns  = [cfgs['8']['ref_tx_file'][c][1] for c,d in fdata] + \
-					[cfgs['8']['ref_tx_file'][c][0] for c,d in fdata]
-			tfs = [os.path.join(ref_dir,d[1],fn) for d,fn in zip(fdata+fdata,tfns)]
-
-			try: os.mkdir(os.path.join(cfg['tmpdir'],'tx'))
-			except: pass
-
-			for f,fn in zip(tfs,tfns):
-				if fn: # use empty fn to skip file
-					shutil.copyfile(f,os.path.join(cfg['tmpdir'],'tx',fn))
+		if skip_for_win(): return
 
-			# make a bad tx file
-			with open(os.path.join(cfg['tmpdir'],'tx','bad.rawtx'),'w') as f:
-				f.write('bad tx data')
+		try: os.mkdir(os.path.join(cfg['tmpdir'],'tx'))
+		except: pass
 
+		def make_wallet():
 			t = MMGenExpect(name,'mmgen-autosign',opts+['gen_key'],extra_desc='(gen_key)')
 			t.expect_getend('Wrote key file ')
 			t.ok()
 
-		def get_mnemonic():
 			t = MMGenExpect(name,'mmgen-autosign',opts+['setup'],extra_desc='(setup)')
 			t.expect('words: ','3')
 			t.expect('OK? (Y/n): ','\n')
-			mn_fn = os.path.join(ref_dir,cfgs['8']['seed_id']+'.mmwords')
+			mn_fn = os.path.join(ref_dir,cfgs['8']['seed_id']+'.mmwords') # 98831F3A
 			mn = read_from_file(mn_fn).strip().split()
 			mn = ['foo'] + mn[:5] + ['realiz','realized'] + mn[5:]
 			wnum = 1
+			max_wordlen = 12
+
+			def get_pad_chars(n):
+				ret = ''
+				for i in range(n):
+					m = int(hexlify(os.urandom(1)),16) % 32
+					ret += r'123579!@#$%^&*()_+-=[]{}"?/,.<>|'[m]
+				return ret
+
 			for i in range(len(mn)):
+				w = mn[i]
+				if len(w) > 5:
+					w = w + '\n'
+				else:
+					w = get_pad_chars(3 if randbool() else 0) + w[0] + get_pad_chars(3) + w[1:] + get_pad_chars(7)
+					w = w[:max_wordlen+1]
 				em,rm = 'Enter word #{}: ','Repeat word #{}: '
 				ret = t.expect((em.format(wnum),rm.format(wnum-1)))
 				if ret == 0: wnum += 1
-				for j in range(len(mn[i])):
-					t.send(mn[i][j])
+				for j in range(len(w)):
+					t.send(w[j])
 					time.sleep(0.005)
-				t.send('\n')
 			wf = t.written_to_file('Autosign wallet')
 			t.ok()
 
-		def run_autosign():
+		def copy_files():
+			fdata_in = (('btc',''),
+						('bch',''),
+						('ltc','litecoin'),
+						('eth','ethereum'),
+						('erc20','ethereum'),
+						('etc','ethereum_classic'))
+			fdata = [e for e in fdata_in if e[0] in txfiles]
+			tfns  = [cfgs['8']['ref_tx_file'][c][1] for c,d in fdata] + \
+					[cfgs['8']['ref_tx_file'][c][0] for c,d in fdata]
+			tfs = [os.path.join(ref_dir,d[1],fn) for d,fn in zip(fdata+fdata,tfns)]
+
+			for f,fn in zip(tfs,tfns):
+				if fn: # use empty fn to skip file
+					shutil.copyfile(f,os.path.join(cfg['tmpdir'],'tx',fn))
+
+			# make a bad tx file
+			with open(os.path.join(cfg['tmpdir'],'tx','bad.rawtx'),'w') as f:
+				f.write('bad tx data')
+
+		def do_autosign():
 			t = MMGenExpect(name,'mmgen-autosign',opts+['wait'],extra_desc='(sign)')
-			t.expect('11 transactions signed')
+			t.expect('{} transactions signed'.format(txcount))
 			t.expect('1 transaction failed to sign')
 			t.expect('Waiting')
 			t.kill(2)
 			t.ok(exit_val=1)
 
-		copy_files_and_make_key()
-		get_mnemonic()
-		run_autosign()
+		make_wallet()
+		copy_files()
+		do_autosign()
 
 	# Saved reference file tests
 	def ref_wallet_conv(self,name):