rpc: add BCH unit test; Daemon: move list attrs from class to instance
This commit is contained in:
parent
94e3b1c0b0
commit
c2cdfa429f
3 changed files with 67 additions and 49 deletions
|
|
@ -36,7 +36,9 @@ class Daemon(MMGenObject):
|
|||
ps_pid_mswin = False
|
||||
lockfile = None
|
||||
avail_flags = ()
|
||||
_flags = []
|
||||
|
||||
def __init__(self):
|
||||
self._flags = []
|
||||
|
||||
def subclass_init(self): pass
|
||||
|
||||
|
|
@ -222,6 +224,7 @@ class MoneroWalletDaemon(Daemon):
|
|||
ps_pid_mswin = True
|
||||
|
||||
def __init__(self,wallet_dir,test_suite=False,host=None,user=None,passwd=None):
|
||||
super().__init__()
|
||||
self.platform = g.platform
|
||||
self.wallet_dir = wallet_dir
|
||||
if test_suite:
|
||||
|
|
@ -303,21 +306,6 @@ class CoinDaemon(Daemon):
|
|||
'etc': cd('Ethereum Classic','Ethereum','parity', 'parity', 'parity.conf', None, 8545, None,None)
|
||||
}
|
||||
|
||||
testnet_arg = []
|
||||
coind_args = []
|
||||
daemonize_args = []
|
||||
cli_args = []
|
||||
shared_args = []
|
||||
coind_cmd = []
|
||||
|
||||
coin_specific_coind_args = []
|
||||
coin_specific_cli_args = []
|
||||
coin_specific_shared_args = []
|
||||
|
||||
usr_coind_args = []
|
||||
usr_cli_args = []
|
||||
usr_shared_args = []
|
||||
|
||||
def __new__(cls,network_id,test_suite=False,flags=None):
|
||||
|
||||
network_id = network_id.lower()
|
||||
|
|
@ -364,6 +352,21 @@ class CoinDaemon(Daemon):
|
|||
return me
|
||||
|
||||
def __init__(self,network_id,test_suite=False,flags=None):
|
||||
super().__init__()
|
||||
|
||||
self.testnet_arg = []
|
||||
self.daemonize_args = []
|
||||
self.cli_args = []
|
||||
self.coind_cmd = []
|
||||
|
||||
self.coin_specific_coind_args = []
|
||||
self.coin_specific_cli_args = []
|
||||
self.coin_specific_shared_args = []
|
||||
|
||||
self.usr_coind_args = []
|
||||
self.usr_cli_args = []
|
||||
self.usr_shared_args = []
|
||||
|
||||
|
||||
if flags:
|
||||
if type(flags) not in (list,tuple):
|
||||
|
|
@ -519,6 +522,7 @@ class EthereumDaemon(CoinDaemon):
|
|||
ps_pid_mswin = True
|
||||
|
||||
def subclass_init(self):
|
||||
self.shared_args = []
|
||||
# defaults:
|
||||
# linux: $HOME/.local/share/io.parity.ethereum/chains/DevelopmentChain
|
||||
# win: $LOCALAPPDATA/Parity/Ethereum/chains/DevelopmentChain
|
||||
|
|
@ -527,10 +531,6 @@ class EthereumDaemon(CoinDaemon):
|
|||
if self.platform == 'linux' and not 'no_daemonize' in self.flags:
|
||||
self.daemonize_args = ['daemon',self.pidfile]
|
||||
|
||||
@property
|
||||
def coind_cmd(self):
|
||||
return []
|
||||
|
||||
@property
|
||||
def coind_args(self):
|
||||
return ['--ports-shift={}'.format(self.port_shift),
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ from mmgen.common import *
|
|||
opts_data = {
|
||||
'text': {
|
||||
'desc': "Unit tests for the MMGen suite",
|
||||
'usage':'[options] [tests | test [subtest]]',
|
||||
'usage':'[options] [test | test.subtest]...',
|
||||
'options': """
|
||||
-h, --help Print this help message
|
||||
-A, --no-daemon-autostart Don't start and stop daemons automatically
|
||||
|
|
@ -108,14 +108,14 @@ def run_test(test,subtest=None):
|
|||
|
||||
try:
|
||||
import importlib
|
||||
if len(cmd_args) == 2 and cmd_args[0] in all_tests and cmd_args[1] not in all_tests:
|
||||
run_test(*cmd_args) # assume 2nd arg is subtest
|
||||
else:
|
||||
for test in cmd_args:
|
||||
if test not in all_tests:
|
||||
die(1,f'{test!r}: test not recognized')
|
||||
for test in (cmd_args or all_tests):
|
||||
run_test(test)
|
||||
for test in (cmd_args or all_tests):
|
||||
if '.' in test:
|
||||
test,subtest = test.split('.')
|
||||
else:
|
||||
subtest = None
|
||||
if test not in all_tests:
|
||||
die(1,f'{test!r}: test not recognized')
|
||||
run_test(test,subtest=subtest)
|
||||
exit_msg()
|
||||
except KeyboardInterrupt:
|
||||
die(1,green('\nExiting at user request'))
|
||||
|
|
|
|||
|
|
@ -10,8 +10,45 @@ from mmgen.protocol import init_coin
|
|||
from mmgen.rpc import MoneroWalletRPCClient
|
||||
from mmgen.daemon import CoinDaemon,MoneroWalletDaemon
|
||||
|
||||
def auth_test(d):
|
||||
d.stop()
|
||||
if g.platform != 'win':
|
||||
qmsg(f'\n Testing authentication with credentials from bitcoin.conf:')
|
||||
d.remove_datadir()
|
||||
os.makedirs(d.datadir)
|
||||
|
||||
cf = os.path.join(d.datadir,'bitcoin.conf')
|
||||
open(cf,'a').write('\nrpcuser = ut_rpc\nrpcpassword = ut_rpc_passw0rd\n')
|
||||
|
||||
d.add_flag('keep_cfg_file')
|
||||
d.start()
|
||||
|
||||
async def do():
|
||||
assert g.rpc.auth.user == 'ut_rpc', 'user is not ut_rpc!'
|
||||
|
||||
run_session(do())
|
||||
d.stop()
|
||||
|
||||
class unit_tests:
|
||||
|
||||
def bch(self,name,ut):
|
||||
|
||||
async def run_test():
|
||||
qmsg(' Testing backend {!r}'.format(type(g.rpc.backend).__name__))
|
||||
|
||||
d = CoinDaemon('bch',test_suite=True)
|
||||
d.remove_datadir()
|
||||
d.start()
|
||||
g.proto.daemon_data_dir = d.datadir # location of cookie file
|
||||
g.rpc_port = d.rpc_port
|
||||
|
||||
for backend in g.autoset_opts['rpc_backend'].choices:
|
||||
run_session(run_test(),backend=backend)
|
||||
|
||||
auth_test(d)
|
||||
qmsg(' OK')
|
||||
return True
|
||||
|
||||
def btc(self,name,ut):
|
||||
|
||||
async def run_test():
|
||||
|
|
@ -40,26 +77,7 @@ class unit_tests:
|
|||
for backend in g.autoset_opts['rpc_backend'].choices:
|
||||
run_session(run_test(),backend=backend)
|
||||
|
||||
d.stop()
|
||||
|
||||
if g.platform != 'win':
|
||||
|
||||
qmsg(f'\n Testing authentication with credentials from bitcoin.conf:')
|
||||
d.remove_datadir()
|
||||
os.makedirs(d.datadir)
|
||||
|
||||
cf = os.path.join(d.datadir,'bitcoin.conf')
|
||||
open(cf,'a').write('\nrpcuser = ut_rpc\nrpcpassword = ut_rpc_passw0rd\n')
|
||||
|
||||
d.add_flag('keep_cfg_file')
|
||||
d.start()
|
||||
|
||||
async def do():
|
||||
assert g.rpc.auth.user == 'ut_rpc', 'user is not ut_rpc!'
|
||||
|
||||
run_session(do())
|
||||
d.stop()
|
||||
|
||||
auth_test(d)
|
||||
qmsg(' OK')
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue