def __init__(self,trunner,cfgs,spawn): TestSuiteBase.__init__(self,trunner,cfgs,spawn) if trunner == None: return from mmgen.protocol import init_proto self.proto = init_proto('XMR',network='testnet') self.datadir_base = os.path.join('test','daemons','xmrtest') self.tool_args = ['--testnet=1', '--monero-wallet-rpc-password=passw0rd'] self.init_users() self.init_daemon_args() for v in self.users.values(): run(['mkdir','-p',v.udir]) self.init_proxy() if not opt.no_daemon_autostart: self.start_daemons() self.start_wallet_daemons() if not opt.no_daemon_stop: atexit.register(self.stop_daemons) atexit.register(self.stop_wallet_daemons) self.balance = None
def verify_core_coin_data(cls, quiet=False, verbose=False): from mmgen.protocol import CoinProtocol, init_proto for network in ('mainnet', 'testnet'): for coin in CoinProtocol.core_coins: e = cls.get_entry(coin, network) if e: proto = init_proto(coin, testnet=network == 'testnet') cdata = (network, coin, e, type(proto).__name__, verbose) if not quiet: msg('Verifying {} {}'.format(coin.upper(), network)) if coin != 'bch': # TODO test_equal('coin name', e.name, proto.name, *cdata) if e.trust_level != -1: test_equal('Trust level', e.trust_level, CoinProtocol.coins[coin].trust_level, *cdata) test_equal( 'WIF version number', e.wif_ver_num, int.from_bytes(bytes.fromhex(proto.wif_ver_num['std']), 'big'), *cdata) test_equal( 'P2PKH version number', e.p2pkh_info[0], int.from_bytes(proto.addr_fmt_to_ver_bytes('p2pkh'), 'big'), *cdata) test_equal( 'P2SH version number', e.p2sh_info[0], int.from_bytes(proto.addr_fmt_to_ver_bytes('p2sh'), 'big'), *cdata)
def __init__(self,trunner,cfgs,spawn): TestSuiteBase.__init__(self,trunner,cfgs,spawn) os.environ['MMGEN_TEST_SUITE_REGTEST'] = '1' if self.proto.testnet: die(2,'--testnet and --regtest options incompatible with regtest test suite') self.proto = init_proto(self.proto.coin,network='regtest') coin = self.proto.coin.lower() for k in rt_data: globals()[k] = rt_data[k][coin] if coin in rt_data[k] else None
def ref_altcoin_tx_chk(self): self.write_to_tmpfile(pwfile, dfl_wpasswd) pf = joinpath(self.tmpdir, pwfile) from mmgen.protocol import init_proto from mmgen.daemon import CoinDaemon for k in ('bch', 'eth', 'mm1', 'etc'): coin, token = ('eth', 'mm1') if k == 'mm1' else (k, None) ref_subdir = self._get_ref_subdir_by_coin(coin) for tn in (False, True): extra_opts = ['--coin=' + coin, f'--testnet={int(tn)}'] if tn and coin == 'etc': continue if coin == 'bch': network_id = get_network_id('bch', tn) start_test_daemons(network_id) extra_opts += [ '--daemon-data-dir=test/daemons/bch', '--rpc-port={}'.format( CoinDaemon(network_id, test_suite=True).rpc_port) ] g.proto = init_proto(coin, testnet=tn) fn = TestSuiteRef.sources['ref_tx_file'][token or coin][bool(tn)] tf = joinpath(ref_dir, ref_subdir, fn) wf = dfl_words_file if token: extra_opts += ['--token=' + token] t = self.txsign(wf, tf, pf, save=False, has_label=True, extra_desc='({}{})'.format( token or coin, ' testnet' if tn else ''), extra_opts=extra_opts) if coin == 'bch': stop_test_daemons(network_id) ok_msg() g.proto = init_proto('btc') t.skip_ok = True return t
def is_for_chain(self,chain): if g.proto.name.startswith('Ethereum'): return True from mmgen.protocol import init_proto proto = init_proto(g.coin,network=chain) if self.addr_fmt == 'bech32': return self[:len(proto.bech32_hrp)] == proto.bech32_hrp else: return bool(proto.parse_addr(self))
def __init__(self): m = "Unable to import moneropy. Is moneropy installed on your system?" try: import moneropy.account except: raise ImportError(m) self.mpa = moneropy.account proto = init_proto('xmr') global addr_type addr_type = MMGenAddrType(proto, 'M')
async def test_mmgen_txs(): fns = ( ('btc',False,'test/ref/0B8D5A[15.31789,14,tl=1320969600].rawtx'), ('btc',True,'test/ref/0C7115[15.86255,14,tl=1320969600].testnet.rawtx'), # ('bch',False,'test/ref/460D4D-BCH[10.19764,tl=1320969600].rawtx') ) print_info('test/ref/*rawtx','MMGen reference transactions') g.rpc_port = None for n,(coin,testnet,fn) in enumerate(fns): g.proto = init_proto(coin,testnet=testnet) g.proto.daemon_data_dir = 'test/daemons/' + coin g.proto.rpc_port = CoinDaemon(coin + ('','_tn')[testnet],test_suite=True).rpc_port await rpc_init() await test_tx(MMGenTX(fn).hex,fn,n+1) Msg('OK')
def eth(self, name, ut): ed = CoinDaemon('eth', test_suite=True) ed.start() g.rpc_port = CoinDaemon('eth', test_suite=True).rpc_port async def run_test(): qmsg(' Testing backend {!r}'.format(type(g.rpc.backend).__name__)) ret = await g.rpc.call('parity_versionInfo', timeout=300) for backend in g.autoset_opts['rpc_backend'].choices: run_session(run_test(), proto=init_proto('eth'), backend=backend) ed.stop() return True
def get_addr_from_addrlist(self, user, sid, mmtype, idx, addr_range='1-5'): id_str = {'L': '', 'S': '-S', 'C': '-C', 'B': '-B'}[mmtype] ext = '{}{}{}[{}]{x}.testnet.addrs'.format( sid, self.altcoin_pfx, id_str, addr_range, x='-α' if g.debug_utf8 else '') addrfile = get_file_with_ext(self._user_dir(user), ext, no_dot=True) psave = g.proto g.proto = init_proto(g.coin, regtest=True) silence() addr = AddrList(addrfile).data[idx].addr end_silence() g.proto = psave return addr
def run_test(coin, auth): proto = init_proto(coin, network=('mainnet', 'regtest')[ coin == 'eth']) # FIXME CoinDaemon's network handling broken d = CoinDaemon(network_id=coin, test_suite=True) d.stop() d.remove_datadir() d.start() for backend in g.autoset_opts['rpc_backend'].choices: run_session(getattr(init_test, coin)(proto, backend), backend=backend) d.stop() if auth: auth_test(proto, d) qmsg(' OK') return True
def __new__(cls, network_id, test_suite=False, flags=None): network_id = network_id.lower() assert network_id in cls.network_ids, '{!r}: invalid network ID'.format( network_id) if network_id.endswith('_rt'): network = 'regtest' daemon_id = network_id[:-3] elif network_id.endswith('_tn'): network = 'testnet' daemon_id = network_id[:-3] else: network = 'mainnet' daemon_id = network_id me = Daemon.__new__(globals()[cls.daemon_ids[daemon_id].cls_pfx + 'Daemon']) me.network_id = network_id me.network = network me.daemon_id = daemon_id me.desc = 'daemon' if network == 'regtest': me.desc = 'regtest daemon' if test_suite: rel_datadir = os.path.join( 'test', 'data_dir{}'.format('-α' if g.debug_utf8 else ''), 'regtest', daemon_id) else: me.datadir = os.path.join(g.data_dir_root, 'regtest', daemon_id) elif test_suite: me.desc = 'test suite daemon' rel_datadir = os.path.join('test', 'daemons', daemon_id) else: from .protocol import init_proto me.datadir = init_proto(daemon_id, False).daemon_data_dir if test_suite: me.datadir = os.path.abspath(os.path.join(os.getcwd(), rel_datadir)) me.port_shift = 1237 if test_suite else 0 me.platform = g.platform return me
async def test_core_vectors(): self._get_core_repo_root() fn_b = 'src/test/data/tx_valid.json' fn = os.path.join(self.core_repo_root, fn_b) data = json.loads(open(fn).read()) print_info(fn_b, 'Core test vector') n = 1 for e in data: if type(e[0]) == list: await test_tx(tx_proto=init_proto('btc'), tx_hex=e[1], desc=desc, n=n) n += 1 else: desc = e[0] Msg('OK')
def state(self): return 'ready' if self.test_socket('localhost', self.rpc_port) else 'stopped' # the following code does not work async def do(): print(g.rpc) ret = await g.rpc.call('eth_chainId') print(ret) return ('stopped', 'ready')[ret == '0x11'] from mmgen.protocol import init_proto try: return run_session( do(), proto=init_proto('eth')) # socket exception is not propagated except: # SocketError: return 'stopped'
def addrimport(self, user, sid=None, addr_range='1-5', num_addrs=5, mmtypes=[]): id_strs = { 'legacy': '', 'compressed': '-C', 'segwit': '-S', 'bech32': '-B' } if not sid: sid = self._user_sid(user) from mmgen.addr import MMGenAddrType for mmtype in mmtypes or g.proto.mmtypes: desc = MMGenAddrType.mmtypes[mmtype].name addrfile = joinpath( self._user_dir(user), '{}{}{}[{}]{x}.testnet.addrs'.format( sid, self.altcoin_pfx, id_strs[desc], addr_range, x='-α' if g.debug_utf8 else '')) if mmtype == g.proto.mmtypes[0] and user == 'bob': psave = g.proto g.proto = init_proto(g.coin, regtest=True) self._add_comments_to_addr_file(addrfile, addrfile, use_labels=True) g.proto = psave t = self.spawn('mmgen-addrimport', ['--quiet', '--' + user, '--batch', addrfile], extra_desc='({})'.format(desc)) if g.debug: t.expect("Type uppercase 'YES' to confirm: ", 'YES\n') t.expect('Importing') t.expect('{} addresses imported'.format(num_addrs)) ok_msg() t.skip_ok = True return t
#!/usr/bin/env python3 # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C)2013-2021 The MMGen Project <*****@*****.**> """ test.objtest_py_d.ot_ltc_mainnet: LTC mainnet test vectors for MMGen data objects """ from mmgen.obj import * from .ot_common import * from mmgen.protocol import init_proto proto = init_proto('ltc') tests = { 'LTCAmt': { 'bad': ('-3.2', '0.123456789', 123, '123L', '88000000', 80999999.12345678), 'good': (('80999999.12345678', Decimal('80999999.12345678')), ) }, 'CoinAddr': { 'bad': ( { 'addr': 1, 'proto': proto }, { 'addr': 'x', 'proto': proto }, {
def alice_add_label_badaddr2(self): addr = init_proto(self.proto.coin,network='mainnet').pubhash2addr('00'*20,False) # mainnet zero address return self.alice_add_label_badaddr( addr, f'Invalid coin address for this chain: {addr}' )
def __init__(self, trunner, cfgs, spawn): TestSuiteBase.__init__(self, trunner, cfgs, spawn) from mmgen.protocol import init_proto self.proto = init_proto(g.coin, network='regtest') from mmgen.daemon import CoinDaemon self.rpc_port = CoinDaemon(proto=self.proto, test_suite=True).rpc_port
def __init__(self): proto = init_proto('zec') global addr_type addr_type = MMGenAddrType(proto, 'Z')
def __init__(self): proto = init_proto('eth') global addr_type addr_type = MMGenAddrType(proto, 'E')
if not opt.all: ag = AddrGenerator(proto, addr_type) if not b and type(arg2) == int: speed_test(a, ag, arg2) elif not b and hasattr(arg2, 'read'): dump_test(a, ag, arg2) elif a and b and type(arg2) == int: if opt.all: from mmgen.protocol import CoinProtocol, init_genonly_altcoins init_genonly_altcoins(testnet=proto.testnet) for coin in ci.external_tests[proto.network][b.desc]: if coin.lower() not in CoinProtocol.coins: # ymsg('Coin {} not configured'.format(coin)) continue proto = init_proto(coin) if addr_type not in proto.mmtypes: continue # proto has changed, so reinit kg and ag a = KeyGenerator(proto, addr_type, a_num) ag = AddrGenerator(proto, addr_type) b_chk = ci.get_test_support(proto.coin, addr_type.name, proto.network, tool=b.desc, verbose=not opt.quiet) if b_chk == b.desc: gentool_test(a, b, ag, arg2) else: gentool_test(a, b, ag, arg2) else:
#!/usr/bin/env python3 # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C)2013-2021 The MMGen Project <*****@*****.**> """ test.objtest_py_d.ot_btc_testnet: BTC testnet test vectors for MMGen data objects """ from mmgen.obj import * from .ot_common import * from mmgen.protocol import init_proto proto = init_proto('btc',network='testnet') tests = { 'CoinAddr': { 'bad': ( {'addr':1, 'proto':proto}, {'addr':'x', 'proto':proto}, {'addr':'я', 'proto':proto}, ), 'good': ( {'addr':'n2FgXPKwuFkCXF946EnoxWJDWF2VwQ6q8J', 'proto':proto}, {'addr':'2MspvWFjBbkv2wzQGqhxJUYPCk3Y2jMaxLN','proto':proto}, ), }, 'WifKey': { 'bad': ( {'proto':proto, 'wif':1}, {'proto':proto, 'wif':[]},
#!/usr/bin/env python3 # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C)2013-2021 The MMGen Project <*****@*****.**> """ test.objtest_py_d.ot_btc_mainnet: BTC mainnet test vectors for MMGen data objects """ from mmgen.obj import * from mmgen.seed import * from .ot_common import * from mmgen.protocol import init_proto proto = init_proto('btc') tw_pfx = proto.base_coin.lower() + ':' ssm = str(SeedShareCount.max_val) privkey = PrivKey(proto=proto,s=bytes.fromhex('deadbeef'*8),compressed=True,pubkey_type='std') tests = { 'Int': { 'arg1': 'n', '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, {'n':'0x0','base':16,'ret':0}, {'n':'0x1','base':16,'ret':1}, {'n':'0xf','base':16,'ret':15}, {'n':'0xff','base':16,'ret':255}, )
""" } } cmd_args = opts.init(opts_data) if g.coin != 'BTC': die(1, "This program must be run with --coin set to 'BTC'") if len(cmd_args) != 1: opts.usage() import mmgen.tx tx = mmgen.tx.MMGenTX(cmd_args[0]) if opt.verbose: gmsg('Original transaction is in {} format'.format(g.coin)) from mmgen.protocol import init_proto g.proto = init_proto('bch') if opt.verbose: gmsg('Converting transaction to {} format'.format(g.coin)) tx.inputs.convert_coin(verbose=opt.verbose) tx.outputs.convert_coin(verbose=opt.verbose) tx.desc = 'converted transaction' tx.write_to_file(ask_write=False, ask_overwrite=False)
def alice_add_label_badaddr4(self): addr = init_proto(g.coin, regtest=True).pubhash2addr( '00' * 20, False) # testnet zero address return self.alice_add_label_badaddr( addr, "Address '{}' not found in tracking wallet".format(addr))