test.py xmrwallet: SSH proxy initialization cleanups, add dep test

This commit is contained in:
The MMGen Project 2022-05-06 12:52:40 +00:00
commit 856b5b1e27
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 20 additions and 16 deletions

View file

@ -37,11 +37,14 @@ class TestSuiteXMRWallet(TestSuiteBase):
"""
Monero wallet operations
"""
networks = ('xmr',)
passthru_opts = ()
tmpdir_nums = [29]
dfl_random_txs = 3
color = True
socks_port = 49237
cmd_group = (
('gen_kafiles', 'generating key-address files'),
('create_wallets_miner', 'creating Monero wallets (Miner)'),
@ -85,8 +88,7 @@ class TestSuiteXMRWallet(TestSuiteBase):
self.tx_relay_daemon_parm = 'localhost:{}'.format( self.users['bob'].md.rpc_port )
self.tx_relay_daemon_proxy_parm = (
self.tx_relay_daemon_parm + f':127.0.0.1:{self.socks_port}' # proxy must be IP, not 'localhost'
if self.use_proxy else None )
self.tx_relay_daemon_parm + f':127.0.0.1:{self.socks_port}' ) # must be IP, not 'localhost'
if not opt.no_daemon_stop:
atexit.register(self.stop_daemons)
@ -102,7 +104,8 @@ class TestSuiteXMRWallet(TestSuiteBase):
# init methods
def init_proxy(self):
@classmethod
def init_proxy(cls,external_call=False):
def port_in_use(port):
import socket
@ -111,26 +114,23 @@ class TestSuiteXMRWallet(TestSuiteBase):
else: return True
def start_proxy():
if not opt.no_daemon_autostart:
if external_call or not opt.no_daemon_autostart:
run(a+b2)
omsg(f'SSH SOCKS server started, listening at localhost:{self.socks_port}')
omsg(f'SSH SOCKS server started, listening at localhost:{cls.socks_port}')
def kill_proxy():
if g.platform == 'linux':
omsg(f'Killing SSH SOCKS server at localhost:{self.socks_port}')
omsg(f'Killing SSH SOCKS server at localhost:{cls.socks_port}')
cmd = [ 'pkill', '-f', ' '.join(a + b2) ]
run(cmd)
self.use_proxy = False
self.socks_port = 9060
a = ['ssh','-x','-o','ExitOnForwardFailure=True','-D',f'localhost:{self.socks_port}']
a = ['ssh','-x','-o','ExitOnForwardFailure=True','-D',f'localhost:{cls.socks_port}']
b0 = ['-o','PasswordAuthentication=False']
b1 = ['localhost','true']
b2 = ['-fN','-E','txrelay-proxy.debug','localhost']
if port_in_use(self.socks_port):
omsg(f'Port {self.socks_port} already in use. Assuming SSH SOCKS server is running')
self.use_proxy = True
if port_in_use(cls.socks_port):
omsg(f'Port {cls.socks_port} already in use. Assuming SSH SOCKS server is running')
else:
cp = run(a+b0+b1,stdout=PIPE,stderr=PIPE)
err = cp.stderr.decode()
@ -139,7 +139,6 @@ class TestSuiteXMRWallet(TestSuiteBase):
if cp.returncode == 0:
start_proxy()
self.use_proxy = True
elif 'onnection refused' in err:
die(2,fmt("""
The SSH daemon must be running and listening on localhost in order to test
@ -167,7 +166,6 @@ class TestSuiteXMRWallet(TestSuiteBase):
if keypress_confirm('Continue?'):
start_proxy()
self.use_proxy = True
else:
die(1,'Exiting at user request')
else:
@ -179,9 +177,11 @@ class TestSuiteXMRWallet(TestSuiteBase):
Then restart the test.
""",indent=' '))
if not opt.no_daemon_stop:
if not (external_call or opt.no_daemon_stop):
atexit.register(kill_proxy)
return True
def init_users(self):
from mmgen.daemon import CoinDaemon
from mmgen.base_proto.monero.daemon import MoneroWalletDaemon

View file

@ -10,7 +10,7 @@ sec = 'deadbeef' * 8
class unit_tests:
altcoin_deps = ('pycoin','moneropy','keyconv','zcash_mini','ethkey')
altcoin_deps = ('pycoin','moneropy','keyconv','zcash_mini','ethkey','ssh_socks_proxy')
win_skip = ('losetup','moneropy','zcash_mini')
arm_skip = ('zcash_mini','ethkey')
@ -50,3 +50,7 @@ class unit_tests:
def ethkey(self,name,ut):
res = run(['ethkey','generate','random'],stdout=PIPE)
return True
def ssh_socks_proxy(self,name,ut):
from test.test_py_d.ts_xmrwallet import TestSuiteXMRWallet
return TestSuiteXMRWallet.init_proxy(external_call=True)