pylint: test suite, examples
This commit is contained in:
parent
790a22d271
commit
3b4e9ebc1e
25 changed files with 60 additions and 74 deletions
|
|
@ -31,7 +31,7 @@ m = MasterNode(cfg, seed)
|
|||
dfl_pub_chain = m.to_chain(idx=0, coin='ltc', addr_type='bech32')
|
||||
dfl_chg_chain = m.to_chain(idx=1, coin='ltc', addr_type='bech32')
|
||||
|
||||
print(f'Default path (LTC, bech32):\n')
|
||||
print('Default path (LTC, bech32):\n')
|
||||
print(f' public chain xpub:\n {dfl_pub_chain.xpub}\n')
|
||||
print(f' internal chain xpub:\n {dfl_chg_chain.xpub}\n')
|
||||
print(f' public chain addr 0:\n {dfl_pub_chain.derive_public(0).address}\n')
|
||||
|
|
@ -77,7 +77,7 @@ nonstd_path = BipHDNode.from_path(
|
|||
addr_type = 'E',
|
||||
no_path_checks = True)
|
||||
|
||||
print(f'Non-standard path (ETH):\n')
|
||||
print('Non-standard path (ETH):\n')
|
||||
print(f' xpub:\n {nonstd_path.xpub}\n')
|
||||
print(f' WIF key:\n {nonstd_path.privkey.wif}\n')
|
||||
print(f' address:\n {nonstd_path.address}\n')
|
||||
|
|
|
|||
|
|
@ -338,14 +338,12 @@ class CmdGroupMgr:
|
|||
|
||||
if add_deps:
|
||||
for dep in cmd_group_in['subgroup.'+key]:
|
||||
for e in add_entries(dep):
|
||||
yield e
|
||||
yield from add_entries(dep)
|
||||
|
||||
assert isinstance(cls.cmd_subgroups[key][0],str), f'header for subgroup {key!r} missing!'
|
||||
|
||||
if not key in added_subgroups:
|
||||
for e in cls.cmd_subgroups[key][1:]:
|
||||
yield e
|
||||
yield from cls.cmd_subgroups[key][1:]
|
||||
added_subgroups.append(key)
|
||||
|
||||
def gen():
|
||||
|
|
@ -353,11 +351,10 @@ class CmdGroupMgr:
|
|||
if name.startswith('subgroup.'):
|
||||
sg_key = name.removeprefix('subgroup.')
|
||||
if sg_name in (None,sg_key):
|
||||
for e in add_entries(
|
||||
yield from add_entries(
|
||||
sg_key,
|
||||
add_deps = sg_name and not cfg.skipping_deps,
|
||||
added_subgroups = [sg_name] if cfg.deps_only else [] ):
|
||||
yield e
|
||||
added_subgroups = [sg_name] if cfg.deps_only else [])
|
||||
if cfg.deps_only and sg_key == sg_name:
|
||||
return
|
||||
elif not cfg.skipping_deps:
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
"""
|
||||
test.cmdtest_py_d.ct_automount: autosigning with automount tests for the cmdtest.py test suite
|
||||
"""
|
||||
import os, time
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from .ct_autosign import CmdTestAutosignThreaded
|
||||
|
|
@ -78,7 +78,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet)
|
|||
CmdTestAutosignThreaded.__init__(self, trunner, cfgs, spawn)
|
||||
CmdTestRegtestBDBWallet.__init__(self, trunner, cfgs, spawn)
|
||||
|
||||
if trunner == None:
|
||||
if trunner is None:
|
||||
return
|
||||
|
||||
self.opts.append('--alice')
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ from subprocess import run,DEVNULL
|
|||
from pathlib import Path
|
||||
|
||||
from mmgen.cfg import Config
|
||||
from mmgen.color import red,green,blue,yellow,cyan,orange,purple,gray
|
||||
from mmgen.util import msg,suf,die,indent,fmt
|
||||
from mmgen.color import red, blue, yellow, cyan, orange, purple, gray
|
||||
from mmgen.util import msg, suf, die, indent, fmt
|
||||
from mmgen.led import LEDControl
|
||||
from mmgen.autosign import Autosign, Signable
|
||||
|
||||
|
|
@ -924,7 +924,7 @@ class CmdTestAutosignLive(CmdTestAutosignBTC):
|
|||
return
|
||||
|
||||
try:
|
||||
cf = LEDControl(enabled=True,simulate=self.simulate_led)
|
||||
LEDControl(enabled=True,simulate=self.simulate_led)
|
||||
except Exception as e:
|
||||
msg(str(e))
|
||||
die(2,'LEDControl initialization failed')
|
||||
|
|
|
|||
|
|
@ -98,8 +98,8 @@ class CmdTestChainsplit(CmdTestRegtest):
|
|||
t.expect(r'\[q\]uit menu, .*?:.','q', regex=True)
|
||||
t.expect('outputs to spend: ','1\n')
|
||||
|
||||
for tx in ('timelocked','split'):
|
||||
for q in ('fee','change'):
|
||||
for _ in ('timelocked', 'split'):
|
||||
for _ in ('fee', 'change'):
|
||||
t.expect('OK? (Y/n): ','y')
|
||||
t.do_comment(False)
|
||||
t.view_tx('t')
|
||||
|
|
|
|||
|
|
@ -394,7 +394,6 @@ class CmdTestRef3Addr(CmdTestRef3Seed):
|
|||
|
||||
def pwgen(self,ftype,id_str,pwfmt=None,pwlen=None,extra_args=[],stdout=False):
|
||||
wf = self.get_file_with_ext('mmdat')
|
||||
pf = joinpath(self.tmpdir,pwfile)
|
||||
pwfmt = (['--passwd-fmt='+pwfmt] if pwfmt else [])
|
||||
pwlen = (['--passwd-len='+str(pwlen)] if pwlen else [])
|
||||
return self.addrgen(
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
test.cmdtest_py_d.ct_regtest: Regtest tests for the cmdtest.py test suite
|
||||
"""
|
||||
|
||||
import sys,os,json,time,re
|
||||
import os, json, time, re
|
||||
from decimal import Decimal
|
||||
|
||||
from mmgen.proto.btc.regtest import MMGenRegtest
|
||||
|
|
@ -465,7 +465,7 @@ class CmdTestRegtest(CmdTestBase,CmdTestShared):
|
|||
|
||||
CmdTestBase.__init__(self,trunner,cfgs,spawn)
|
||||
|
||||
if trunner == None:
|
||||
if trunner is None:
|
||||
return
|
||||
|
||||
if self.proto.testnet:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import sys, os
|
|||
from mmgen.util import msg,capfirst,get_extension
|
||||
from mmgen.wallet import get_wallet_cls
|
||||
|
||||
from ..include.common import cfg, joinpath, imsg, VirtBlockDevice
|
||||
from ..include.common import cfg, joinpath, VirtBlockDevice
|
||||
from .common import ref_dir,ref_wallet_brainpass,ref_wallet_incog_offset,hincog_fn,hincog_bytes
|
||||
from .ct_base import CmdTestBase
|
||||
from .ct_shared import CmdTestShared
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@
|
|||
test.cmdtest_py_d.ct_xmr_autosign: xmr autosigning tests for the cmdtest.py test suite
|
||||
"""
|
||||
|
||||
import os,time,re,shutil
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
from mmgen.color import purple,gray,blue,cyan,brown
|
||||
from mmgen.util import fmt,async_run
|
||||
from mmgen.color import blue, cyan, brown
|
||||
from mmgen.util import async_run
|
||||
|
||||
from ..include.common import cfg,imsg,silence,end_silence
|
||||
from ..include.common import cfg, imsg, silence, end_silence
|
||||
from .common import get_file_with_ext
|
||||
|
||||
from .ct_xmrwallet import CmdTestXMRWallet
|
||||
|
|
@ -435,7 +434,7 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignThreaded):
|
|||
return t
|
||||
|
||||
def txview_all(self):
|
||||
t = self.spawn('', msg_only=True)
|
||||
self.spawn('', msg_only=True)
|
||||
self.insert_device()
|
||||
self.do_mount()
|
||||
imsg(blue('Opening transaction directory: ') + cyan(f'{self.asi.xmr_tx_dir}'))
|
||||
|
|
|
|||
|
|
@ -725,8 +725,7 @@ class CmdTestXMRWallet(CmdTestBase):
|
|||
await self.start_mining()
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
die(2,'Restart attempt limit exceeded')
|
||||
die(2,'Restart attempt limit exceeded')
|
||||
|
||||
async def mine10(self):
|
||||
return await self.mine(10)
|
||||
|
|
@ -771,8 +770,7 @@ class CmdTestXMRWallet(CmdTestBase):
|
|||
omsg('Daemon busy. Attempting to start mining...')
|
||||
else:
|
||||
die(2,f'Monerod returned status {status}')
|
||||
else:
|
||||
die(2,'Max retries exceeded')
|
||||
die(2,'Max retries exceeded')
|
||||
|
||||
async def stop_mining(self):
|
||||
ret = self.users['miner'].md_rpc.call_raw('stop_mining')
|
||||
|
|
|
|||
|
|
@ -319,8 +319,7 @@ def do_ab_test(proto,scfg,addr_type,gen1,kg2,ag,tool,cache_data):
|
|||
|
||||
def get_randbytes():
|
||||
if tool and len(tool.data) > len(edgecase_sks):
|
||||
for privbytes in tuple(tool.data)[len(edgecase_sks):]:
|
||||
yield privbytes
|
||||
yield from tuple(tool.data)[len(edgecase_sks):]
|
||||
else:
|
||||
for _ in range(scfg.rounds):
|
||||
yield getrand(32)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ test.include.common: Shared routines and data for the MMGen test suites
|
|||
"""
|
||||
|
||||
import sys, os, re, atexit
|
||||
from subprocess import run,PIPE
|
||||
from subprocess import run, PIPE, DEVNULL
|
||||
from pathlib import Path
|
||||
|
||||
from mmgen.cfg import gv
|
||||
|
|
@ -57,7 +57,6 @@ def set_globals(cfg):
|
|||
this.dmsg = msg if cfg.debug else noop
|
||||
|
||||
def strip_ansi_escapes(s):
|
||||
import re
|
||||
return re.sub('\x1b' + r'\[[;0-9]+?m','',s)
|
||||
|
||||
cmdtest_py_log_fn = 'cmdtest.py.log'
|
||||
|
|
@ -330,11 +329,9 @@ def get_ethkey():
|
|||
pass
|
||||
else:
|
||||
return cmdname
|
||||
else:
|
||||
die(1,f'ethkey executable not found (tried {cmdnames})')
|
||||
die(1,f'ethkey executable not found (tried {cmdnames})')
|
||||
|
||||
def do_run(cmd, check=True):
|
||||
from subprocess import run,PIPE,DEVNULL
|
||||
return run(cmd, stdout=PIPE, stderr=DEVNULL, check=check)
|
||||
|
||||
def VirtBlockDevice(img_path, size):
|
||||
|
|
|
|||
|
|
@ -197,8 +197,8 @@ def do_loop():
|
|||
if cfg.getobj and arg1 is None:
|
||||
msg(gray(f'{nl}Skipping {test}'))
|
||||
continue
|
||||
else:
|
||||
msg(clr(f'{nl}Testing {test}'))
|
||||
|
||||
msg(clr(f'{nl}Testing {test}'))
|
||||
|
||||
for k in ('bad','good'):
|
||||
if not cfg.super_silent:
|
||||
|
|
|
|||
|
|
@ -214,8 +214,7 @@ def run_test(cls, gid, cmd_name):
|
|||
qmsg(('' if n else '\n') + gray(skip_msg if len(skip_msg) <= 100 else skip_msg[:97] + '...'))
|
||||
skipping = True
|
||||
continue
|
||||
else:
|
||||
skipping = False
|
||||
skipping = False
|
||||
stdin_input = None
|
||||
if args and isinstance(args[0],bytes):
|
||||
stdin_input = args[0]
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ if not os.getenv('MMGEN_DEVTOOLS'):
|
|||
init_dev()
|
||||
|
||||
from mmgen.cfg import Config,gc
|
||||
from mmgen.color import green, gray, brown, orange, yellow, red
|
||||
from mmgen.color import gray, brown, orange, yellow, red
|
||||
from mmgen.util import msg,gmsg,ymsg,Msg
|
||||
|
||||
from test.include.common import set_globals,end_msg
|
||||
|
|
@ -195,21 +195,21 @@ def run_test(test,subtest=None):
|
|||
)
|
||||
if hasattr(t,'_pre'):
|
||||
t._pre()
|
||||
for subtest in subtests:
|
||||
subtest_disp = subtest.replace('_','-')
|
||||
if cfg.no_altcoin_deps and subtest in altcoin_deps:
|
||||
for _subtest in subtests:
|
||||
subtest_disp = _subtest.replace('_','-')
|
||||
if cfg.no_altcoin_deps and _subtest in altcoin_deps:
|
||||
cfg._util.qmsg(gray(f'Skipping unit subtest {subtest_disp!r} [--no-altcoin-deps]'))
|
||||
continue
|
||||
if sys.platform == 'win32' and subtest in win_skip:
|
||||
if sys.platform == 'win32' and _subtest in win_skip:
|
||||
cfg._util.qmsg(gray(f'Skipping unit subtest {subtest_disp!r} for Windows platform'))
|
||||
continue
|
||||
elif sys.platform == 'darwin' and subtest in mac_skip:
|
||||
if sys.platform == 'darwin' and _subtest in mac_skip:
|
||||
cfg._util.qmsg(gray(f'Skipping unit subtest {subtest_disp!r} for macOS platform'))
|
||||
continue
|
||||
elif platform.machine() == 'aarch64' and subtest in arm_skip:
|
||||
if platform.machine() == 'aarch64' and _subtest in arm_skip:
|
||||
cfg._util.qmsg(gray(f'Skipping unit subtest {subtest_disp!r} for ARM platform'))
|
||||
continue
|
||||
run_subtest(t,subtest)
|
||||
run_subtest(t, _subtest)
|
||||
if hasattr(t,'_post'):
|
||||
t._post()
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@
|
|||
test/unit_tests_d/ut_bip39: BIP39 unit test for the MMGen suite
|
||||
"""
|
||||
|
||||
from mmgen.util import msg,msg_r
|
||||
from mmgen.color import blue,orange,purple
|
||||
from mmgen.color import blue, orange, purple
|
||||
from mmgen.bip39 import bip39
|
||||
|
||||
from ..include.common import cfg,qmsg,vmsg,vmsg_r
|
||||
from ..include.common import cfg, qmsg, vmsg
|
||||
|
||||
class unit_tests:
|
||||
|
||||
|
|
|
|||
|
|
@ -287,10 +287,9 @@ class unit_tests:
|
|||
vmsg('Parsing and validating extended keys:\n')
|
||||
|
||||
for vec in vectors_bip32:
|
||||
seed = bytes.fromhex(vec['seed'])
|
||||
vmsg(f' Seed: {vec["seed"]}')
|
||||
|
||||
for n,path_str in enumerate(vec):
|
||||
for path_str in vec:
|
||||
if path_str in ('seed','comment'):
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ test.unit_tests_d.ut_dep: dependency unit tests for the MMGen suite
|
|||
No data verification is performed.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from subprocess import run,PIPE
|
||||
|
||||
from mmgen.util import msg,rmsg,ymsg,gmsg
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ def main():
|
|||
c = 3
|
||||
""".lstrip()
|
||||
|
||||
jsonA = open('test/ref/ethereum/tracking-wallet-v1.json').read()
|
||||
with open('test/ref/ethereum/tracking-wallet-v1.json') as fh:
|
||||
jsonA = fh.read()
|
||||
dataB = json.loads(jsonA)
|
||||
dataB['coin'] = 'ETC'
|
||||
jsonB = json.dumps(dataB)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
test.unit_tests_d.ut_ecc: elliptic curve unit test for the MMGen suite
|
||||
"""
|
||||
|
||||
from mmgen.color import gray,pink,blue
|
||||
from mmgen.proto.secp256k1.secp256k1 import pubkey_gen,pubkey_tweak_add,pubkey_check
|
||||
|
||||
from ..include.common import cfg,qmsg,vmsg
|
||||
from ..include.common import vmsg
|
||||
from ..include.ecc import pubkey_tweak_add_pyecdsa
|
||||
from mmgen.protocol import CoinProtocol
|
||||
|
||||
|
|
@ -16,7 +15,7 @@ secp256k1_group_order = CoinProtocol.Secp256k1.secp256k1_group_order
|
|||
class unit_tests:
|
||||
|
||||
def pubkey_ops(self,name,ut):
|
||||
vmsg(f' Generating pubkey, adding scalar 123456789 to pubkey:')
|
||||
vmsg(' Generating pubkey, adding scalar 123456789 to pubkey:')
|
||||
pk_addend_bytes = int.to_bytes(123456789,length=32,byteorder='big')
|
||||
|
||||
for privkey in (
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ class unit_test:
|
|||
arg = [('a',1),('b',2)]
|
||||
dict(arg)
|
||||
|
||||
for i in range(6):
|
||||
for n, func in enumerate([bad0, bad1, bad2, bad3, bad4, bad5]):
|
||||
try:
|
||||
locals()['bad'+str(i)]()
|
||||
func()
|
||||
except NotImplementedError as e:
|
||||
omsg(e)
|
||||
else:
|
||||
odie(i)
|
||||
odie(n)
|
||||
|
||||
try:
|
||||
d.key(2)
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class unit_test:
|
|||
|
||||
lcdn = MyLockableAutolockDflNone()
|
||||
assert lcdn.foo == 0
|
||||
assert lcdn.bar == None
|
||||
assert lcdn.bar is None
|
||||
|
||||
class MyLockableBad(Lockable):
|
||||
_set_ok = ('foo','bar')
|
||||
|
|
@ -148,7 +148,7 @@ class unit_test:
|
|||
def bad15(): lc.epsilon = [0]
|
||||
|
||||
def bad16(): lca.foo = None
|
||||
def bad17(): lb = MyLockableBad()
|
||||
def bad17(): MyLockableBad()
|
||||
def bad18(): aca._lock()
|
||||
|
||||
def bad19(): acdn.baz = None
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class unit_tests:
|
|||
vmsg(f' {k}')
|
||||
if k in vectors:
|
||||
vmsg(f' pat: {v.pat}')
|
||||
vmsg(f' vectors:')
|
||||
vmsg( ' vectors:')
|
||||
for vec in vectors[k]:
|
||||
m = re.match(v.pat, vec.text)
|
||||
vmsg(f' {vec.text:10} ==> {m.groups()}')
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
test.unit_tests_d.ut_rpc: RPC unit test for the MMGen suite
|
||||
"""
|
||||
|
||||
import sys,os,time
|
||||
import sys, os
|
||||
|
||||
from mmgen.cfg import Config
|
||||
from mmgen.color import yellow,cyan
|
||||
|
|
@ -174,7 +174,8 @@ class unit_tests:
|
|||
return await run_test(['bch','bch_tn'], test_cf_auth=True)
|
||||
|
||||
async def geth(self, name, ut):
|
||||
return await run_test(['eth_tn','eth_rt'], daemon_ids=['geth']) # mainnet returns EIP-155 error on empty blockchain
|
||||
# mainnet returns EIP-155 error on empty blockchain:
|
||||
return await run_test(['eth_tn','eth_rt'], daemon_ids=['geth'])
|
||||
|
||||
async def erigon(self, name, ut):
|
||||
return await run_test(['eth','eth_tn','eth_rt'], daemon_ids=['erigon'])
|
||||
|
|
|
|||
|
|
@ -35,15 +35,15 @@ class unit_tests:
|
|||
|
||||
col1_w = max(len(str(e)) for e in list(chks.values())[0]) + 1
|
||||
|
||||
for name,sample in samples.items():
|
||||
for _name, sample in samples.items():
|
||||
vmsg(cyan(f'Input: {sample}'))
|
||||
for fmt in list(chks.values())[0]:
|
||||
spc = '\n' if fmt in ('col','list') else ' '
|
||||
indent = ' + ' if fmt == 'col' else ''
|
||||
res = fmt_list(sample,fmt=fmt,indent=indent) if fmt else fmt_list(sample,indent=indent)
|
||||
vmsg(f' {str(fmt)+":":{col1_w}}{spc}{res}')
|
||||
if name in chks:
|
||||
assert res == chks[name][fmt], f'{res} != {chks[name][fmt]}'
|
||||
if _name in chks:
|
||||
assert res == chks[_name][fmt], f'{res} != {chks[_name][fmt]}'
|
||||
|
||||
vmsg('')
|
||||
return True
|
||||
|
|
@ -84,13 +84,13 @@ class unit_tests:
|
|||
|
||||
col1_w = max(len(str(e)) for e in list(chks.values())[0]) + 1
|
||||
|
||||
for name,sample in samples.items():
|
||||
for _name, sample in samples.items():
|
||||
vmsg(cyan(f'Input: {sample}'))
|
||||
for fmt in list(chks.values())[0]:
|
||||
res = fmt_dict(sample,fmt=fmt) if fmt else fmt_dict(sample)
|
||||
vmsg(f' {str(fmt)+":":{col1_w}} {res}')
|
||||
if name in chks:
|
||||
assert res == chks[name][fmt], f'{res} != {chks[name][fmt]}'
|
||||
if _name in chks:
|
||||
assert res == chks[_name][fmt], f'{res} != {chks[_name][fmt]}'
|
||||
|
||||
vmsg('')
|
||||
return True
|
||||
|
|
@ -98,7 +98,7 @@ class unit_tests:
|
|||
def list_gen(self,name,ut):
|
||||
res = list_gen(
|
||||
['a'],
|
||||
['b', 1==2],
|
||||
['b', False],
|
||||
['c', 'x'],
|
||||
['d', int],
|
||||
['e', None, 1, 'f', isinstance(7,int)],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue