test.py,unit_tests.py: start/stop BTC,LTC,BCH daemons automatically
This commit is contained in:
parent
adc5bc6e36
commit
041c55b65a
11 changed files with 53 additions and 11 deletions
|
|
@ -132,6 +132,8 @@ def check_daemons_running():
|
|||
g.proto = CoinProtocol(coin,g.testnet)
|
||||
if g.proto.sign_mode != 'daemon':
|
||||
continue
|
||||
if g.test_suite:
|
||||
g.proto.daemon_data_dir = 'test/daemons/' + coin.lower()
|
||||
vmsg('Checking {} daemon'.format(coin))
|
||||
try:
|
||||
rpc_init(reinit=True)
|
||||
|
|
@ -192,6 +194,8 @@ def sign_tx_file(txfile,signed_txs):
|
|||
tx = mmgen.tx.MMGenTX(txfile,offline=True)
|
||||
|
||||
if g.proto.sign_mode == 'daemon':
|
||||
if g.test_suite:
|
||||
g.proto.daemon_data_dir = 'test/daemons/' + g.coin.lower()
|
||||
rpc_init(reinit=True)
|
||||
|
||||
if txsign(tx,wfs,None,None):
|
||||
|
|
|
|||
|
|
@ -164,3 +164,21 @@ def iqmsg(s):
|
|||
if not opt.quiet: omsg(s)
|
||||
def iqmsg_r(s):
|
||||
if not opt.quiet: omsg_r(s)
|
||||
|
||||
def start_test_daemons(*network_ids):
|
||||
return test_daemons_ops(*network_ids,op='start')
|
||||
|
||||
def stop_test_daemons(*network_ids):
|
||||
return test_daemons_ops(*network_ids,op='stop')
|
||||
|
||||
def test_daemons_ops(*network_ids,op):
|
||||
if opt.no_daemon_autostart:
|
||||
return
|
||||
from mmgen.test_daemon import TestDaemon
|
||||
repo_root = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),os.pardir)))
|
||||
silent = not opt.verbose and not (hasattr(opt,'exact_output') and opt.exact_output)
|
||||
for network_id in network_ids:
|
||||
if network_id not in TestDaemon.network_ids: # silently ignore invalid IDs
|
||||
continue
|
||||
datadir = '{}/test/daemons/{}'.format(repo_root,network_id.replace('_tn',''))
|
||||
TestDaemon(network_id,datadir).cmd(op,silent=silent)
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ f_color='Terminal color tests completed'
|
|||
i_unit='Unit'
|
||||
s_unit='The bitcoin and bitcoin-abc mainnet daemons must be running for the following tests'
|
||||
t_unit="$unit_tests_py"
|
||||
f_unit='You may stop the bitcoin and bitcoin-abc mainnet daemons if you wish'
|
||||
f_unit='Unit tests completed'
|
||||
|
||||
i_hash='Internal hash function implementations'
|
||||
s_hash='Testing internal hash function implementations'
|
||||
|
|
@ -379,7 +379,7 @@ t_btc="
|
|||
$test_py --bech32
|
||||
$python scripts/compute-file-chksum.py $REFDIR/*testnet.rawtx >/dev/null 2>&1
|
||||
"
|
||||
f_btc='You may stop the bitcoin (mainnet) daemon if you wish'
|
||||
f_btc='Bitcoin mainnet tests completed'
|
||||
|
||||
i_btc_tn='Bitcoin testnet'
|
||||
s_btc_tn='The bitcoin testnet daemon must both be running for the following tests'
|
||||
|
|
@ -389,7 +389,7 @@ t_btc_tn="
|
|||
$test_py --testnet=1 --segwit-random
|
||||
$test_py --testnet=1 --bech32
|
||||
"
|
||||
f_btc_tn='You may stop the bitcoin testnet daemon if you wish'
|
||||
f_btc_tn='Bitcoin testnet tests completed'
|
||||
|
||||
i_btc_rt='Bitcoin regtest'
|
||||
s_btc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
|
||||
|
|
@ -399,7 +399,7 @@ f_btc_rt='Regtest (Bob and Alice) mode tests for BTC completed'
|
|||
i_bch='Bcash (BCH) mainnet'
|
||||
s_bch='The bitcoin-abc mainnet daemon must both be running for the following tests'
|
||||
t_bch="$test_py --coin=bch --exclude regtest"
|
||||
f_bch='You may stop the Bitcoin ABC daemon if you wish'
|
||||
f_bch='Bcash (BCH) mainnet tests completed'
|
||||
|
||||
i_bch_tn='Bcash (BCH) testnet'
|
||||
s_bch_tn='The bitcoin-abc testnet daemon must both be running for the following tests'
|
||||
|
|
@ -409,7 +409,7 @@ f_bch_tn='Bcash (BCH) testnet tests completed'
|
|||
i_bch_rt='Bcash (BCH) regtest'
|
||||
s_bch_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
|
||||
t_bch_rt="$test_py --coin=bch regtest"
|
||||
f_bch_tn='You may stop the bitcoin-abc testnet daemon if you wish'
|
||||
f_bch_rt='Regtest (Bob and Alice) mode tests for BCH completed'
|
||||
|
||||
i_ltc='Litecoin'
|
||||
s_ltc='The litecoin mainnet daemon must both be running for the following tests'
|
||||
|
|
@ -419,7 +419,7 @@ t_ltc="
|
|||
$test_py --coin=ltc --segwit-random
|
||||
$test_py --coin=ltc --bech32
|
||||
"
|
||||
f_ltc='You may stop the litecoin daemon if you wish'
|
||||
f_ltc='Litecoin mainnet tests completed'
|
||||
|
||||
i_ltc_tn='Litecoin testnet'
|
||||
s_ltc_tn='The litecoin testnet daemon must both be running for the following tests'
|
||||
|
|
@ -429,7 +429,7 @@ t_ltc_tn="
|
|||
$test_py --coin=ltc --testnet=1 --segwit-random
|
||||
$test_py --coin=ltc --testnet=1 --bech32
|
||||
"
|
||||
f_ltc_tn='You may stop the litecoin testnet daemon if you wish'
|
||||
f_ltc_tn='Litecoin testnet tests completed'
|
||||
|
||||
i_ltc_rt='Litecoin regtest'
|
||||
s_ltc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ opts_data = {
|
|||
'options': """
|
||||
-h, --help Print this help message
|
||||
--, --longhelp Print help message for long options (common options)
|
||||
-A, --no-daemon-autostart Don't start and stop daemons automatically
|
||||
-B, --bech32 Generate and use Bech32 addresses
|
||||
-b, --buf-keypress Use buffered keypresses as with real human input
|
||||
(often required on slow systems, or under emulation)
|
||||
|
|
@ -148,6 +149,7 @@ if not ('resume' in _uopts or 'skip_deps' in _uopts):
|
|||
except: pass
|
||||
|
||||
sys.argv.insert(1,'--data-dir=' + data_dir)
|
||||
sys.argv.insert(1,'--daemon-data-dir=test/daemons/' + (_uopts.get('coin') or 'btc'))
|
||||
|
||||
# step 2: opts.init will create new data_dir in ./test (if not 'resume' or 'skip_deps'):
|
||||
usr_args = opts.init(opts_data)
|
||||
|
|
@ -926,11 +928,14 @@ if opt.pause:
|
|||
set_restore_term_at_exit()
|
||||
|
||||
set_environ_for_spawned_scripts()
|
||||
start_test_daemons(network_id)
|
||||
|
||||
try:
|
||||
tr = TestSuiteRunner(data_dir,trash_dir)
|
||||
tr.run_tests(usr_args)
|
||||
stop_test_daemons(network_id)
|
||||
except KeyboardInterrupt:
|
||||
stop_test_daemons(network_id)
|
||||
die(1,'\ntest.py exiting at user request')
|
||||
except TestSuiteException as e:
|
||||
ydie(1,e.args[0])
|
||||
|
|
|
|||
|
|
@ -178,6 +178,9 @@ class TestSuiteAutosign(TestSuiteBase):
|
|||
imsg('')
|
||||
return t
|
||||
|
||||
network_ids = [c+'_tn' for c in coins] + coins
|
||||
start_test_daemons(*network_ids)
|
||||
|
||||
if live:
|
||||
mountpoint = '/mnt/tx'
|
||||
if not os.path.ismount(mountpoint):
|
||||
|
|
@ -220,6 +223,7 @@ class TestSuiteAutosign(TestSuiteBase):
|
|||
except: pass
|
||||
ret = do_autosign(opts,mountpoint)
|
||||
|
||||
stop_test_daemons(*network_ids)
|
||||
return ret
|
||||
|
||||
class TestSuiteAutosignMinimal(TestSuiteAutosign):
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared):
|
|||
'basic operations with emulated tracking wallet'
|
||||
tmpdir_nums = [1,2,3,4,5,14,15,16,20,21]
|
||||
networks = ('btc','btc_tn','ltc','ltc_tn','bch','bch_tn')
|
||||
passthru_opts = ('coin','testnet')
|
||||
passthru_opts = ('daemon_data_dir','coin','testnet')
|
||||
segwit_opts_ok = True
|
||||
cmd_group = (
|
||||
('walletgen_dfl_wallet', (15,'wallet generation (default wallet)',[[[],15]])),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class TestSuiteHelp(TestSuiteBase):
|
|||
'help, info and usage screens'
|
||||
networks = ('btc','ltc','bch','eth')
|
||||
tmpdir_nums = []
|
||||
passthru_opts = ('coin','testnet')
|
||||
passthru_opts = ('daemon_data_dir','coin','testnet')
|
||||
cmd_group = (
|
||||
('helpscreens', (1,'help screens', [])),
|
||||
('longhelpscreens', (1,'help screens (--longhelp)',[])),
|
||||
|
|
@ -257,7 +257,7 @@ class TestSuiteTool(TestSuiteMain,TestSuiteBase):
|
|||
class TestSuiteRefTX(TestSuiteMain,TestSuiteBase):
|
||||
'create a reference transaction file (administrative command)'
|
||||
segwit_opts_ok = False
|
||||
passthru_opts = ('coin','testnet')
|
||||
passthru_opts = ('daemon_data_dir','coin','testnet')
|
||||
tmpdir_nums = [31,32,33,34]
|
||||
cmd_group = (
|
||||
('ref_tx_addrgen1', (31,'address generation (legacy)', [[[],1]])),
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class TestSuiteRef(TestSuiteBase,TestSuiteShared):
|
|||
'saved reference address, password and transaction files'
|
||||
tmpdir_nums = [8]
|
||||
networks = ('btc','btc_tn','ltc','ltc_tn')
|
||||
passthru_opts = ('coin','testnet')
|
||||
passthru_opts = ('daemon_data_dir','coin','testnet')
|
||||
sources = {
|
||||
'ref_addrfile': '98831F3A{}[1,31-33,500-501,1010-1011]{}.addrs',
|
||||
'ref_segwitaddrfile':'98831F3A{}-S[1,31-33,500-501,1010-1011]{}.addrs',
|
||||
|
|
|
|||
|
|
@ -90,18 +90,24 @@ class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
|
|||
for tn in (False,True):
|
||||
if tn and coin == 'etc':
|
||||
continue
|
||||
if coin == 'bch':
|
||||
network_id = 'bch' + ('','_tn')[tn]
|
||||
start_test_daemons(network_id)
|
||||
g.testnet = tn
|
||||
init_coin(coin)
|
||||
fn = TestSuiteRef.sources['ref_tx_file'][token or coin][bool(tn)]
|
||||
tf = joinpath(ref_dir,ref_subdir,fn)
|
||||
wf = dfl_words_file
|
||||
e = ['--coin='+coin,'--testnet='+('0','1')[tn]]
|
||||
e += ['--daemon-data-dir=test/daemons/bch']
|
||||
if token: e += ['--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 = e )
|
||||
if coin == 'bch':
|
||||
stop_test_daemons(network_id)
|
||||
ok_msg()
|
||||
g.testnet = False
|
||||
init_coin('btc')
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ opts_data = {
|
|||
'usage':'[options] [tests]',
|
||||
'options': """
|
||||
-h, --help Print this help message
|
||||
-A, --no-daemon-autostart Don't start and stop daemons automatically
|
||||
-f, --fast Speed up execution by reducing rounds on some tests
|
||||
-l, --list List available tests
|
||||
-n, --names Print command names instead of descriptions
|
||||
|
|
|
|||
|
|
@ -5,6 +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 *
|
||||
|
||||
class unit_test(object):
|
||||
|
||||
|
|
@ -109,6 +110,7 @@ class unit_test(object):
|
|||
print_info('test/ref/*rawtx','MMGen reference transactions')
|
||||
for n,(coin,tn,fn) in enumerate(fns):
|
||||
init_coin(coin,tn)
|
||||
g.proto.daemon_data_dir = 'test/daemons/' + g.coin.lower()
|
||||
rpc_init(reinit=True)
|
||||
test_tx(MMGenTX(fn).hex,fn,n+1)
|
||||
init_coin('btc',False)
|
||||
|
|
@ -118,7 +120,9 @@ class unit_test(object):
|
|||
from mmgen.tx import DeserializedTX
|
||||
import json
|
||||
|
||||
start_test_daemons('btc','btc_tn','bch')
|
||||
test_mmgen_txs()
|
||||
test_core_vectors()
|
||||
stop_test_daemons('btc','btc_tn','bch')
|
||||
|
||||
return True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue