minor changes and fixes

This commit is contained in:
The MMGen Project 2020-02-15 14:11:30 +00:00
commit e1f7a50ba4
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 34 additions and 22 deletions

View file

@ -102,6 +102,7 @@ class baseconv(object):
for k,v in list(cls.wl_chksums.items()):
res = cls.get_wordlist_chksum(k)
assert res == v,'{}: checksum mismatch for {} (should be {})'.format(res,k,v)
return True
@classmethod
def check_wordlist(cls,wl_id):
@ -109,13 +110,16 @@ class baseconv(object):
wl = cls.digits[wl_id]
from mmgen.util import qmsg,compare_chksums
qmsg('Wordlist: {}\nLength: {} words'.format(wl_id,len(wl)))
ret = 'Wordlist: {}\nLength: {} words'.format(wl_id,len(wl))
new_chksum = cls.get_wordlist_chksum(wl_id)
a,b = 'generated','saved'
compare_chksums(new_chksum,a,cls.wl_chksums[wl_id],b,die_on_fail=True)
qmsg('List is sorted') if tuple(sorted(wl)) == wl else die(3,'ERROR: List is not sorted!')
if tuple(sorted(wl)) == wl:
return ret + '\nList is sorted'
else:
die(3,'ERROR: List is not sorted!')
@classmethod
def get_pad(cls,pad,seed_pad_func):

View file

@ -464,12 +464,13 @@ class CoinProtocol(MMGenObject):
coin = coin.lower()
assert type(testnet) == bool
m = "{}: not a valid coin for network {}\nSupported coins: {}"
assert coin in cls.coins, m.format(coin.upper(),g.network.upper(),cls.list_coins())
return cls.coins[coin][testnet]
assert coin in cls.coins, m.format(coin.upper(),g.network.upper(),' '.join(cls.list_coins()))
proto = cls.coins[coin][testnet]
return proto
@classmethod
def list_coins(cls):
return ' '.join(c.upper() for c in cls.coins)
return [c.upper() for c in cls.coins]
@classmethod
def get_base_coin_from_name(cls,name):
@ -557,6 +558,8 @@ def make_init_genonly_altcoins_str(data):
def init_coin(coin,testnet=None):
if testnet is not None:
g.testnet = testnet
g.network = ('mainnet','testnet')[g.testnet]
coin = coin.upper()
g.coin = coin
g.proto = CoinProtocol(coin,g.testnet)
return g.proto

View file

@ -527,7 +527,6 @@ class MMGenToolCmdMnemonic(MMGenToolCmdBase):
def hex2mn( self, hexstr:'sstr', fmt:mn_opts_disp = dfl_mnemonic_fmt ):
"convert a 16, 24 or 32-byte hexadecimal number to a mnemonic seed phrase"
opt.out_fmt = self._get_mnemonic_fmt(fmt)
if fmt == 'bip39':
from mmgen.bip39 import bip39
return ' '.join(bip39.fromhex(hexstr,fmt))
@ -539,7 +538,6 @@ class MMGenToolCmdMnemonic(MMGenToolCmdBase):
def mn2hex( self, seed_mnemonic:'sstr', fmt:mn_opts_disp = dfl_mnemonic_fmt ):
"convert a 12, 18 or 24-word mnemonic seed phrase to a hexadecimal number"
in_fmt = self._get_mnemonic_fmt(fmt)
if fmt == 'bip39':
from mmgen.bip39 import bip39
return bip39.tohex(seed_mnemonic.split(),fmt)
@ -549,8 +547,7 @@ class MMGenToolCmdMnemonic(MMGenToolCmdBase):
def mn_stats(self, fmt:mn_opts_disp = dfl_mnemonic_fmt ):
"show stats for mnemonic wordlist"
conv_cls = mnemonic_fmts[fmt]['conv_cls']()
conv_cls.check_wordlist(fmt)
return True
return conv_cls.check_wordlist(fmt)
def mn_printlist( self, fmt:mn_opts_disp = dfl_mnemonic_fmt, enum=False, pager=False ):
"print mnemonic wordlist"
@ -896,12 +893,12 @@ class MMGenToolCmdRPC(MMGenToolCmdBase):
class MMGenToolCmdMonero(MMGenToolCmdBase):
"Monero wallet utilities"
_chain_height = None
_monero_chain_height = None
monerod_args = []
@property
def chain_height(self):
if self._chain_height == None:
def monero_chain_height(self):
if self._monero_chain_height == None:
from mmgen.daemon import CoinDaemon
port = CoinDaemon('xmr',test_suite=g.test_suite).rpc_port
cmd = ['monerod','--rpc-bind-port={}'.format(port)] + self.monerod_args + ['status']
@ -912,10 +909,10 @@ class MMGenToolCmdMonero(MMGenToolCmdBase):
m = re.search(r'Height: (\d+)/\d+ ',cp.stdout.decode())
if not m:
die(1,'Unable to connect to monerod!')
self._chain_height = int(m.group(1))
msg('Chain height: {}'.format(self._chain_height))
self._monero_chain_height = int(m.group(1))
msg('Chain height: {}'.format(self._monero_chain_height))
return self._chain_height
return self._monero_chain_height
def keyaddrlist2monerowallets( self,
xmr_keyaddrfile:str,
@ -962,7 +959,7 @@ class MMGenToolCmdMonero(MMGenToolCmdBase):
ymsg("Wallet '{}' does not exist!".format(fn))
return False
chain_height = self.chain_height
chain_height = self.monero_chain_height
gmsg(m)
import time

View file

@ -305,14 +305,17 @@ t_alts="
f_alts='Gen-only altcoin tests completed'
[ "$NO_TMPFILE_REMOVAL" ] || rm -rf /tmp/mmgen-test-release*
if [ "$MSYS2" ]; then
TMPDIR='/tmp/mmgen-test-release'
if [ "$NO_TMPFILE_REMOVAL" ]; then
TMPDIR=$(echo /tmp/mmgen-test-release*)
else
TMPDIR='/tmp/mmgen-test-release-'$(cat /dev/urandom | base32 - | head -n1 | cut -b 1-16)
rm -rf /tmp/mmgen-test-release*
if [ "$MSYS2" ]; then
TMPDIR='/tmp/mmgen-test-release'
else
TMPDIR='/tmp/mmgen-test-release-'$(cat /dev/urandom | base32 - | head -n1 | cut -b 1-16)
fi
mkdir -p $TMPDIR
fi
mkdir -p $TMPDIR
i_xmr='Monero'
s_xmr='Testing key-address file generation and wallet creation and sync operations for Monero'
@ -439,6 +442,11 @@ f_ltc_rt='Regtest (Bob and Alice) mode tests for LTC completed'
i_tool2='Tooltest2'
s_tool2="The following tests will run '$tooltest2_py' for all supported coins"
t_tool2="
$tooltest2_py --tool-api # test the tool_api subsystem
$tooltest2_py --tool-api --testnet=1
$tooltest2_py --tool-api --coin=eth
$tooltest2_py --tool-api --coin=xmr
$tooltest2_py --tool-api --coin=zec
$tooltest2_py --fork # run once with --fork so commands are actually executed
$tooltest2_py
$tooltest2_py --testnet=1