Browse Source

autosign: whitespace, test code cleanups

The MMGen Project 4 years ago
parent
commit
d5078e8ce6
2 changed files with 47 additions and 47 deletions
  1. 17 15
      mmgen/main_autosign.py
  2. 30 32
      test/test_py_d/ts_autosign.py

+ 17 - 15
mmgen/main_autosign.py

@@ -40,21 +40,23 @@ opts_data = {
 		'desc': 'Auto-sign MMGen transactions',
 		'desc': 'Auto-sign MMGen transactions',
 		'usage':'[opts] [command]',
 		'usage':'[opts] [command]',
 		'options': """
 		'options': """
--h, --help          Print this help message
---, --longhelp      Print help message for long options (common options)
--c, --coins=c       Coins to sign for (comma-separated list)
--I, --no-insert-check Don't check for device insertion
--l, --led           Use status LED to signal standby, busy and error
--m, --mountpoint=m  Specify an alternate mountpoint (default: '{mp}')
--n, --no-summary    Don't print a transaction summary
--s, --stealth-led   Stealth LED mode - signal busy and error only, and only
-                    after successful authorization.
--S, --full-summary  Print a full summary of each signed transaction after
-                    each autosign run. The default list of non-MMGen outputs
-                    will not be printed.
--q, --quiet         Produce quieter output
--v, --verbose       Produce more verbose output
-""".format(mp=mountpoint),
+-h, --help            Print this help message
+--, --longhelp        Print help message for long options (common options)
+-c, --coins=c         Coins to sign for (comma-separated list)
+-I, --no-insert-check Don’t check for device insertion
+-l, --led             Use status LED to signal standby, busy and error
+-m, --mountpoint=M    Specify an alternate mountpoint 'M' (default: '{mp}')
+-n, --no-summary      Don’t print a transaction summary
+-s, --stealth-led     Stealth LED mode - signal busy and error only, and only
+                      after successful authorization.
+-S, --full-summary    Print a full summary of each signed transaction after
+                      each autosign run. The default list of non-MMGen outputs
+                      will not be printed.
+-q, --quiet           Produce quieter output
+-v, --verbose         Produce more verbose output
+""".format(
+		mp = mountpoint
+	),
 	'notes': """
 	'notes': """
 
 
                               COMMANDS
                               COMMANDS

+ 30 - 32
test/test_py_d/ts_autosign.py

@@ -67,12 +67,21 @@ class TestSuiteAutosign(TestSuiteBase):
 		if self.skip_for_win():
 		if self.skip_for_win():
 			return 'skip'
 			return 'skip'
 
 
+		def gen_key(opts):
+			if not getattr(self,'key_generated',False):
+				t = self.spawn('mmgen-autosign',opts+['gen_key'],extra_desc='(gen_key)')
+				t.expect_getend('Wrote key file ')
+				t.ok()
+				self.key_generated = True
+
 		def make_wallet(opts):
 		def make_wallet(opts):
-			t = self.spawn('mmgen-autosign',opts+['gen_key'],extra_desc='(gen_key)')
-			t.expect_getend('Wrote key file ')
-			t.ok()
 
 
-			t = self.spawn('mmgen-autosign',opts+['setup'],extra_desc='(setup)')
+			t = self.spawn(
+				'mmgen-autosign',
+				opts +
+				['setup'],
+				extra_desc = '(setup)' )
+
 			t.expect('words: ','3')
 			t.expect('words: ','3')
 			t.expect('OK? (Y/n): ','\n')
 			t.expect('OK? (Y/n): ','\n')
 			mn_file = dfl_words_file
 			mn_file = dfl_words_file
@@ -135,6 +144,7 @@ class TestSuiteAutosign(TestSuiteBase):
 
 
 			if gen_wallet:
 			if gen_wallet:
 				if not opt.skip_deps:
 				if not opt.skip_deps:
+					gen_key(opts)
 					make_wallet(opts)
 					make_wallet(opts)
 			else:
 			else:
 				do_mount()
 				do_mount()
@@ -178,50 +188,38 @@ class TestSuiteAutosign(TestSuiteBase):
 
 
 		def do_autosign(opts,mountpoint):
 		def do_autosign(opts,mountpoint):
 
 
+			def autosign_expect(t,txcount):
+				t.expect('{} transactions signed'.format(txcount))
+				t.expect('2 transactions failed to sign')
+				t.expect('Waiting')
+				t.kill(2)
+				t.req_exit_val = 1
+				imsg('')
+				t.ok()
+
 			if not opt.skip_deps:
 			if not opt.skip_deps:
+				gen_key(opts)
 				make_wallet(opts)
 				make_wallet(opts)
 
 
 			copy_files(mountpoint,include_bad_tx=True)
 			copy_files(mountpoint,include_bad_tx=True)
-
-			t = self.spawn('mmgen-autosign',opts+['--full-summary','wait'],extra_desc='(sign - full summary)')
-			t.expect('{} transactions signed'.format(txcount))
-			t.expect('2 transactions failed to sign')
-			t.expect('Waiting')
-			t.kill(2)
-			t.req_exit_val = 1
-			imsg('')
-			t.ok()
+			t = self.spawn('mmgen-autosign',opts+['--quiet','wait'],extra_desc='(sign)')
+			autosign_expect(t,txcount)
 
 
 			copy_files(mountpoint,remove_signed_only=True)
 			copy_files(mountpoint,remove_signed_only=True)
-			t = self.spawn('mmgen-autosign',opts+['--quiet','wait'],extra_desc='(sign)')
-			t.expect('{} transactions signed'.format(txcount))
-			t.expect('2 transactions failed to sign')
-			t.expect('Waiting')
-			t.kill(2)
-			t.req_exit_val = 1
-			imsg('')
-			t.ok()
+			t = self.spawn('mmgen-autosign',opts+['--full-summary','wait'],extra_desc='(sign - full summary)')
+			autosign_expect(t,txcount)
 
 
 			copy_files(mountpoint,include_bad_tx=True,fdata_in=(('btc',''),))
 			copy_files(mountpoint,include_bad_tx=True,fdata_in=(('btc',''),))
 			t = self.spawn(
 			t = self.spawn(
 				'mmgen-autosign',
 				'mmgen-autosign',
 				opts + ['--quiet','--stealth-led','wait'],
 				opts + ['--quiet','--stealth-led','wait'],
 				extra_desc='(sign - --quiet --stealth-led)' )
 				extra_desc='(sign - --quiet --stealth-led)' )
-			t.expect('2 transactions failed to sign')
-			t.expect('Waiting')
-			t.kill(2)
-			t.req_exit_val = 1
-			imsg('')
-			t.ok()
+			autosign_expect(t,txcount)
 
 
 			copy_files(mountpoint,include_bad_tx=False,fdata_in=(('btc',''),))
 			copy_files(mountpoint,include_bad_tx=False,fdata_in=(('btc',''),))
-			t = self.spawn(
-				'mmgen-autosign',
-				opts + ['--quiet','--led'],
-				extra_desc='(sign - --quiet --led)' )
+			t = self.spawn('mmgen-autosign',opts+['--quiet','--led'],extra_desc='(sign - --quiet --led)')
 			t.read()
 			t.read()
 			imsg('')
 			imsg('')
-			t.ok()
 
 
 			return t
 			return t