test.py: tx*_ui_common(): make 'caller' a keyword arg

This commit is contained in:
The MMGen Project 2019-03-04 07:02:57 +00:00
commit 78176a0833
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 43 additions and 28 deletions

View file

@ -328,7 +328,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
t = self.spawn('mmgen-txcreate', self.eth_args + ['-B'] + args)
t.expect(r'add \[l\]abel, .*?:.','p', regex=True)
t.written_to_file('Account balances listing')
return self.txcreate_ui_common( t,self.test_name,menu=menu,
return self.txcreate_ui_common( t, menu=menu,
input_sels_prompt = 'to spend from',
inputs = acct,
file_desc = 'Ethereum transaction',
@ -350,7 +350,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
+ add_args
+ ([],['--yes'])[ni]
+ ['-k', keyfile, txfile, dfl_words_file] )
return self.txsign_ui_common(t,self.test_name,ni=ni,has_label=True)
return self.txsign_ui_common(t,ni=ni,has_label=True)
def txsend(self,ni=False,bogus_send=False,ext='{}.sigtx',add_args=[]):
ext = ext.format('' if g.debug_utf8 else '')
@ -358,7 +358,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
if not bogus_send: os.environ['MMGEN_BOGUS_SEND'] = ''
t = self.spawn('mmgen-txsend', self.eth_args + add_args + [txfile])
if not bogus_send: os.environ['MMGEN_BOGUS_SEND'] = '1'
txid = self.txsend_ui_common(t,self.test_name,quiet=True,bogus_send=bogus_send,has_label=True)
txid = self.txsend_ui_common(t,quiet=True,bogus_send=bogus_send,has_label=True)
return t
def txcreate1(self):
@ -516,12 +516,12 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
ext = '[0,8000]{}.rawtx'.format('' if g.debug_utf8 else '')
txfile = self.get_file_with_ext(ext,no_dot=True)
t = self.spawn('mmgen-txsign', self.eth_args + ['--yes','-k',keyfile,txfile],no_msg=True)
self.txsign_ui_common(t,self.test_name,ni=True)
self.txsign_ui_common(t,ni=True)
txfile = txfile.replace('.rawtx','.sigtx')
t = self.spawn('mmgen-txsend', self.eth_args + [txfile],no_msg=True)
os.environ['MMGEN_BOGUS_SEND'] = '1'
txid = self.txsend_ui_common(t,mmgen_cmd,quiet=True,bogus_send=False)
txid = self.txsend_ui_common(t,caller=mmgen_cmd,quiet=True,bogus_send=False)
addr = t.expect_getend('Contract address: ')
from mmgen.altcoins.eth.tx import EthereumMMGenTX as etx
assert etx.get_exec_status(txid.encode(),True) != 0,(
@ -618,7 +618,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
def token_txcreate(self,args=[],token='',inputs='1',fee='50G'):
t = self.spawn('mmgen-txcreate', self.eth_args + ['--token='+token,'-B','--tx-fee='+fee] + args)
return self.txcreate_ui_common( t,self.test_name,
return self.txcreate_ui_common( t,
menu = [],
inputs = inputs,
input_sels_prompt = 'to spend from',

View file

@ -403,7 +403,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared):
outputs_list = [(addrs_per_wallet+1)*i + 1 for i in range(len(tx_data))]
if non_mmgen_input: outputs_list.append(len(tx_data)*(addrs_per_wallet+1) + 1)
self.txcreate_ui_common(t,self.test_name,
self.txcreate_ui_common(t,
menu=(['M'],['M','D','m','g'])[self.test_name=='txcreate'],
inputs=' '.join(map(str,outputs_list)),
add_comment=('',ref_tx_label_lat_cyr_gr)[do_label],
@ -447,13 +447,13 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared):
if not bogus_send: os.environ['MMGEN_BOGUS_SEND'] = ''
t = self.spawn('mmgen-txsend', extra_opts + ['-d',self.tmpdir,sigfile])
if not bogus_send: os.environ['MMGEN_BOGUS_SEND'] = '1'
self.txsend_ui_common(t,self.test_name,view='t',add_comment='')
self.txsend_ui_common(t,view='t',add_comment='')
return t
def txdo(self,addrfile,wallet):
t = self.txcreate_common(sources=['1'],txdo_args=[wallet])
self.txsign_ui_common(t,self.test_name,view='n',do_passwd=True)
self.txsend_ui_common(t,self.test_name)
self.txsign_ui_common(t,view='n',do_passwd=True)
self.txsend_ui_common(t)
return t
def _walletconv_export(self,wf,desc,uargs=[],out_fmt='w',pf=None,out_pw=False):
@ -652,8 +652,8 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared):
for cnum,desc in (('1','incognito data'),('3','MMGen wallet')):
t.passphrase('{}'.format(desc),self.cfgs[cnum]['wpasswd'])
self.txsign_ui_common(t,self.test_name)
self.txsend_ui_common(t,self.test_name)
self.txsign_ui_common(t)
self.txsend_ui_common(t)
cmd = 'touch ' + joinpath(self.tmpdir,'txdo')
os.system(cmd.encode())

View file

@ -334,7 +334,8 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
extra_args + ([],[wf])[bool(wf)] + outputs_cl)
os.environ['MMGEN_BOGUS_SEND'] = '1'
self.txcreate_ui_common(t,'txdo',
self.txcreate_ui_common(t,
caller = 'txdo',
menu = ['M'],
inputs = outputs_list,
file_desc = 'Signed transaction',
@ -405,7 +406,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
t.do_comment(False,has_label=True)
t.passphrase('MMGen wallet',rt_pw)
t.written_to_file('Signed transaction')
self.txsend_ui_common(t,'txdo',bogus_send=False,file_desc='Signed transaction')
self.txsend_ui_common(t,caller='txdo',bogus_send=False,file_desc='Signed transaction')
t.read()
return t

View file

@ -30,14 +30,24 @@ from test.common import *
class TestSuiteShared(object):
'shared methods for the test.py test suite'
def txcreate_ui_common(self,t,caller,
menu=[],inputs='1',
file_desc='Transaction',
input_sels_prompt='to spend',
bad_input_sels=False,non_mmgen_inputs=0,
interactive_fee='',
fee_desc='transaction fee',fee_res=None,eth_fee_res=None,
add_comment='',view='t',save=True):
def txcreate_ui_common( self,t,
caller = None,
menu = [],
inputs = '1',
file_desc = 'Transaction',
input_sels_prompt = 'to spend',
bad_input_sels = False,
non_mmgen_inputs = 0,
interactive_fee = '',
fee_desc = 'transaction fee',
fee_res = None,
eth_fee_res = None,
add_comment = '',
view = 't',
save = True ):
txdo = (caller or self.test_name)[:4] == 'txdo'
for choice in menu + ['q']:
t.expect(r'\[q\]uit view, .*?:.',choice,regex=True)
if bad_input_sels:
@ -45,7 +55,7 @@ class TestSuiteShared(object):
t.expect(input_sels_prompt+': ',r+'\n')
t.expect(input_sels_prompt+': ',inputs+'\n')
if not caller[:4] == 'txdo':
if not txdo:
for i in range(non_mmgen_inputs):
t.expect('Accept? (y/N): ','y')
@ -64,13 +74,14 @@ class TestSuiteShared(object):
t.expect('(Y/n): ','\n') # chg amt OK?
t.do_comment(add_comment)
t.view_tx(view)
if not caller[:4] == 'txdo':
if not txdo:
t.expect('(y/N): ',('n','y')[save])
t.written_to_file(file_desc)
return t
def txsign_ui_common( self,t,caller,
def txsign_ui_common( self,t,
caller = None,
view = 't',
add_comment = '',
file_desc = 'Signed transaction',
@ -78,7 +89,8 @@ class TestSuiteShared(object):
save = True,
do_passwd = False,
has_label = False ):
txdo = caller[:4] == 'txdo'
txdo = (caller or self.test_name)[:4] == 'txdo'
if do_passwd:
t.passphrase('MMGen wallet',self.wpasswd)
@ -92,7 +104,8 @@ class TestSuiteShared(object):
return t
def txsend_ui_common( self,t,caller,
def txsend_ui_common( self,t,
caller = None,
view = 'n',
add_comment = '',
file_desc = 'Sent transaction',
@ -101,7 +114,8 @@ class TestSuiteShared(object):
quiet = False,
has_label = False ):
txdo = caller[:4] == 'txdo'
txdo = (caller or self.test_name)[:4] == 'txdo'
if not txdo:
t.license() # MMGEN_NO_LICENSE is set, so does nothing
t.view_tx(view)