diff --git a/mmgen/devtools.py b/mmgen/devtools.py index 47ce8747..a5f63ed4 100755 --- a/mmgen/devtools.py +++ b/mmgen/devtools.py @@ -70,7 +70,6 @@ if os.getenv('MMGEN_DEBUG') or os.getenv('MMGEN_TEST_SUITE') or os.getenv('MMGEN out.append('\n') if not e: out.append('{}\n'.format(repr(e))) - from collections import OrderedDict def isDict(obj): return isinstance(obj,dict) def isList(obj): @@ -85,7 +84,6 @@ if os.getenv('MMGEN_DEBUG') or os.getenv('MMGEN_TEST_SUITE') or os.getenv('MMGEN do_list(out,self,lvl=lvl,is_dict=isDict(self)) for k in self.__dict__: - if k in ('_OrderedDict__root','_OrderedDict__map'): continue # excluded because of recursion e = getattr(self,k) if isList(e) or isDict(e): out.append('{:>{l}}{:<10} {:16}'.format('',k,'<'+type(e).__name__+'>',l=(lvl*8)+4)) diff --git a/mmgen/protocol.py b/mmgen/protocol.py index d0e159f4..24b6ef9e 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -21,7 +21,7 @@ protocol.py: Coin protocol functions, classes and methods """ import sys,os,hashlib -from collections import namedtuple,OrderedDict +from collections import namedtuple from .util import msg,ymsg,Msg,ydie from .devtools import * @@ -283,7 +283,7 @@ class LitecoinProtocol(BitcoinProtocol): daemon_name = 'litecoind' daemon_data_dir = os.path.join(os.getenv('APPDATA'),'Litecoin') if g.platform == 'win' \ else os.path.join(g.home_dir,'.litecoin') - addr_ver_bytes = OrderedDict((('30','p2pkh'), ('32','p2sh'), ('05','p2sh'))) # new p2sh ver 0x32 must come first + addr_ver_bytes = { '30': 'p2pkh', '32': 'p2sh', '05': 'p2sh' } # new p2sh ver 0x32 must come first wif_ver_num = { 'std': 'b0' } mmtypes = ('L','C','S','B') secs_per_block = 150 @@ -297,7 +297,7 @@ class LitecoinProtocol(BitcoinProtocol): class LitecoinTestnetProtocol(LitecoinProtocol): # addr ver nums same as Bitcoin testnet, except for 'p2sh' - addr_ver_bytes = OrderedDict((('6f','p2pkh'), ('3a','p2sh'), ('c4','p2sh'))) + addr_ver_bytes = { '6f':'p2pkh', '3a':'p2sh', 'c4':'p2sh' } wif_ver_num = { 'std': 'ef' } # same as Bitcoin testnet data_subdir = 'testnet' daemon_data_subdir = 'testnet4' diff --git a/mmgen/tool.py b/mmgen/tool.py index 096703b1..253dbf99 100755 --- a/mmgen/tool.py +++ b/mmgen/tool.py @@ -1112,8 +1112,7 @@ class MMGenToolCmdMonero(MMGenToolCmds): if blockheight < 0: blockheight = 0 # TODO: handle the non-zero case - from collections import OrderedDict - bals = OrderedDict() # locked,unlocked + bals = {} # locked,unlocked try: process_wallets() diff --git a/mmgen/tw.py b/mmgen/tw.py index 94fc8016..bea3070e 100755 --- a/mmgen/tw.py +++ b/mmgen/tw.py @@ -760,8 +760,7 @@ class TrackingWallet(MMGenObject): @property def mmid_ordered_dict(self): - from collections import OrderedDict - return OrderedDict([(x['mmid'],{'addr':x['addr'],'comment':x['comment']}) for x in self.sorted_list]) + return dict((x['mmid'],{'addr':x['addr'],'comment':x['comment']}) for x in self.sorted_list) @write_mode def import_address(self,addr,label,rescan): diff --git a/mmgen/txsign.py b/mmgen/txsign.py index 78af581f..9ea5134d 100755 --- a/mmgen/txsign.py +++ b/mmgen/txsign.py @@ -38,8 +38,7 @@ ERROR: a key file must be supplied for the following non-{pnm} address{{}}:\n """.format(pnm=pnm).strip() } -from collections import OrderedDict -saved_seeds = OrderedDict() +saved_seeds = {} def get_seed_for_seed_id(sid,infiles,saved_seeds): diff --git a/test/objtest_py_d/ot_btc_mainnet.py b/test/objtest_py_d/ot_btc_mainnet.py index 52baa992..85976e3e 100755 --- a/test/objtest_py_d/ot_btc_mainnet.py +++ b/test/objtest_py_d/ot_btc_mainnet.py @@ -7,16 +7,14 @@ test.objtest_py_d.ot_btc_mainnet: BTC mainnet test vectors for MMGen data objects """ -from collections import OrderedDict - from mmgen.obj import * from mmgen.seed import * from .ot_common import * ssm = str(SeedShareCount.max_val) -tests = OrderedDict([ - ('Int', { +tests = { + 'Int': { 'bad': ('1L',0.0,'0.0','1.0',1.0,'s',1.1,'1.1'), 'good': ( ('0',0),('-1',-1),('7',7),-1,0,1,9999999, @@ -25,32 +23,32 @@ tests = OrderedDict([ {'n':'0xf','base':16,'ret':15}, {'n':'0xff','base':16,'ret':255}, ) - }), - ('AddrIdx', { + }, + 'AddrIdx': { 'bad': ('s',1.1,10000000,-1,0), 'good': (('7',7),(1,1),(9999999,9999999)) - }), - ('SeedShareIdx', { + }, + 'SeedShareIdx': { 'bad': ('s',1.1,1025,-1,0), 'good': (('7',7),(1,1),(1024,1024)) - }), - ('SeedShareCount', { + }, + 'SeedShareCount': { 'bad': ('s',2.1,1025,-1,0,1), 'good': (('7',7),(2,2),(1024,1024)) - }), - ('MasterShareIdx', { + }, + 'MasterShareIdx': { 'bad': ('s',1.1,1025,-1,0), 'good': (('7',7),(1,1),(1024,1024)) - }), - ('AddrIdxList', { + }, + 'AddrIdxList': { 'bad': ('x','5,9,1-2-3','8,-11','66,3-2'), 'good': ( ('3,2,2',[2,3]), ('101,1,3,5,2-7,99',[1,2,3,4,5,6,7,99,101]), ({'idx_list':AddrIdxList('1-5')},[1,2,3,4,5]) ) - }), - ('SubSeedIdxRange', { + }, + 'SubSeedIdxRange': { 'bad': (33,'x','-11','66,3','0','3-2','8000000','100000000',(1,2,3)), 'good': ( ('3',(3,3)), @@ -59,8 +57,8 @@ tests = OrderedDict([ (str(g.subseeds),(g.subseeds,g.subseeds)), (str(SubSeedIdxRange.max_idx),(SubSeedIdxRange.max_idx,SubSeedIdxRange.max_idx)), ) - }), - ('BTCAmt', { + }, + 'BTCAmt': { 'bad': ('-3.2','0.123456789',123,'123L','22000000',20999999.12345678, {'num':'1','from_decimal':True}, {'num':1,'from_decimal':True}, @@ -82,12 +80,12 @@ tests = OrderedDict([ 'ret':Decimal('0.00002428') }, {'num':1234,'from_unit':'satoshi','ret':Decimal('0.00001234')}, ) - }), - ('CoinAddr', { + }, + 'CoinAddr': { 'bad': (1,'x','я'), 'good': ('1MjjELEy6EJwk8fSNfpS8b5teFRo4X5fZr','32GiSWo9zJQgkCmjAaLRrbPwXhKry2jHhj'), - }), - ('SeedID', { + }, + 'SeedID': { 'bad': ( {'sid':'я'}, {'sid':'F00F00'}, @@ -97,20 +95,20 @@ tests = OrderedDict([ {'sid':'f00baa12'}, 'я',r32,'abc'), 'good': (({'sid':'F00BAA12'},'F00BAA12'),(Seed(r16),Seed(r16).sid)) - }), - ('SubSeedIdx', { + }, + 'SubSeedIdx': { 'bad': (33,'x','я','1x',200,'1ss','L','s','200LS','30ll','s100',str(SubSeedIdxRange.max_idx+1),'0'), 'good': (('1','1L'),('1s','1S'),'20S','30L',('300l','300L'),('200','200L'),str(SubSeedIdxRange.max_idx)+'S') - }), - ('MMGenID', { + }, + 'MMGenID': { 'bad': ('x',1,'f00f00f','a:b','x:L:3','F00BAA12:0','F00BAA12:Z:99'), 'good': (('F00BAA12:99','F00BAA12:L:99'),'F00BAA12:L:99','F00BAA12:S:99') - }), - ('TwMMGenID', { + }, + 'TwMMGenID': { 'bad': ('x','я','я:я',1,'f00f00f','a:b','x:L:3','F00BAA12:0','F00BAA12:Z:99',tw_pfx,tw_pfx+'я'), 'good': (('F00BAA12:99','F00BAA12:L:99'),'F00BAA12:L:99','F00BAA12:S:9999999',tw_pfx+'x') - }), - ('TwLabel', { + }, + 'TwLabel': { 'bad': ('x x','x я','я:я',1,'f00f00f','a:b','x:L:3','F00BAA12:0 x', 'F00BAA12:Z:99',tw_pfx+' x',tw_pfx+'я x', 'F00BAA12:S:1 '+ utf8_ctrl[:40], @@ -121,25 +119,25 @@ tests = OrderedDict([ 'F00BAA12:L:99 comment (UTF-8) α', 'F00BAA12:S:9999999 comment', tw_pfx+'x comment') - }), - ('MMGenTxID', { + }, + 'MMGenTxID': { 'bad': (1,[],'\0','\1','я','g','gg','FF','f00','F00F0012'), 'good': ('DEADBE','F00BAA') - }), - ('CoinTxID',{ + }, + 'CoinTxID':{ 'bad': (1,[],'\0','\1','я','g','gg','FF','f00','F00F0012',r16.hex(),r32.hex()+'ee'), 'good': (r32.hex(),) - }), - ('WifKey', { + }, + 'WifKey': { 'bad': (1,[],'\0','\1','я','g','gg','FF','f00',r16.hex(),'2MspvWFjBbkv2wzQGqhxJUYPCk3Y2jMaxLN'), 'good': ('5KXEpVzjWreTcQoG5hX357s1969MUKNLuSfcszF6yu84kpsNZKb', 'KwWr9rDh8KK5TtDa3HLChEvQXNYcUXpwhRFUPc5uSNnMtqNKLFhk'), - }), - ('PubKey', { + }, + 'PubKey': { 'bad': ({'arg':1,'compressed':False},{'arg':'F00BAA12','compressed':False},), 'good': ({'arg':'deadbeef','compressed':True},) # TODO: add real pubkeys - }), - ('PrivKey', { + }, + 'PrivKey': { 'bad': ( {'wif':1}, {'wif':'1'}, @@ -160,8 +158,8 @@ tests = OrderedDict([ {'s':r32,'compressed':False,'pubkey_type':'std','ret':r32.hex()}, {'s':r32,'compressed':True,'pubkey_type':'std','ret':r32.hex()} ) - }), - ('AddrListID', { # a rather pointless test, but do it anyway + }, + 'AddrListID': { # a rather pointless test, but do it anyway 'bad': ( {'sid':SeedID(sid='F00BAA12'),'mmtype':'Z','ret':'F00BAA12:Z'}, ), @@ -169,12 +167,12 @@ tests = OrderedDict([ {'sid':SeedID(sid='F00BAA12'),'mmtype':MMGenAddrType('S'),'ret':'F00BAA12:S'}, {'sid':SeedID(sid='F00BAA12'),'mmtype':MMGenAddrType('L'),'ret':'F00BAA12:L'}, ) - }), - ('MMGenWalletLabel', { + }, + 'MMGenWalletLabel': { 'bad': (utf8_text[:49],utf8_combining[:48],utf8_ctrl[:48],gr_uc_w_ctrl), 'good': (utf8_text[:48],) - }), - ('TwComment', { + }, + 'TwComment': { 'bad': ( utf8_combining[:40], utf8_ctrl[:40], text_jp[:41], @@ -185,16 +183,16 @@ tests = OrderedDict([ (ru_uc + gr_uc + utf8_text)[:80], text_jp[:40], text_zh[:40] ) - }), - ('MMGenTXLabel',{ + }, + 'MMGenTXLabel':{ 'bad': (utf8_text[:73],utf8_combining[:72],utf8_ctrl[:72],gr_uc_w_ctrl), 'good': (utf8_text[:72],) - }), - ('MMGenPWIDString', { # forbidden = list(u' :/\\') + }, + 'MMGenPWIDString': { # forbidden = list(u' :/\\') 'bad': ('foo/','foo:','foo:\\'), 'good': ('qwerty@яяя',) - }), - ('MMGenAddrType', { + }, + 'MMGenAddrType': { 'bad': ('U','z','xx',1,'dogecoin'), 'good': ( {'s':'legacy','ret':'L'}, @@ -206,18 +204,18 @@ tests = OrderedDict([ {'s':'bech32','ret':'B'}, {'s':'B','ret':'B'} ) - }), - ('MMGenPasswordType', { + }, + 'MMGenPasswordType': { 'bad': ('U','z','я',1,'passw0rd'), 'good': ( {'s':'password','ret':'P'}, {'s':'P','ret':'P'}, ) - }), - ('SeedSplitSpecifier', { + }, + 'SeedSplitSpecifier': { 'bad': ('M','αβ:2',1,'0:1','1:1','2:1','3:2','1:2000','abc:0:2'), 'good': ( ('1:2','2:2','alice:2:2','αβ:2:2','1:'+ssm,ssm+':'+ssm) ) - }), -]) + }, +} diff --git a/test/objtest_py_d/ot_btc_testnet.py b/test/objtest_py_d/ot_btc_testnet.py index 8b49f4fe..0ab80af2 100755 --- a/test/objtest_py_d/ot_btc_testnet.py +++ b/test/objtest_py_d/ot_btc_testnet.py @@ -7,22 +7,20 @@ test.objtest_py_d.ot_btc_testnet: BTC testnet test vectors for MMGen data objects """ -from collections import OrderedDict - from mmgen.obj import * from .ot_common import * -tests = OrderedDict([ - ('CoinAddr', { +tests = { + 'CoinAddr': { 'bad': (1,'x','я'), 'good': ('n2FgXPKwuFkCXF946EnoxWJDWF2VwQ6q8J','2MspvWFjBbkv2wzQGqhxJUYPCk3Y2jMaxLN'), - }), - ('WifKey', { + }, + 'WifKey': { 'bad': (1,[],'\0','\1','я','g','gg','FF','f00',r16.hex(),'2MspvWFjBbkv2wzQGqhxJUYPCk3Y2jMaxLN'), 'good': ('93HsQEpH75ibaUJYi3QwwiQxnkW4dUuYFPXZxcbcKds7XrqHkY6', 'cMsqcmDYZP1LdKgqRh9L4ZRU9br28yvdmTPwW2YQwVSN9aQiMAoR'), - }), - ('PrivKey', { + }, + 'PrivKey': { 'bad': ( {'wif':1}, {'wif':'1'}, @@ -42,6 +40,6 @@ tests = OrderedDict([ 'ret':'08d0ed83b64b68d56fa064be48e2385060ed205be2b1e63cd56d218038c3a05f'}, {'s':r32,'compressed':False,'pubkey_type':'std','ret':r32.hex()}, {'s':r32,'compressed':True,'pubkey_type':'std','ret':r32.hex()} - ) - }) -]) + ), + }, +} diff --git a/test/objtest_py_d/ot_eth_mainnet.py b/test/objtest_py_d/ot_eth_mainnet.py index a88e3662..4f646075 100755 --- a/test/objtest_py_d/ot_eth_mainnet.py +++ b/test/objtest_py_d/ot_eth_mainnet.py @@ -7,13 +7,11 @@ test.objtest_py_d.ot_eth_mainnet: ETH mainnet test vectors for MMGen data objects """ -from collections import OrderedDict - from mmgen.obj import * from .ot_common import * -tests = OrderedDict([ - ('ETHAmt', { +tests = { + 'ETHAmt': { 'bad': ('-3.2','0.1234567891234567891',123,'123L', {'num':'1','from_decimal':True}, {'num':1,'from_decimal':True}, @@ -27,8 +25,8 @@ tests = OrderedDict([ {'num':1234,'from_unit':'wei','ret':Decimal('0.000000000000001234')}, {'num':1234,'from_unit':'Mwei','ret':Decimal('0.000000001234')}, ) - }), - ('ETHNonce', { + }, + 'ETHNonce': { 'bad': ('z','я',-1,'-1',0.0,'0.0'), 'good': ( ('0',0),('1',1),('100',100),1,100, @@ -37,5 +35,5 @@ tests = OrderedDict([ {'n':'0xf','base':16,'ret':15}, {'n':'0xff','base':16,'ret':255}, ) - }), -]) + }, +} diff --git a/test/objtest_py_d/ot_ltc_mainnet.py b/test/objtest_py_d/ot_ltc_mainnet.py index 5b408d13..21047b04 100755 --- a/test/objtest_py_d/ot_ltc_mainnet.py +++ b/test/objtest_py_d/ot_ltc_mainnet.py @@ -7,26 +7,24 @@ test.objtest_py_d.ot_ltc_mainnet: LTC mainnet test vectors for MMGen data objects """ -from collections import OrderedDict - from mmgen.obj import * from .ot_common import * -tests = OrderedDict([ - ('LTCAmt', { +tests = { + 'LTCAmt': { 'bad': ('-3.2','0.123456789',123,'123L','88000000',80999999.12345678), 'good': (('80999999.12345678',Decimal('80999999.12345678')),) - }), - ('CoinAddr', { + }, + 'CoinAddr': { 'bad': (1,'x','я'), 'good': ('LXYx4j8PDGE8GEwDFnEQhcLyHFGsRxSJwt','MEnuCzUGHaQx9fK5WYvLwR1NK4SAo8HmSr'), - }), - ('WifKey', { + }, + 'WifKey': { 'bad': (1,[],'\0','\1','я','g','gg','FF','f00',r16.hex(),'2MspvWFjBbkv2wzQGqhxJUYPCk3Y2jMaxLN'), 'good': ('6udBAGS6B9RfGyvEQDkVDsWy3Kqv9eTULqtEfVkJtTJyHdLvojw', 'T7kCSp5E71jzV2zEJW4q5qU1SMB5CSz8D9VByxMBkamv1uM3Jjca'), - }), - ('PrivKey', { + }, + 'PrivKey': { 'bad': ( {'wif':1}, {'wif':'1'}, @@ -47,5 +45,5 @@ tests = OrderedDict([ {'s':r32,'compressed':False,'pubkey_type':'std','ret':r32.hex()}, {'s':r32,'compressed':True,'pubkey_type':'std','ret':r32.hex()} ) - }), -]) + }, +} diff --git a/test/objtest_py_d/ot_ltc_testnet.py b/test/objtest_py_d/ot_ltc_testnet.py index c3aab983..1183c413 100755 --- a/test/objtest_py_d/ot_ltc_testnet.py +++ b/test/objtest_py_d/ot_ltc_testnet.py @@ -7,22 +7,20 @@ test.objtest_py_d.ot_ltc_testnet: LTC testnet test vectors for MMGen data objects """ -from collections import OrderedDict - from mmgen.obj import * from .ot_common import * -tests = OrderedDict([ - ('CoinAddr', { +tests = { + 'CoinAddr': { 'bad': (1,'x','я'), 'good': ('n2D3joAy3yE5fqxUeCp38X6uPUcVn7EFw9','QN59YbnHsPQcbKWSq9PmTpjrhBnHGQqRmf') - }), - ('WifKey', { + }, + 'WifKey': { 'bad': (1,[],'\0','\1','я','g','gg','FF','f00',r16.hex(),'2MspvWFjBbkv2wzQGqhxJUYPCk3Y2jMaxLN'), 'good': ('936Fd4qs3Zy2ZiYHH7vZ3UpT23KtCAiGiG2xBTkjHo7jE9aWA2f', 'cQY3EumdaSNuttvDSUuPdiMYLyw8aVmYfFqxo9kdPuWbJBN4Ny66') - }), - ('PrivKey', { + }, + 'PrivKey': { 'bad': ( {'wif':1}, {'wif':'1'}, @@ -43,5 +41,5 @@ tests = OrderedDict([ {'s':r32,'compressed':False,'pubkey_type':'std','ret':r32.hex()}, {'s':r32,'compressed':True,'pubkey_type':'std','ret':r32.hex()} ) - }), -]) + }, +} diff --git a/test/test.py b/test/test.py index 3f09b5bd..86edb581 100755 --- a/test/test.py +++ b/test/test.py @@ -592,8 +592,7 @@ class TestSuiteRunner(object): self.data_dir = data_dir self.trash_dir = trash_dir self.cmd_total = 0 - from collections import OrderedDict - self.rebuild_list = OrderedDict() + self.rebuild_list = {} self.gm = CmdGroupMgr() self.repo_root = repo_root self.skipped_warnings = [] diff --git a/test/tooltest.py b/test/tooltest.py index 6d11c5a8..399a7484 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -54,47 +54,46 @@ sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:] cmd_args = opts.init(opts_data,add_opts=['exact_output','profile']) -from collections import OrderedDict -cmd_data = OrderedDict([ - ('cryptocoin', { - 'desc': 'Cryptocoin address/key commands', - 'cmd_data': OrderedDict([ - ('randwif', ()), - ('randpair', ()), # create 4 pairs: uncomp,comp,segwit,bech32 - ('wif2addr', ('randpair','o4')), - ('wif2hex', ('randpair','o4')), +cmd_data = { + 'cryptocoin': { + 'desc': 'Cryptocoin address/key commands', + 'cmd_data': { + 'randwif': (), + 'randpair': (), # create 4 pairs: uncomp,comp,segwit,bech32 + 'wif2addr': ('randpair','o4'), + 'wif2hex': ('randpair','o4'), + 'privhex2pubhex': ('wif2hex','o3'), # segwit only + 'pubhex2addr': ('privhex2pubhex','o3'), # segwit only + 'hex2wif': ('wif2hex','io2'), # uncomp, comp + 'addr2pubhash': ('randpair','o4'), # uncomp, comp, bech32 + 'pubhash2addr': ('addr2pubhash','io4'), # uncomp, comp, bech32 + }, + }, + 'mnemonic': { + 'desc': 'mnemonic commands', + 'cmd_data': { + 'hex2mn': (), + 'mn2hex': ('hex2mn','io3'), + 'mn_rand128': (), + 'mn_rand192': (), + 'mn_rand256': (), + 'mn_stats': (), + 'mn_printlist': (), + }, + }, +} - ('privhex2pubhex', ('wif2hex','o3')), # segwit only - ('pubhex2addr', ('privhex2pubhex','o3')), # segwit only - ('hex2wif', ('wif2hex','io2')), # uncomp, comp - ('addr2pubhash', ('randpair','o4'))] + # uncomp, comp, bech32 - ([],[ - ('pubhash2addr', ('addr2pubhash','io4')) # uncomp, comp, bech32 - ])[opt.type != 'zcash_z'] + - ([],[ - ('pubhex2redeem_script', ('privhex2pubhex','o3')), - ('wif2redeem_script', ('randpair','o3')), - ('wif2segwit_pair', ('randpair','o2')), - ('privhex2addr', ('wif2hex','o4')), # compare with output of randpair - ('pipetest', ('randpair','o3')) - ])[g.coin in ('BTC','LTC')] - ) - } - ), - ('mnemonic', { - 'desc': 'mnemonic commands', - 'cmd_data': OrderedDict([ - ('hex2mn', ()), - ('mn2hex', ('hex2mn','io3')), - ('mn_rand128', ()), - ('mn_rand192', ()), - ('mn_rand256', ()), - ('mn_stats', ()), - ('mn_printlist', ()), - ]) - } - ), -]) +if g.coin in ('BTC','LTC'): + cmd_data['cryptocoin']['cmd_data'].update({ + 'pubhex2redeem_script': ('privhex2pubhex','o3'), + 'wif2redeem_script': ('randpair','o3'), + 'wif2segwit_pair': ('randpair','o2'), + 'privhex2addr': ('wif2hex','o4'), # compare with output of randpair + 'pipetest': ('randpair','o3') + }) + +if opt.type == 'zcash_z': + del cmd_data['cryptocoin']['cmd_data']['pubhash2addr'] cfg = { 'name': 'the tool utility',