test suite: relocate some modules, use relative imports

This commit is contained in:
The MMGen Project 2020-03-16 10:45:00 +00:00
commit de7fba0c19
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
35 changed files with 172 additions and 156 deletions

View file

@ -7,8 +7,8 @@
colortest.py: test color handling for the MMGen suite
"""
import tests_header
from test.common import *
import include.tests_header
from include.common import *
from mmgen.color import *
from mmgen.color import _colors
init_color()

View file

@ -20,7 +20,7 @@ test/hashfunc.py: Test internal implementations of SHA256, SHA512 and Keccak256
"""
import sys,os
import tests_header
import include.tests_header
from mmgen.util import die
assert len(sys.argv) in (2,3),"Test takes 1 or 2 arguments: test name, plus optional rounds count"

0
test/include/__init__.py Executable file
View file

View file

@ -24,7 +24,7 @@ import sys,os,time
from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.util import msg,msg_r,vmsg,vmsg_r,rmsg,red,yellow,green,cyan,die,rdie
from test.common import *
from .common import *
try:
import pexpect

View file

@ -13,6 +13,7 @@ text = {
'jp': 'Japanese text: {}'.format('必要なのは、信用ではなく暗号化された証明に基づく電子取引システムであり、')
}
assert cmd_args[0] in text,'argument must be one of {}'.format(list(text.keys()))
if not cmd_args or not cmd_args[0] in text:
die(2,'argument must be one of {}'.format(list(text.keys())))
msg(text[cmd_args[0]])

View file

@ -9,7 +9,7 @@ test.objtest_py_d.ot_common: shared data for MMGen data objects tests
import os
from mmgen.globalvars import g
from ..common import *
from ..include.common import *
r32,r24,r16,r17,r18 = os.urandom(32),os.urandom(24),os.urandom(16),os.urandom(17),os.urandom(18)
tw_pfx = g.proto.base_coin.lower()+':'

View file

@ -24,9 +24,9 @@ supported coins + passwords
import sys,os
from subprocess import run,PIPE
from tests_header import repo_root
from include.tests_header import repo_root
from mmgen.common import *
from test.common import *
from test.include.common import *
opts_data = {
'text': {

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
import sys
from tests_header import repo_root
from include.tests_header import repo_root
from mmgen.common import *
from mmgen.daemon import CoinDaemon
from mmgen.regtest import MMGenRegtest

View file

@ -71,14 +71,14 @@ def create_shm_dir(data_dir,trash_dir):
return shm_dir
import sys,os,time
from tests_header import repo_root
from include.tests_header import repo_root
try: os.unlink(os.path.join(repo_root,'my.err'))
except: pass
from mmgen.common import *
from mmgen.daemon import CoinDaemon
from test.common import *
from test.include.common import *
from test.test_py_d.common import *
g.quiet = False # if 'quiet' was set in config file, disable here
@ -666,7 +666,7 @@ class TestSuiteRunner(object):
except:
self.log_fd.write(ascii(cmd_disp)+'\n')
from test.pexpect import MMGenPexpect
from test.include.pexpect import MMGenPexpect
return MMGenPexpect(args,no_output=no_output)
def end_msg(self):

View file

@ -20,9 +20,9 @@
common.py: Shared routines and data for the test.py test suite
"""
import os,time
import os
from mmgen.common import *
from ..common import *
from ..include.common import *
log_file = 'test.py.log'
@ -113,30 +113,29 @@ def get_file_with_ext(tdir,ext,delete=True,no_dot=False,return_list=False,delete
else:
return flist[0]
labels = [
"Automotive",
"Travel expenses",
"Healthcare",
tx_label_jp[:40],
tx_label_zh[:40],
"Alice's allowance",
"Bob's bequest",
"House purchase",
"Real estate fund",
"Job 1",
"XYZ Corp.",
"Eddie's endowment",
"Emergency fund",
"Real estate fund",
"Ian's inheritance",
"",
"Rainy day",
"Fred's funds",
"Job 2",
"Carl's capital",
]
def get_label(do_shuffle=False):
labels = [
"Automotive",
"Travel expenses",
"Healthcare",
tx_label_jp[:40],
tx_label_zh[:40],
"Alice's allowance",
"Bob's bequest",
"House purchase",
"Real estate fund",
"Job 1",
"XYZ Corp.",
"Eddie's endowment",
"Emergency fund",
"Real estate fund",
"Ian's inheritance",
"",
"Rainy day",
"Fred's funds",
"Job 2",
"Carl's capital",
]
from random import shuffle
global label_iter
try:
@ -145,60 +144,3 @@ def get_label(do_shuffle=False):
if do_shuffle: shuffle(labels)
label_iter = iter(labels)
return next(label_iter)
def stealth_mnemonic_entry(t,mne,mn,entry_mode,pad_entry=False):
def pad_mnemonic(mn,ss_len):
def get_pad_chars(n):
ret = ''
for i in range(n):
m = int.from_bytes(os.urandom(1),'big') % 32
ret += r'123579!@#$%^&*()_+-=[]{}"?/,.<>|'[m]
return ret
ret = []
for w in mn:
if entry_mode == 'short':
w = w[:ss_len]
if len(w) < ss_len:
npc = 3
w = w[0] + get_pad_chars(npc) + w[1:]
if pad_entry:
w += '%' * (1 + mne.em.pad_max - npc)
else:
w += '\n'
else:
w = get_pad_chars(1) + w[0] + get_pad_chars(1) + w[1:]
elif len(w) > (3,5)[ss_len==12]:
w = w + '\n'
else:
w = (
get_pad_chars(2 if randbool() and entry_mode != 'short' else 0)
+ w[0] + get_pad_chars(2) + w[1:]
+ get_pad_chars(9) )
w = w[:ss_len+1]
ret.append(w)
return ret
if entry_mode == 'fixed':
mn = ['bkr'] + mn[:5] + ['nfb'] + mn[5:]
ssl = mne.uniq_ss_len
mn = [w[:ssl] if len(w) >= ssl else (w[0] + 'z\b{}'.format('#'*(ssl-len(w))) + w[1:]) for w in mn]
elif entry_mode in ('full','short'):
mn = ['fzr'] + mn[:5] + ['grd','grdbxm'] + mn[5:]
mn = pad_mnemonic(mn,mne.em.ss_len)
mn[10] = '@#$%*##' + mn[10]
wnum = 1
p_ok,p_err = mne.word_prompt
for w in mn:
ret = t.expect((p_ok.format(wnum),p_err.format(wnum-1)))
if ret == 0:
wnum += 1
for j in range(len(w)):
t.send(w[j])
time.sleep(0.005)
def user_dieroll_entry(t,data):
for s in data:
t.expect(r'Enter die roll #.+: ',s,regex=True)
time.sleep(0.005)

71
test/test_py_d/input.py Executable file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env python3
#
# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
# Copyright (C)2013-2020 The MMGen Project <mmgen@tuta.io>
#
# Project source code repository: https://github.com/mmgen/mmgen
# Licensed according to the terms of GPL Version 3. See LICENSE for details.
"""
input.py: Shared input routines for the test.py test suite
"""
import os,time
from .common import randbool
def stealth_mnemonic_entry(t,mne,mn,entry_mode,pad_entry=False):
def pad_mnemonic(mn,ss_len):
def get_pad_chars(n):
ret = ''
for i in range(n):
m = int.from_bytes(os.urandom(1),'big') % 32
ret += r'123579!@#$%^&*()_+-=[]{}"?/,.<>|'[m]
return ret
ret = []
for w in mn:
if entry_mode == 'short':
w = w[:ss_len]
if len(w) < ss_len:
npc = 3
w = w[0] + get_pad_chars(npc) + w[1:]
if pad_entry:
w += '%' * (1 + mne.em.pad_max - npc)
else:
w += '\n'
else:
w = get_pad_chars(1) + w[0] + get_pad_chars(1) + w[1:]
elif len(w) > (3,5)[ss_len==12]:
w = w + '\n'
else:
w = (
get_pad_chars(2 if randbool() and entry_mode != 'short' else 0)
+ w[0] + get_pad_chars(2) + w[1:]
+ get_pad_chars(9) )
w = w[:ss_len+1]
ret.append(w)
return ret
if entry_mode == 'fixed':
mn = ['bkr'] + mn[:5] + ['nfb'] + mn[5:]
ssl = mne.uniq_ss_len
mn = [w[:ssl] if len(w) >= ssl else (w[0] + 'z\b{}'.format('#'*(ssl-len(w))) + w[1:]) for w in mn]
elif entry_mode in ('full','short'):
mn = ['fzr'] + mn[:5] + ['grd','grdbxm'] + mn[5:]
mn = pad_mnemonic(mn,mne.em.ss_len)
mn[10] = '@#$%*##' + mn[10]
wnum = 1
p_ok,p_err = mne.word_prompt
for w in mn:
ret = t.expect((p_ok.format(wnum),p_err.format(wnum-1)))
if ret == 0:
wnum += 1
for j in range(len(w)):
t.send(w[j])
time.sleep(0.005)
def user_dieroll_entry(t,data):
for s in data:
t.expect(r'Enter die roll #.+: ',s,regex=True)
time.sleep(0.005)

View file

@ -25,11 +25,12 @@ from subprocess import run
from mmgen.globalvars import g
from mmgen.opts import opt
from test.common import *
from test.test_py_d.common import *
from ..include.common import *
from .common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from .ts_base import *
from .ts_shared import *
from .input import *
class TestSuiteAutosign(TestSuiteBase):
'autosigning with BTC, BCH, LTC, ETH and ETC'
@ -86,7 +87,7 @@ class TestSuiteAutosign(TestSuiteBase):
('mm1','ethereum'),
('etc','ethereum_classic'))
fdata = [e for e in fdata_in if e[0] in txfiles]
from test.test_py_d.ts_ref import TestSuiteRef
from .ts_ref import TestSuiteRef
tfns = [TestSuiteRef.sources['ref_tx_file'][c][1] for c,d in fdata] + \
[TestSuiteRef.sources['ref_tx_file'][c][0] for c,d in fdata] + \
['25EFA3[2.34].testnet.rawtx'] # TX with 2 non-MMGen outputs

View file

@ -23,8 +23,8 @@ ts_base.py: Base class for the test.py test suite
import os
from mmgen.globalvars import g
from mmgen.opts import opt
from test.common import *
from test.test_py_d.common import *
from ..include.common import *
from .common import *
class TestSuiteBase(object):
'initializer class for the test.py test suite'

View file

@ -12,8 +12,8 @@ ts_misc.py: CfgFile tests for the MMGen test.py test suite
import shutil
from test.common import *
from test.test_py_d.ts_base import *
from ..include.common import *
from .ts_base import *
from mmgen.cfg import *
class TestSuiteCfg(TestSuiteBase):

View file

@ -24,12 +24,12 @@ import os
from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.util import die
from test.common import *
from test.test_py_d.common import *
from ..include.common import *
from .common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from test.test_py_d.ts_regtest import *
from .ts_base import *
from .ts_shared import *
from .ts_regtest import *
class TestSuiteChainsplit(TestSuiteRegtest):
'forking scenario tests for the test.py test suite'

View file

@ -28,8 +28,8 @@ from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.util import die
from mmgen.exception import *
from test.common import *
from test.test_py_d.common import *
from ..include.common import *
from .common import *
del_addrs = ('4','1')
dfl_sid = '98831F3A'
@ -132,8 +132,8 @@ token_bals_getbalance = {
'2': ('111.888877776666555545','888.111122223333444455')
}
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from .ts_base import *
from .ts_shared import *
class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
'Ethereum transacting, token deployment and tracking wallet operations'

View file

@ -10,8 +10,9 @@
ts_input.py: user input tests for the MMGen test.py test suite
"""
from test.common import *
from test.test_py_d.ts_base import *
from ..include.common import *
from .ts_base import *
from .input import *
from mmgen.seed import SeedSource
class TestSuiteInput(TestSuiteBase):

View file

@ -23,10 +23,10 @@ ts_main.py: Basic operations tests for the test.py test suite
from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.seed import SeedSource,Wallet,MMGenMnemonic,IncogWallet,MMGenSeedFile
from test.common import *
from test.test_py_d.common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from ..include.common import *
from .common import *
from .ts_base import *
from .ts_shared import *
def make_brainwallet_file(fn):
# Print random words with random whitespace in between

View file

@ -21,10 +21,10 @@ ts_misc.py: Miscellaneous test groups for the test.py test suite
"""
from mmgen.globalvars import g
from test.common import *
from test.test_py_d.common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_main import TestSuiteMain
from ..include.common import *
from .common import *
from .ts_base import *
from .ts_main import TestSuiteMain
class TestSuiteHelp(TestSuiteBase):
'help, info and usage screens'

View file

@ -10,8 +10,8 @@
ts_opts.py: options processing tests for the MMGen test.py test suite
"""
from test.common import *
from test.test_py_d.ts_base import *
from ..include.common import *
from .ts_base import *
class TestSuiteOpts(TestSuiteBase):
'options processing'

View file

@ -24,11 +24,11 @@ import os
from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.seed import MMGenMnemonic
from test.common import *
from test.test_py_d.common import *
from ..include.common import *
from .common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from .ts_base import *
from .ts_shared import *
wpasswd = 'reference password'
nw_name = '{} {}'.format(g.coin,('Mainnet','Testnet')[g.testnet])

View file

@ -24,11 +24,11 @@ ts_ref_3seed.py: Saved and generated reference file tests for 128, 192 and
from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.seed import SeedSource
from test.common import *
from test.test_py_d.common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from test.test_py_d.ts_wallet import TestSuiteWalletConv
from ..include.common import *
from .common import *
from .ts_base import *
from .ts_shared import *
from .ts_wallet import TestSuiteWalletConv
class TestSuiteRef3Seed(TestSuiteBase,TestSuiteShared):
'saved wallet files for 128-, 192- and 256-bit seeds + generated filename checks'

View file

@ -23,9 +23,9 @@ ts_ref_altcoin.py: Altcoin reference file tests for the test.py test suite
import os
from mmgen.globalvars import g
from mmgen.opts import opt
from test.test_py_d.common import *
from test.test_py_d.ts_ref import *
from test.test_py_d.ts_base import *
from .common import *
from .ts_ref import *
from .ts_base import *
class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
'saved and generated altcoin reference files'

View file

@ -28,8 +28,8 @@ from mmgen.util import die,gmsg,write_data_to_file
from mmgen.protocol import CoinProtocol
from mmgen.addr import AddrList
from mmgen.seed import Wallet
from test.common import *
from test.test_py_d.common import *
from ..include.common import *
from .common import *
dfl_wcls = Wallet
rt_pw = 'abc-α'
@ -128,8 +128,8 @@ rt_data = {
}
}
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from .ts_base import *
from .ts_shared import *
class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
'transacting and tracking wallet operations via regtest mode'

View file

@ -24,7 +24,7 @@ from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.seed import SeedSource,Wallet,IncogWallet,IncogWalletHex,IncogWalletHidden,SeedSourceEnc
from test.test_py_d.ts_base import *
from .ts_base import *
ref_wf = 'test/ref/98831F3A.bip39'
ref_sid = '98831F3A'

View file

@ -25,8 +25,8 @@ from mmgen.globalvars import g
from mmgen.opts import opt
from mmgen.util import ymsg
from mmgen.seed import SeedSource,SeedSourceEnc,Brainwallet,Wallet,IncogWalletHidden
from test.test_py_d.common import *
from test.common import *
from ..include.common import *
from .common import *
class TestSuiteShared(object):
'shared methods for the test.py test suite'

View file

@ -10,9 +10,9 @@
ts_tool.py: tool tests for the MMGen test.py test suite
"""
from test.common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_main import TestSuiteMain
from ..include.common import *
from .ts_base import *
from .ts_main import TestSuiteMain
class TestSuiteTool(TestSuiteMain,TestSuiteBase):
"interactive 'mmgen-tool' commands"

View file

@ -23,9 +23,9 @@ ts_wallet.py: Wallet conversion tests for the test.py test suite
import os
from mmgen.opts import opt
from mmgen.seed import *
from test.test_py_d.common import *
from test.test_py_d.ts_base import *
from test.test_py_d.ts_shared import *
from .common import *
from .ts_base import *
from .ts_shared import *
class TestSuiteWalletConv(TestSuiteBase,TestSuiteShared):
'wallet conversion to and from reference data'

View file

@ -23,9 +23,9 @@ test/tooltest.py: Tests for the 'mmgen-tool' utility
import sys,os,binascii
from subprocess import run,PIPE
from tests_header import repo_root
from include.tests_header import repo_root
from mmgen.common import *
from test.common import *
from test.include.common import *
opts_data = {
'text': {

View file

@ -27,9 +27,9 @@ import sys,os,time
from subprocess import run,PIPE
from decimal import Decimal
from tests_header import repo_root
from include.tests_header import repo_root
from mmgen.common import *
from test.common import *
from test.include.common import *
from mmgen.obj import is_wif,is_coin_addr
from mmgen.seed import is_bip39_mnemonic,is_mmgen_mnemonic
from mmgen.addr import is_xmrseed

View file

@ -22,7 +22,7 @@ test/unit_tests.py: Unit tests for the MMGen suite
import sys,os,time
from tests_header import repo_root
from include.tests_header import repo_root
from mmgen.common import *
opts_data = {

View file

@ -3,7 +3,7 @@
test/unit_tests_d/ut_scrypt.py: password hashing unit test for the MMGen suite
"""
from test.common import *
from ..include.common import *
class unit_test(object):

View file

@ -5,7 +5,7 @@ test/unit_tests_d/ut_tx_deserialize: TX deserialization unit test for the MMGen
import os
from mmgen.common import *
from test.common import *
from ..include.common import *
class unit_test(object):