From 3db1c423ef23e1cf9406ec73305436daf65c2a8f Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 6 Nov 2019 17:35:14 +0000 Subject: [PATCH] gentest.py: forkcoin testing framework, BCH support --- mmgen/altcoin.py | 12 +++++++++--- test/gentest.py | 25 +++++++++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/mmgen/altcoin.py b/mmgen/altcoin.py index f467b06c..9a1dc3c0 100755 --- a/mmgen/altcoin.py +++ b/mmgen/altcoin.py @@ -57,10 +57,9 @@ class CoinInfo(object): # Trust levels apply to key/address generation only. # Non core-coin fork coins (i.e. BCG) must be disabled here to prevent generation from # incorrect scrambled seed. - ce('Bitcoin', 'BTC', 0x80, (0x00,'1'), (0x05,'3'), True, -1), - ce('BitcoinSegwit2X', 'B2X', 0x80, (0x00,'1'), (0x05,'3'), True, -1), + ce('Bitcoin', 'BTC', 0x80, (0x00,'1'), (0x05,'3'), True, 5), + ce('Bcash', 'BCH', 0x80, (0x00,'1'), (0x05,'3'), False, 5), ce('BitcoinGold', 'BCG', 0x80, (0x00,'1'), (0x05,'3'), True, -1), - ce('Bcash', 'BCH', 0x80, (0x00,'1'), (0x05,'3'), False,-1), ce('2GiveCoin', '2GIVE', 0xa7, (0x27,('G','H')), None, False, 0), ce('42Coin', '42', 0x88, (0x08,'4'), None, False, 1), ce('ACoin', 'ACOIN', 0xe6, (0x17,'A'), None, False, 0), @@ -210,12 +209,16 @@ class CoinInfo(object): ) coin_constants['testnet'] = ( + ce('Bitcoin', 'BTC', 0xef, (0x6f,('m','n')), (0xc4,'2'), True, 5), + ce('Bcash', 'BCH', 0xef, (0x6f,('m','n')), (0xc4,'2'), True, 5), + ce('BitcoinGold', 'BCG', 0xef, (0x6f,('m','n')), (0xc4,'2'), True, -1), ce('Dash', 'DASH', 0xef, (0x8c,'y'), (0x13,('8','9')), False, 1), ce('Decred', 'DCR', 0x230e, (0x0f21,'T'), (0x0e6c,'S'), False, 1), ce('Dogecoin', 'DOGE', 0xf1, (0x71,'n'), (0xc4,'2'), False, 2), ce('Feathercoin', 'FTC', 0xc1, (0x41,'T'), (0xc4,'2'), False, 2), ce('Viacoin', 'VIA', 0xff, (0x7f,'t'), (0xc4,'2'), False, 2), ce('Emercoin', 'EMC', 0xef, (0x6f,('m','n')), (0xc4,'2'), False, 2), + ce('Litecoin', 'LTC', 0xef, (0x6f,('m','n')), (0x3a,'Q'), True, 5), # old p2sh: 0xc4 ) coin_sources = ( @@ -650,9 +653,11 @@ class CoinInfo(object): # If 'tool' is not specified, the first tool supporting the coin will be selected. 'pycoin': ( 'DASH', # only compressed + 'BCH', 'BTC','LTC','VIA','FTC','DOGE','MEC', 'JBS','MZC','RIC','DFC','FAI','ARG','ZEC','DCR'), 'keyconv': ( + 'BCH', # broken: PIVX '42','AC','AIB','ANC','ARS','ATMOS','AUR','BLK','BQC','BTC','TEST','BTCD','CCC','CCN','CDN', 'CLAM','CNC','CNOTE','CON','CRW','DEEPONION','DGB','DGC','DMD','DOGED','DOGE','DOPE', @@ -668,6 +673,7 @@ class CoinInfo(object): 'testnet': { 'pycoin': { 'DASH':'tDASH', # only compressed + 'BCH':'XTN', 'BTC':'XTN','LTC':'XLT','VIA':'TVI','FTC':'FTX','DOGE':'XDT','DCR':'DCRT' }, 'ethkey': {}, diff --git a/test/gentest.py b/test/gentest.py index eecf0feb..8ba735e6 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -124,7 +124,11 @@ def get_cmd_output(cmd,input=None): from collections import namedtuple gtr = namedtuple('gen_tool_result',['wif','addr','vk']) -class GenTool(object): pass +class GenTool(object): + + def run_tool(self,sec): + vcoin = 'BTC' if g.coin == 'BCH' else g.coin + return self.run(sec,vcoin) class GenToolEthkey(GenTool): desc = 'ethkey' @@ -133,14 +137,14 @@ class GenToolEthkey(GenTool): global addr_type addr_type = MMGenAddrType('E') - def run(self,sec): + def run(self,sec,vcoin): o = get_cmd_output(['ethkey','info',sec]) return gtr(o[0].split()[1],o[-1].split()[1],None) class GenToolKeyconv(GenTool): desc = 'keyconv' - def run(self,sec): - o = get_cmd_output(['keyconv','-C',g.coin,sec.wif]) + def run(self,sec,vcoin): + o = get_cmd_output(['keyconv','-C',vcoin,sec.wif]) return gtr(o[1].split()[1],o[0].split()[1],None) class GenToolZcash_mini(GenTool): @@ -150,7 +154,7 @@ class GenToolZcash_mini(GenTool): global addr_type addr_type = MMGenAddrType('Z') - def run(self,sec): + def run(self,sec,vcoin): o = get_cmd_output(['zcash-mini','-key','-simple'],input=(sec.wif+'\n').encode()) return gtr(o[1],o[0],o[-1]) @@ -167,9 +171,10 @@ class GenToolPycoin(GenTool): raise ImportError(m) self.nfnc = network_for_netcode - def run(self,sec): - coin = ci.external_tests['testnet']['pycoin'][g.coin] if g.testnet else g.coin - network = self.nfnc(coin) + def run(self,sec,vcoin): + if g.testnet: + vcoin = ci.external_tests['testnet']['pycoin'][vcoin] + network = self.nfnc(vcoin) key = network.keys.private(secret_exponent=int(sec,16),is_compressed=addr_type.name != 'legacy') if key is None: die(1,"can't parse {}".format(sec)) @@ -200,7 +205,7 @@ class GenToolMoneropy(GenTool): global addr_type addr_type = MMGenAddrType('M') - def run(self,sec): + def run(self,sec,vcoin): sk_t,vk_t,addr_t = self.mpa.account_from_spend_key(sec) # VERY slow! return gtr(sk_t,addr_t,vk_t) @@ -269,7 +274,7 @@ def gentool_test(kg_a,kg_b,ag,rounds): a_vk = None tinfo = (in_bytes,sec,sec.wif,kg_a.desc,kg_b.desc) if isinstance(kg_b,GenTool): - b = kg_b.run(sec) + b = kg_b.run_tool(sec) test_equal('WIF keys',sec.wif,b.wif,*tinfo) test_equal('addresses',a_addr,b.addr,*tinfo) if b.vk: